tree.bend checks
raw source on the hub · import bend-ndarray@0.1.4.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. A float64 element is two cells, its high word then its low one, under one node: the tree of a float64 array of shape s is that of shape s + [2], so moving elements (reshape, transpose, slices, joins, broadcasting) works on it unchanged, and element-wise operations stop at those nodes.
5 imports
import Base import ./shape.bend as S import ./cells.bend as C import ./cells64.bend as C64 import bend-float64@0.1.8.0/float64.bend as F
Types
type MK source · line 141 · raw
Data
how an operation's elements change width: 32-bit cells, float64 elements, or a conversion one way
K32MK
K64MK
KNarrow@to:0xb394b5997edb05025e33977930018c47/shape.DType -> MK
KWidenMK
type Step source · line 223 · raw
Data
KeepStep
Rep@d:Nat -> Step
Definitions
def pow2 source · line 17 · raw
@n:Nat -> Nat
def dep_if source · line 24 · raw
@done:Bool -> @+d:Nat -> @more:(@_:Unit -> Nat) -> Nat
def dep_go source · line 31 · raw
@fuel:Nat -> @+n:Nat -> @+d:Nat -> @+p:Nat -> Nat
def dep source · line 39 · raw
@+n:Nat -> Nat
the levels a dimension of n elements takes (the least d with 2^d >= n)
def depth source · line 43 · raw
@s:List<&2, Nat> -> Nat
the levels of a whole shape
def depth_before source · line 51 · raw
@s:List<&2, Nat> -> @i:Nat -> Nat
the levels of the dimensions before axis i
def depth_after source · line 61 · raw
@s:List<&2, Nat> -> @i:Nat -> Nat
the levels of the dimensions after axis i
def fill source · line 70 · raw
@+d:Nat -> @+v:U32 -> Array<U32>
def pair source · line 75 · raw
@x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> Array<U32>
def fill2 source · line 80 · raw
@d:Nat -> @+h:U32 -> @+l:U32 -> Array<U32>
def fill_k source · line 88 · raw
@w:Bool -> @+d:Nat -> @+v:U32 -> Array<U32>
def fill_dt source · line 96 · raw
@+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+d:Nat -> @+v:U32 -> Array<U32>
d levels of elements all v (a float64's v is its high word, the low one 0: enough for 0, 1 and the identities)
def amap32 source · line 101 · raw
@+op:0xb394b5997edb05025e33977930018c47/cells.U1 -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @a:Array<U32> -> Array<U32>
def amap64 source · line 110 · raw
@+op:0xb394b5997edb05025e33977930018c47/cells.U1 -> @a:Array<U32> -> Array<U32>
float64 elements to float64 elements
def narrow source · line 121 · raw
@+to:0xb394b5997edb05025e33977930018c47/shape.DType -> @a:Array<U32> -> Array<U32>
float64 elements to cells of dtype to
def widen source · line 132 · raw
@+from:0xb394b5997edb05025e33977930018c47/shape.DType -> @a:Array<U32> -> Array<U32>
cells of dtype from to float64 elements
def conv_kind source · line 147 · raw
@from64:Bool -> @to64:Bool -> @+to:0xb394b5997edb05025e33977930018c47/shape.DType -> MK
def map_kind source · line 158 · raw
@op:0xb394b5997edb05025e33977930018c47/cells.U1 -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> MK
def amap_k source · line 165 · raw
@k:MK -> @+op:0xb394b5997edb05025e33977930018c47/cells.U1 -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @a:Array<U32> -> Array<U32>
def amap source · line 177 · raw
@+op:0xb394b5997edb05025e33977930018c47/cells.U1 -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @a:Array<U32> -> Array<U32>
op on every element of a tree of dtype dt
def zip32 source · line 181 · raw
@+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @a:Array<U32> -> @b:Array<U32> -> Array<U32>
two trees of the same shape, cell by cell
def out64 source · line 192 · raw
@cmp:Bool -> @+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+y:0x72aa159312099184b98e33378b057a0a/float64.F64 -> Array<U32>
a float64 result: a comparison's bool cell, or a float64 element
def zip64 source · line 200 · raw
@+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @a:Array<U32> -> @b:Array<U32> -> Array<U32>
two float64 trees of the same shape, element by element
def zip_k source · line 210 · raw
@w:Bool -> @+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @a:Array<U32> -> @b:Array<U32> -> Array<U32>
def zip source · line 218 · raw
@+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @a:Array<U32> -> @b:Array<U32> -> Array<U32>
two trees of dtype dt and the same shape, element by element
def node_of source · line 227 · raw
@p:Pair(Array<U32>, Array<U32>) -> Array<U32>
def rep_two source · line 234 · raw
@c:Pair(Array<U32>, Array<U32>) -> @f:(@_:Array<U32> -> Array<U32>) -> @g:(@_:Array<U32> -> Array<U32>) -> Array<U32>
2^d copies of t: split first, so each copy is cloned from t itself (not from the copies made so far) and the halves are built in parallel
def rep source · line 240 · raw
@d:Nat -> @t:Array<U32> -> Array<U32>
def keeps source · line 247 · raw
@n:Nat -> @rest:List<&2, Step> -> List<&2, Step>
def step_pick source · line 255 · 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 262 · raw
@a:List<&2, Nat> -> @s:List<&2, Nat> -> List<&2, Step>
def bto source · line 269 · raw
@st:List<&2, Step> -> @t:Array<U32> -> Array<U32>
def ones source · line 281 · raw
@n:Nat -> @rest:List<&2, Nat> -> List<&2, Nat>
def pad_to source · line 289 · 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 293 · 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 298 · raw
@+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @a:Maybe<&1, Array<U32>> -> @b:Maybe<&1, Array<U32>> -> Maybe<&1, Array<U32>>
def keep_if source · line 307 · raw
@ok:Bool -> @t:Array<U32> -> Maybe<&1, Array<U32>>
def red_axis source · line 315 · raw
@+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+dt:0xb394b5997edb05025e33977930018c47/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 325 · raw
@+d:Nat -> @m:Maybe<&1, Array<U32>> -> Array<U32>
def red_at source · line 333 · raw
@+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+dt:0xb394b5997edb05025e33977930018c47/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 346 · raw
@b:Nat -> @t:Array<U32> -> Array<U32>
the top level moves below the next b levels
def sink_at source · line 355 · raw
@k:Nat -> @+b:Nat -> @t:Array<U32> -> Array<U32>
sink(b) applied at depth k
def swap_groups source · line 366 · 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 374 · raw
@off:Nat -> @+a:Nat -> @+b:Nat -> @t:Array<U32> -> Array<U32>
swap_groups at depth off
def kids source · line 387 · raw
@h:Nat -> @t:Array<U32> -> List<&1, Array<U32>>
the 2^h sub-arrays h levels down, in order
def take source · line 396 · raw
@n:Nat -> @xs:List<&1, Array<U32>> -> List<&1, Array<U32>>
def drop source · line 403 · raw
@n:Nat -> @xs:List<&1, Array<U32>> -> List<&1, Array<U32>>
def pair_up source · line 411 · 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 421 · 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 431 · 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 441 · 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 452 · 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 464 · raw
@+n:Nat -> @+h:Nat -> @ts:List<&1, Array<U32>> -> List<&1, Array<U32>>
def flat source · line 471 · raw
@s:List<&2, Nat> -> @ts:List<&1, Array<U32>> -> List<&1, Array<U32>>
def leaf_vals source · line 478 · raw
@ts:List<&1, Array<U32>> -> List<&2, U32>
def elems source · line 488 · 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 491 · raw
@xs:List<&2, U32> -> List<&1, Array<U32>>
def vtake source · line 498 · raw
@n:Nat -> @xs:List<&2, U32> -> List<&2, U32>
def vdrop source · line 505 · raw
@n:Nat -> @xs:List<&2, U32> -> List<&2, U32>
def zeros_list source · line 512 · raw
@n:Nat -> List<&2, U32>
def zero_chunks source · line 519 · raw
@k:Nat -> @+m:Nat -> List<&2, List<&2, U32>>
def split_n source · line 527 · 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 535 · 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 542 · raw
@cs:List<&2, List<&2, U32>> -> List<&2, U32>
def size source · line 551 · raw
@s:List<&2, Nat> -> Nat
def tree_order source · line 559 · 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 dense source · line 568 · raw
@s:List<&2, Nat> -> Bool
def rows_dense source · line 575 · raw
@d:Bool -> @+s:List<&2, Nat> -> @xs:List<&2, U32> -> Array<U32>
def from_rows source · line 583 · raw
@+s:List<&2, Nat> -> @xs:List<&2, U32> -> Array<U32>
the tree of shape s holding xs (row-major, size(s) of them); without padding, row-major is already tree order
def tab32 source · line 587 · raw
@+dt:0xb394b5997edb05025e33977930018c47/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)
def tab64 source · line 596 · raw
@h:Nat -> @+lo:Nat -> @+n:Nat -> Array<U32>
the same for float64 elements
def tab_k source · line 604 · raw
@w:Bool -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+h:Nat -> @+lo:Nat -> @+n:Nat -> Array<U32>
def tab source · line 611 · raw
@+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+h:Nat -> @+lo:Nat -> @+n:Nat -> Array<U32>