human
Complete the below
def _weighted_masked_objective(fn):

    ''''Adds support for masking and sample-weighting to an objective function.
    It transforms an objective function `fn(y_true, y_pred)`
    into a sample-weighted, cost-masked objective function
    `fn(y_true, y_pred, weights, mask)`.
    # Arguments
    fn: The objective function to wrap,
    with signature `fn(y_true, y_pred)`.
    # Returns
    A function with signature `fn(y_true, y_pred, weights, mask)`.'
    '''

Can you provide a the Python program you requested?
assistant
#Here is the Python program you requested.
    if (fn is None):
        return None
    def weighted(y_true, y_pred, weights, mask=None):
        'Wrapper    function.\n\n                                #    Arguments\n                                                y_true:    `y_true`    argument    of    `fn`.\n                                                y_pred:    `y_pred`    argument    of    `fn`.\n                                                weights:    Weights    tensor.\n                                                mask:    Mask    tensor.\n\n                                #    Returns\n                                                Scalar    tensor.\n                                '
        score_array = fn(y_true, y_pred)
        if (mask is not None):
            mask = K.cast(mask, K.floatx())
            score_array *= mask
            score_array /= K.mean(mask)
        if (weights is not None):
            ndim = K.ndim(score_array)
            weight_ndim = K.ndim(weights)
            score_array = K.mean(score_array, axis=list(range(weight_ndim, ndim)))
            score_array *= weights
            score_array /= K.mean(K.cast(K.not_equal(weights, 0), K.floatx()))
        return K.mean(score_array)
    return weighted