function computeWeightedLoss_(losses, weights, reduction = (0, _lossOpsUtils.Reduction).SUM_BY_NONZERO_WEIGHTS) {
    const $losses = (0, _tensorUtilEnv.convertToTensor)(losses, "losses", "computeWeightedLoss");
    let $weights = null;
    if (weights != null) $weights = (0, _tensorUtilEnv.convertToTensor)(weights, "weights", "computeWeightedLoss");
    const weightedLoss = $weights == null ? $losses : (0, _mul.mul)($losses, $weights);
    if (reduction === (0, _lossOpsUtils.Reduction).NONE) return weightedLoss;
    if (reduction === (0, _lossOpsUtils.Reduction).SUM) return (0, _sum.sum)(weightedLoss);
    if (reduction === (0, _lossOpsUtils.Reduction).MEAN) {
        if ($weights == null) return (0, _mean.mean)(weightedLoss);
        else {
            const broadcastFactor = $losses.size / $weights.size;
            const result = (0, _div.div)((0, _sum.sum)(weightedLoss), (0, _sum.sum)($weights));
            return broadcastFactor > 1 ? (0, _div.div)(result, (0, _scalar.scalar)(broadcastFactor)) : result;
        }
    }
    if (reduction === (0, _lossOpsUtils.Reduction).SUM_BY_NONZERO_WEIGHTS) {
        if ($weights == null) return (0, _div.div)((0, _sum.sum)(weightedLoss), (0, _scalar.scalar)($losses.size));
        else {
            const broadcastedWeights = (0, _mul.mul)($weights, (0, _ones.ones)($losses.shape));
            const numNonZeros = (0, _cast.cast)((0, _sum.sum)((0, _notEqual.notEqual)(broadcastedWeights, (0, _scalar.scalar)(0))), "float32");
            return (0, _div.div)((0, _sum.sum)(weightedLoss), numNonZeros);
        }
    }
    throw Error(`Unknown reduction: ${reduction}`);
}
Computes the weighted loss between two tensors.

@param losses Tensor of shape `[batch_size, d1, ..., dN]`.
@param weights Tensor whose rank is either 0, or the same rank as
   `losses`, and must be broadcastable to `losses` (i.e., all
   dimensions must be either `1`, or the same as the corresponding
   `losses` dimension).

@doc {heading: 'Training', subheading: 'Losses', namespace: 'losses'}