def tnode

bendtorch-gpu@1.3.0.0 · main.bend:1371

import bendtorch-gpu@1.3.0.0/main.bend as BendtorchGpu
import Base

1371# tree_sum of the len cells from lo, read in place: a node l passes above the cells sums its left child (the first h =
1372# 2^(l-1) cells) and its right child (the rest) when there is a rest (big = h < len), and is its left child otherwise
1373# (tree_sum's odd last cell carried up a pass)
1374def tnode(l: Nat, big: Bool, +lo: U32, +len: U32, +h: U32, a: Array<F32>) -> TS:
1375  match l big:
1376    case 0n _: ts_leaf(Array.get(F32, a, lo))
1377    case 1n++q True{}: ts_then(tnode(q, U32.is_lt(U32.shr(h), h), lo, h, U32.shr(h), a), +s => a2 => ts_plus(s, tnode(q, U32.is_lt(U32.shr(h), (len - h : U32)), (lo + h : U32), (len - h : U32), U32.shr(h), a2)))
1378    case 1n+q False{}: tnode(q, U32.is_lt(U32.shr(h), len), lo, len, U32.shr(h), a)

Uses (14)

Used by (1)