~/bend-docscommunity

tree.bend checks

raw source on the hub · import bend-ndarray@0.1.2.0/tree.bend as Tree

bend-ndarray's storage: one binary tree (a Bend Array<U32>) whose levels follow the dimensions. A dimension of n elements takes dep(n) levels (the least d with 2^d >= n; a dimension of 1 or 0 takes none), the first dimension's levels at the top. So element (i0, i1, ...) is the cell whose index is i0, i1, ... written in dep(n0), dep(n1), ... bits, and every operation is a recursion over the tree: a subtree at a dimension's boundary is a sub-array. Cells past a dimension's length are padding: any value, never read as data.

3 imports
import Base
import ./shape.bend as S
import ./cells.bend as C

Types

type Step source · line 91 · raw

Data

Definitions

def pow2 source · line 12 · raw

@n:Nat -> Nat

def dep_if source · line 19 · raw

@done:Bool -> @+d:Nat -> @more:(@_:Unit -> Nat) -> Nat

def dep_go source · line 26 · raw

@fuel:Nat -> @+n:Nat -> @+d:Nat -> @+p:Nat -> Nat

def dep source · line 34 · raw

@+n:Nat -> Nat

the levels a dimension of n elements takes (the least d with 2^d >= n)

def depth source · line 38 · raw

@s:List<&2, Nat> -> Nat

the levels of a whole shape

def depth_before source · line 46 · raw

@s:List<&2, Nat> -> @i:Nat -> Nat

the levels of the dimensions before axis i

def depth_after source · line 56 · raw

@s:List<&2, Nat> -> @i:Nat -> Nat

the levels of the dimensions after axis i

def fill source · line 65 · raw

@+d:Nat -> @+v:U32 -> Array<U32>

def amap source · line 70 · raw

@+op:0xe2a576a925a38b8ab216e6d41f3358a6/cells.U1 -> @+dt:0xe2a576a925a38b8ab216e6d41f3358a6/shape.DType -> @a:Array<U32> -> Array<U32>

def zip source · line 79 · raw

@+op:0xe2a576a925a38b8ab216e6d41f3358a6/cells.B2 -> @+dt:0xe2a576a925a38b8ab216e6d41f3358a6/shape.DType -> @a:Array<U32> -> @b:Array<U32> -> Array<U32>

two trees of the same shape, cell by cell

def node_of source · line 95 · raw

@p:Pair(Array<U32>, Array<U32>) -> Array<U32>

def rep source · line 100 · raw

@d:Nat -> @t:Array<U32> -> Array<U32>

def keeps source · line 107 · raw

@n:Nat -> @rest:List<&2, Step> -> List<&2, Step>

def step_pick source · line 115 · raw

@e:Bool -> @+y:Nat -> @rest:List<&2, Step> -> List<&2, Step>

the steps that stretch an operand of shape a (as many dimensions as s, missing ones as 1) to s

def steps source · line 122 · raw

@a:List<&2, Nat> -> @s:List<&2, Nat> -> List<&2, Step>

def bto source · line 129 · raw

@st:List<&2, Step> -> @t:Array<U32> -> Array<U32>

def ones source · line 141 · raw

@n:Nat -> @rest:List<&2, Nat> -> List<&2, Nat>

def pad_to source · line 149 · raw

@+a:List<&2, Nat> -> @+s:List<&2, Nat> -> List<&2, Nat>

a (fewer or as many dimensions as s) with leading 1s up to s's count

def stretch source · line 153 · raw

@+a:List<&2, Nat> -> @+s:List<&2, Nat> -> @t:Array<U32> -> Array<U32>

t, of shape a, stretched to shape s (a broadcasts to s)

def comb source · line 158 · raw

@+op:0xe2a576a925a38b8ab216e6d41f3358a6/cells.B2 -> @+dt:0xe2a576a925a38b8ab216e6d41f3358a6/shape.DType -> @a:Maybe<&1, Array<U32>> -> @b:Maybe<&1, Array<U32>> -> Maybe<&1, Array<U32>>

def keep_if source · line 167 · raw

@ok:Bool -> @t:Array<U32> -> Maybe<&1, Array<U32>>

def red_axis source · line 175 · raw

@+op:0xe2a576a925a38b8ab216e6d41f3358a6/cells.B2 -> @+dt:0xe2a576a925a38b8ab216e6d41f3358a6/shape.DType -> @h:Nat -> @t:Array<U32> -> @+lo:Nat -> @+n:Nat -> Maybe<&1, Array<U32>>

the sub-arrays below h levels whose positions (from lo) are below n, combined in pairs, left before right

def or_fill source · line 185 · raw

@+d:Nat -> @m:Maybe<&1, Array<U32>> -> Array<U32>

def red_at source · line 193 · raw

@+op:0xe2a576a925a38b8ab216e6d41f3358a6/cells.B2 -> @+dt:0xe2a576a925a38b8ab216e6d41f3358a6/shape.DType -> @pre:Nat -> @t:Array<U32> -> @+h:Nat -> @+n:Nat -> @+rd:Nat -> Array<U32>

