def METHOD_NAME(
    values,
    sample_weight=None,
    mask=None,
    reduction="sum_over_batch_size",
):
    reduction = standardize_reduction(reduction)
    values = ops.convert_to_tensor(values)
    if sample_weight is not None:
        sample_weight = ops.convert_to_tensor(sample_weight, dtype=values.dtype)
    if mask is not None:
        mask = ops.convert_to_tensor(mask, dtype=values.dtype)
    # Merge mask and sample weight into sample weight.
    sample_weight = apply_mask(
        sample_weight, mask, dtype=values.dtype, reduction=reduction
    )
    # Convert any non float dtypes to floats, to avoid loss of precision
    # for dtype like int or bool.
    dtype = backend.standardize_dtype(values.dtype)
    if not dtype_utils.is_float(dtype):
        input_dtype = values.dtype
        values = ops.cast(values, "float32")
        input_casted = True
    else:
        input_casted = False
    if sample_weight is not None:
        sample_weight = ops.cast(sample_weight, values.dtype)
        # Update dimensions of `sample_weight` to match `losses`.
        values, sample_weight = squeeze_to_same_rank(values, sample_weight)
        values = values * sample_weight
    # Apply reduction function to the individual weighted losses.
    loss = reduce_values(values, reduction)
    if input_casted:
        # Convert the result back to the input type.
        loss = ops.cast(loss, input_dtype)
    return loss