def cross_entropy
import bendtorch-core@0.1.0.0/src/autograd/loss.bend as Lossimport Base
import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
415# PyTorch's cross_entropy(logits, targets) with mean reduction, for logits
416# of [rows, columns] and one class index below `columns` per row. Per row,
417# the stable log_softmax: m = the row maximum (max_step), shifted = x - m,
418# lse = log of the sum of exp(shifted) in ascending order from +0.0, and
419# lp = shifted - lse, PyTorch's (x - max) - log(sum). The loss is the sum of
420# -lp at each row's target, in row order from +0.0, divided by the rows.
421# The logits come back unchanged, next to the loss, lp and the one-hot rows
422# of the targets, which the backward reads. Logits that are not of rank 2
423# fail with NotLogits (107); a target count other than the rows or a target
424# at or past `columns` with TargetOutOfRange (108).
425def cross_entropy(logits: Core.Dynamic, +targets: List<&2, U32>) -> Core.Dynamic & Result<&2, &1, Error, Recorded>:
426 ce_shaped(targets, Core.shape(logits))