def first_digit
import bendtorch-core@0.1.0.0/src/autograd/reduce.bend as Reduceimport Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
51# The first digit a row walks: 0 on a reduced axis (`Nat.div` by 0 is 0),
52# else the digit `target` names there.
53def first_digit(+rows: List<&2, Shape.Row>, +target: Nat) -> Nat:
54 match rows:
55 case Nil{}:
56 0n
57 case Shape.Row{stride, +left, right} <> rest:
58 Nat.div(target, left)