def ce_maxed
bendtorch-core@0.1.0.0 · src/autograd/loss.bend:376
import bendtorch-core@0.1.0.0/src/autograd/loss.bend as Loss
import Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
import bendtorch-core@0.1.0.0/src/tensor/elementwise.bend as Elementwise
import bendtorch-core@0.1.0.0/src/tensor/reduction.bend as Reduction
376def ce_maxed(+rows: Nat, onehot: Core.Dynamic, +target: Shape.Shape, pair: Core.Dynamic & Result<&2, &1, Core.Error, Core.Dynamic>) ->
377 Core.Dynamic & Result<&2, &1, Error, Recorded>:
378 (logits, result) = pair
379 match result:
380 case Fail{error}:
381 (logits, Fail{TensorError{error}})
382 case Done{maxes}:
383 ce_shifted(rows, onehot, target, Elementwise.binary(Elementwise.Sub{}, logits, maxes), Core.new(Reduction.scalar_shape(), 0.0))