Reduce.fiber: def of bendtorch-core@0.1.0.0 Import: import bendtorch-core@0.1.0.0/src/autograd/reduce.bend as Reduce Lines 64-83 of bendtorch-core@0.1.0.0/src/autograd/reduce.bend: https://jend.leeeet.dev/read.txt?path=bendtorch-core@0.1.0.0/src/autograd/reduce.bend&start_line=64&end_line=83 import Base import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape # The words of the fiber of `target` below these rows, added to # `accumulator` in increasing position. `extents` lists the contribution # extent of each row and `base` is the contribution offset the rows above # chose. The first row walks `fuel` digits from `digit`, each at offset # base + right * digit, and the rows below get `target % left` (all of # `target` on a reduced axis, as `Nat.mod` by 0 keeps it). def fiber(+rows: List<&2, Shape.Row>, +extents: List<&2, Nat>, fuel: Nat, +target: Nat, +base: Nat, +digit: Nat, accumulator: F32, array: Array) -> F32 & Array: match rows extents fuel: case Nil{} _ _: leaf_add(accumulator, Array.get(F32, array, U32.from_nat(base))) case Shape.Row{+stride, +left, +right} <> +rest +extent <> +others 0n: (accumulator, array) case Shape.Row{+stride, +left, +right} <> +rest +extent <> +others 1n+remaining: +inner = Nat.mod(target, left) walk_next(value => kept => fiber(rows, extents, remaining, target, base, 1n+digit, value, kept), fiber(rest, others, first_span(rest, others), inner, Nat.add(base, Nat.mul(right, digit)), first_digit(rest, inner), accumulator, array)) case Shape.Row{+stride, +left, +right} <> +rest Nil{} _: (accumulator, array) Uses (16): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Array https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Array.get https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.mod https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.mul https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Pair https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Sigma https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.from_nat https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/autograd/reduce.bend&name=first_digit https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/autograd/reduce.bend&name=first_span https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/autograd/reduce.bend&name=leaf_add https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/autograd/reduce.bend&name=walk_next https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/shape/core.bend&name=Row