reduce the axis whose levels start pre levels down (h levels, n elements; rd levels below it); n >= 1

def sink source · line 206 · raw

@b:Nat -> @t:Array<U32> -> Array<U32>

the top level moves below the next b levels

def sink_at source · line 215 · raw

@k:Nat -> @+b:Nat -> @t:Array<U32> -> Array<U32>

sink(b) applied at depth k

def swap_groups source · line 226 · raw

@a:Nat -> @+b:Nat -> @t:Array<U32> -> Array<U32>

the top a levels moved below the next b levels, the deepest of them first

def swap_at source · line 234 · raw

@off:Nat -> @+a:Nat -> @+b:Nat -> @t:Array<U32> -> Array<U32>

swap_groups at depth off

def kids source · line 247 · raw

@h:Nat -> @t:Array<U32> -> List<&1, Array<U32>>

the 2^h sub-arrays h levels down, in order

def take source · line 256 · raw

@n:Nat -> @xs:List<&1, Array<U32>> -> List<&1, Array<U32>>

def drop source · line 263 · raw

@n:Nat -> @xs:List<&1, Array<U32>> -> List<&1, Array<U32>>

def pair_up source · line 271 · raw

@xs:List<&1, Array<U32>> -> @+d:Nat -> List<&1, Array<U32>>

pairs of neighbours joined into one level, the last padded with a tree of d levels

def build source · line 281 · raw

@h:Nat -> @xs:List<&1, Array<U32>> -> @+d:Nat -> Array<U32>

a tree of h levels over xs (at most 2^h of them, each of d levels), padded at the end

def every source · line 291 · raw

@m:Nat -> @xs:List<&1, Array<U32>> -> @+skip:Nat -> List<&1, Array<U32>>

every n-th of xs from the first, m of them

def slice_at source · line 301 · raw

@pre:Nat -> @t:Array<U32> -> @+h:Nat -> @+start:Nat -> @+step:Nat -> @+m:Nat -> @+h2:Nat -> @+rd:Nat -> Array<U32>

the axis (h levels, n elements; rd levels below) cut to m elements: start, start + step, ...

def concat_at source · line 312 · raw

@pre:Nat -> @a:Array<U32> -> @b:Array<U32> -> @+ha:Nat -> @+na:Nat -> @+hb:Nat -> @+nb:Nat -> @+h:Nat -> @+rd:Nat -> Array<U32>

the axis of a (ha levels, na elements) followed by b's (hb, nb), into h levels

def expand source · line 324 · raw

@+n:Nat -> @+h:Nat -> @ts:List<&1, Array<U32>> -> List<&1, Array<U32>>

def flat source · line 331 · raw

@s:List<&2, Nat> -> @ts:List<&1, Array<U32>> -> List<&1, Array<U32>>

def leaf_vals source · line 338 · raw

@ts:List<&1, Array<U32>> -> List<&2, U32>

def elems source · line 348 · raw

@+s:List<&2, Nat> -> @t:Array<U32> -> List<&2, U32>

the elements of t (shape s) in row-major order

def leaves source · line 351 · raw

@xs:List<&2, U32> -> List<&1, Array<U32>>

def vtake source · line 358 · raw

@n:Nat -> @xs:List<&2, U32> -> List<&2, U32>

def vdrop source · line 365 · raw

@n:Nat -> @xs:List<&2, U32> -> List<&2, U32>

def zeros_list source · line 372 · raw

@n:Nat -> List<&2, U32>

def zero_chunks source · line 379 · raw

@k:Nat -> @+m:Nat -> List<&2, List<&2, U32>>

def split_n source · line 387 · raw

@k:Nat -> @+m:Nat -> @+xs:List<&2, U32> -> List<&2, List<&2, U32>>

xs cut into k pieces of m

def split_all source · line 395 · raw

@cs:List<&2, List<&2, U32>> -> @+n:Nat -> @+h:Nat -> @+m:Nat -> List<&2, List<&2, U32>>

each piece cut into its n sub-blocks of m, then padded with zero blocks to 2^h

def heads source · line 402 · raw

@cs:List<&2, List<&2, U32>> -> List<&2, U32>

def size source · line 411 · raw

@s:List<&2, Nat> -> Nat

def tree_order source · line 419 · raw

@s:List<&2, Nat> -> @cs:List<&2, List<&2, U32>> -> List<&2, U32>

row-major blocks laid out in tree order, padding included

def from_rows source · line 427 · raw

@+s:List<&2, Nat> -> @xs:List<&2, U32> -> Array<U32>

the tree of shape s holding xs (row-major, size(s) of them)

def dense source · line 432 · raw

@s:List<&2, Nat> -> Bool

def tab source · line 440 · raw

@+dt:0xe2a576a925a38b8ab216e6d41f3358a6/shape.DType -> @h:Nat -> @+lo:Nat -> @+n:Nat -> Array<U32>

the tree of h levels whose cell at position i (from lo) holds conv(i) for i < n (0 past n)