Reduce.fiber_fast: def of bendtorch-core@0.1.0.0 Import: import bendtorch-core@0.1.0.0/src/autograd/reduce.bend as Reduce Lines 138-159 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=138&end_line=159 import Base import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape # `fiber`, the same words added in the same order, except that a row whose # rows below all take one digit (`single`, which is `single_below` of the # rows; a later digit of the same row passes False) walks its digits in one # strided loop: below digit d it reads the one word at base + right * d + # single_offset(rest, others, target % left, 0), with no closure per word. # Column sums, row sums and batch sums over one axis take that loop. def fiber_fast(+rows: List<&2, Shape.Row>, +extents: List<&2, Nat>, fuel: Nat, single: Bool, +target: Nat, +base: Nat, +digit: Nat, accumulator: F32, array: Array) -> F32 & Array: match rows extents fuel single: case Nil{} _ _ single: leaf_add(accumulator, Array.get(F32, array, U32.from_nat(base))) case Shape.Row{+stride, +left, +right} <> +rest +extent <> +others fuel True{}: strided(fuel, right, base, digit, single_offset(rest, others, Nat.mod(target, left), 0n), accumulator, array) case Shape.Row{+stride, +left, +right} <> +rest +extent <> +others 0n False{}: (accumulator, array) case Shape.Row{+stride, +left, +right} <> +rest +extent <> +others 1n+remaining False{}: +inner = Nat.mod(target, left) walk_next(value => kept => fiber_fast(rows, extents, remaining, False{}, target, base, 1n+digit, value, kept), fiber_fast(rest, others, first_span(rest, others), single_below(rest, others), inner, step_offset(base, right, digit), first_digit(rest, inner), accumulator, array)) case Shape.Row{+stride, +left, +right} <> +rest Nil{} _ single: (accumulator, array) Uses (19): 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=Bool 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.mod 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=single_below https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/autograd/reduce.bend&name=single_offset https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/autograd/reduce.bend&name=step_offset https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/autograd/reduce.bend&name=strided 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