def fiber_fast
bendtorch-core@0.1.0.0 · src/autograd/reduce.bend:138
import bendtorch-core@0.1.0.0/src/autograd/reduce.bend as Reduce
import Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
138
139
140
141
142
143
144def fiber_fast(+rows: List<&2, Shape.Row>, +extents: List<&2, Nat>, fuel: Nat, single: Bool, +target: Nat, +base: Nat, +digit: Nat,
145 accumulator: F32, array: Array<F32>) -> F32 & Array<F32>:
146 match rows extents fuel single:
147 case Nil{} _ _ single:
148 leaf_add(accumulator, Array.get(F32, array, U32.from_nat(base)))
149 case Shape.Row{+stride, +left, +right} <> +rest +extent <> +others fuel True{}:
150 strided(fuel, right, base, digit, single_offset(rest, others, Nat.mod(target, left), 0n), accumulator, array)
151 case Shape.Row{+stride, +left, +right} <> +rest +extent <> +others 0n False{}:
152 (accumulator, array)
153 case Shape.Row{+stride, +left, +right} <> +rest +extent <> +others 1n+remaining False{}:
154 +inner = Nat.mod(target, left)
155 walk_next(value => kept => fiber_fast(rows, extents, remaining, False{}, target, base, 1n+digit, value, kept),
156 fiber_fast(rest, others, first_span(rest, others), single_below(rest, others), inner, step_offset(base, right, digit),
157 first_digit(rest, inner), accumulator, array))
158 case Shape.Row{+stride, +left, +right} <> +rest Nil{} _ single:
159 (accumulator, array)