def single_offset

bendtorch-core@0.1.0.0 · src/autograd/reduce.bend:104

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

104# The offset of the one word that rows of span 1 reach from `base`.
105def single_offset(+rows: List<&2, Shape.Row>, +extents: List<&2, Nat>, +target: Nat, +base: Nat) -> Nat:
106  match rows extents:
107    case Shape.Row{stride, +left, +right} <> +rest +extent <> +others:
108      single_offset(rest, others, Nat.mod(target, left), Nat.add(base, Nat.mul(right, Nat.div(target, left))))
109    case _ _:
110      base

Uses (7)

Used by (11)