function softmaxCrossEntropyWithLogits_(labels, logits, dim = -1) {
    if (dim === -1) dim = logits.rank - 1;
    if (dim !== logits.rank - 1) throw Error(`Softmax cross entropy along a non-last dimension is not yet ` + `supported. Labels / logits was rank ${logits.rank} ` + `and dim was ${dim}`);
    // Use a custom gradient for numerical stability.
    const customOp = (0, _gradients.customGrad)((labels, logits, save)=>{
        // Reference:
        //   1. http://cs231n.github.io/linear-classify/#softmax
        //   2. https://blog.feedly.com/tricks-of-the-trade-logsumexp/
        const keepDims = true;
        const lse = (0, _logSumExp.logSumExp)(logits, [
            dim
        ], keepDims);
        const logResult = (0, _sub.sub)((0, _cast.cast)(logits, "float32"), lse);
        save([
            labels,
            logResult
        ]);
        const costVector = (0, _neg.neg)((0, _mul.mul)(logResult, labels));
        const value = (0, _sum.sum)(costVector, [
            dim
        ]);
        const gradFunc = (dy, saved)=>{
            const [labels, logResult] = saved;
            const dyShape = (0, _axisUtil.expandShapeToKeepDim)(dy.shape, [
                dim
            ]);
            return [
                (0, _mul.mul)((0, _reshape.reshape)(dy, dyShape), (0, _sub.sub)((0, _cast.cast)(labels, "float32"), (0, _exp.exp)(logResult))),
                (0, _mul.mul)((0, _reshape.reshape)(dy, dyShape), (0, _sub.sub)((0, _exp.exp)(logResult), (0, _cast.cast)(labels, "float32")))
            ];
        };
        return {
            value,
            gradFunc
        };
    });
    return customOp(labels, logits);
}
Computes softmax cross entropy between logits and labels.

Measures the probability error in discrete classification tasks in which
the classes are mutually exclusive (each entry is in exactly one class).
For example, each CIFAR-10 image is labeled with one and only one label: an
image can be a dog or a truck, but not both.

`NOTE`: While the classes are mutually exclusive, their probabilities need
not be. All that is required is that each row of labels is a valid
probability distribution. If they are not, the computation of the gradient
will be incorrect.

`WARNING`: This op expects unscaled logits, since it performs a softmax on
logits internally for efficiency. Do not call this op with the output of
softmax, as it will produce incorrect results.

logits and labels must have the same shape, e.g. [batch_size, num_classes]
and the same dtype.
@param labels The labels array.
@param logits The logits array.
@param dim The dimension softmax would be performed on. Defaults to `-1`
    which indicates the last dimension.