Scan.sums: def of bend-parallel@0.1.0.0 Import: import bend-parallel@0.1.0.0/scan.bend as Scan Lines 113-128 of bend-parallel@0.1.0.0/scan.bend: https://jend.leeeet.dev/read.txt?path=bend-parallel@0.1.0.0/scan.bend&start_line=113&end_line=128 import Base # Pass 1's forks: d levels down to the leaves under leaf index i. fa and # fs are two handles each to the data a and the sums s. Leaf i reads only # its block of a and writes only s[i], so no two lanes touch one slot. def sums(+d: Nat, +i: U32, +e: Nat, fa: Array & Array, fs: Array & Array) -> Two: match d: case 0n: (a, a2) = fa (s, s2) = fs two.rejoin(a2, s2, sums.leaf(i, e, a, s)) case 1n+p: (a0, a1) = fa (s0, s1) = fs +j = (i * 2 : U32) l r = sums(p, j, e, Array.fork(U32, a0), Array.fork(U32, s0)) sums(p, (j + 1 : U32), e, Array.fork(U32, a1), Array.fork(U32, s1)) two.join(l, r) Uses (12): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Array https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Array.fork https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat 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 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.mul https://jend.leeeet.dev/definition.txt?path=bend-parallel@0.1.0.0/scan.bend&name=Two https://jend.leeeet.dev/definition.txt?path=bend-parallel@0.1.0.0/scan.bend&name=sums.leaf https://jend.leeeet.dev/definition.txt?path=bend-parallel@0.1.0.0/scan.bend&name=two.join https://jend.leeeet.dev/definition.txt?path=bend-parallel@0.1.0.0/scan.bend&name=two.rejoin