import logging


def featurize_data(model, array):
    """
    Given a model and an array, perform error checking and return the prediction
    of the full feature array.

    Parameters:
    ----------
        model : keras.models.Model
            The featurizer model performing predictions

        array : np.ndarray
            The vectorized array of images being converted into features

    Returns:
    --------
        full_feature_array : np.ndarray
            A numpy array containing the featurized images

    """
    # Raise error if the array has the wrong shape
    if len(array.shape) != 4:
        raise ValueError('Image array must be a 4D tensor, with dimensions: '
                         '[batch, height, width, channel]')

    # Perform predictions
    logging.info('Creating feature array.')

    # NOTE: No clue why this is here, it's to make the models note break due to
    # Keras update: https://github.com/keras-team/keras/issues/9394
    model.compile('sgd', 'mse')
    full_feature_array = model.predict(array, verbose=1)

    # Return features
    logging.info('Feature array created successfully.')
    return full_feature_array