f32array.bend checks
raw source on the hub · import bend-kit-f32array@0.2.1.0/f32array.bend as F32array
Packed F32 arrays: get, set, slice, concat, map, fold, zip, dot, sum, max, and little- or big-endian Bytes and files. Source: https://github.com/paymog/bend-kit/tree/main/f32array
2 imports
import Base import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes
Types
type Cell source · line 6 · raw
Data
Eight elements per Array slot, so one access reads or writes eight.
Cell@v0:F32 -> @v1:F32 -> @v2:F32 -> @v3:F32 -> @v4:F32 -> @v5:F32 -> @v6:F32 -> @v7:F32 -> Cell
type F32Array source · line 10 · raw
Type
Element i is lane i % 8 of cell i / 8. buf has the fewest 2^d cells that hold len elements, and every lane at or past len is +0.0.
F32Array@len:U32 -> @buf:Array<Cell> -> F32Array
Definitions
def of_bits source · line 13 · raw
@x:U32 -> F32
def to_bits source · line 18 · raw
@x:F32 -> U32
def of_bits.be source · line 23 · raw
@x:U32 -> F32
def to_bits.be source · line 27 · raw
@x:F32 -> U32
def zero source · line 30 · raw
Cell
def cells source · line 33 · raw
@+n:U32 -> U32
def alloc source · line 36 · raw
@+n:U32 -> Array<Cell>
def lane source · line 40 · raw
@c:Cell -> @+k:U32 -> F32
Lane k, for k < 8.
def put source · line 44 · raw
@c:Cell -> @+k:U32 -> @+v:F32 -> Cell
def mask source · line 49 · raw
@c:Cell -> @+k:U32 -> Cell
Lanes at or past k become +0.0.
def peek.of source · line 54 · raw
@+k:U32 -> @r:Pair(Array<Cell>, Cell) -> Pair(Array<Cell>, F32)
Unchecked element read and write. Callers keep i below len.
def peek source · line 58 · raw
@a:Array<Cell> -> @+i:U32 -> Pair(Array<Cell>, F32)
def poke.of source · line 61 · raw
@+i:U32 -> @+v:F32 -> @r:Pair(Array<Cell>, Cell) -> Array<Cell>
def poke source · line 65 · raw
@a:Array<Cell> -> @+i:U32 -> @+v:F32 -> Array<Cell>
def trim.of source · line 68 · raw
@+j:U32 -> @+k:U32 -> @r:Pair(Array<Cell>, Cell) -> Array<Cell>
def trim.if source · line 72 · raw
@part:Bool -> @a:Array<Cell> -> @+len:U32 -> Array<Cell>
def trim source · line 80 · raw
@a:Array<Cell> -> @+len:U32 -> Array<Cell>
The lanes past len in its last cell become +0.0 again.
def new source · line 84 · raw
@+n:U32 -> F32Array
n zeros.
def length source · line 87 · raw
@a:F32Array -> Pair(F32Array, U32)
def get.some source · line 91 · raw
@+len:U32 -> @r:Pair(Array<Cell>, F32) -> Pair(F32Array, Maybe<&2, F32>)
def get.if source · line 95 · raw
@ok:Bool -> @+len:U32 -> @buf:Array<Cell> -> @+i:U32 -> Pair(F32Array, Maybe<&2, F32>)
def get source · line 103 · raw
@a:F32Array -> @+i:U32 -> Pair(F32Array, Maybe<&2, F32>)
Element i, or None when i >= len.
def set.if source · line 107 · raw
@ok:Bool -> @+len:U32 -> @buf:Array<Cell> -> @+i:U32 -> @+v:F32 -> F32Array
def set source · line 115 · raw
@a:F32Array -> @+i:U32 -> @+v:F32 -> F32Array
Element i becomes v. Nothing changes when i >= len.
def count source · line 119 · raw
@xs:List<&2, F32> -> @+n:U32 -> U32
def from_list.go source · line 126 · raw
@xs:List<&2, F32> -> @a:Array<Cell> -> @+i:U32 -> Array<Cell>
def from_list source · line 133 · raw
@+xs:List<&2, F32> -> F32Array
def to_list.go source · line 138 · raw
@n:Nat -> @r:Pair(Array<Cell>, F32) -> @+i:U32 -> @acc:List<&2, F32> -> List<&2, F32>
r holds element i; the list is built from the last element back.
def to_list source · line 146 · raw
@a:F32Array -> List<&2, F32>
def copy.go source · line 151 · raw
@n:Nat -> @r:Pair(Array<Cell>, F32) -> @dst:Array<Cell> -> @+s:U32 -> @+d:U32 -> Pair(Array<Cell>, Array<Cell>)
n elements from src[s..] to dst[d..]; r holds src[s].
def copy.cells source · line 161 · raw
@n:Nat -> @r:Pair(Array<Cell>, Cell) -> @dst:Array<Cell> -> @+s:U32 -> @+d:U32 -> Pair(Array<Cell>, Array<Cell>)
n whole cells from src[s..] to dst[d..] (cell indexes); r holds src cell s.
def copy.trim source · line 170 · raw
@+end:U32 -> @r:Pair(Array<Cell>, Array<Cell>) -> Pair(Array<Cell>, Array<Cell>)
def copy.pick source · line 174 · raw
@aligned:Bool -> @+m:U32 -> @src:Array<Cell> -> @dst:Array<Cell> -> @+s:U32 -> @+d:U32 -> Pair(Array<Cell>, Array<Cell>)
def copy source · line 182 · raw
@+m:U32 -> @src:Array<Cell> -> @dst:Array<Cell> -> @+s:U32 -> @+d:U32 -> Pair(Array<Cell>, Array<Cell>)
m elements from src[s..] to dst[d..]. When both are cell-aligned, whole cells move, and dst's lanes past d + m in its last cell become +0.0.
def slice.fin source · line 185 · raw
@+len:U32 -> @+m:U32 -> @r:Pair(Array<Cell>, Array<Cell>) -> Pair(F32Array, F32Array)
def slice source · line 190 · raw
@a:F32Array -> @+start:U32 -> @+n:U32 -> Pair(F32Array, F32Array)
The array back, and a copy of up to n elements from start. Both ends are clamped to len.
def concat.total.con source · line 196 · raw
@x:F32Array -> @r:Pair(List<&1, F32Array>, U32) -> Pair(List<&1, F32Array>, U32)
def concat.total source · line 200 · raw
@xs:List<&1, F32Array> -> @+n:U32 -> Pair(List<&1, F32Array>, U32)
def snd source · line 207 · raw
@r:Pair(Array<Cell>, Array<Cell>) -> Array<Cell>
def concat.go source · line 211 · raw
@xs:List<&1, F32Array> -> @out:Array<Cell> -> @+at:U32 -> Array<Cell>
def concat.of source · line 218 · raw
@r:Pair(List<&1, F32Array>, U32) -> F32Array
def concat source · line 223 · raw
@xs:List<&1, F32Array> -> F32Array
The pieces in order, in one new array.
def fold.fin source · line 269 · raw
@-A:Data -> @+len:U32 -> @r:Pair(Array<Cell>, A) -> Pair(F32Array, A)
def zip.fin source · line 295 · raw
@+la:U32 -> @+lb:U32 -> @r:Pair(Array<Cell>, Array<Cell>) -> Pair(F32Array, Pair(F32Array, Bool))
def add2 source · line 312 · raw
@x:F32 -> @y:F32 -> F32
def mul2 source · line 315 · raw
@x:F32 -> @y:F32 -> F32
def add source · line 319 · raw
@a:F32Array -> @b:F32Array -> Pair(F32Array, Pair(F32Array, Bool))
a[i] + b[i], into a, as zip_with.
def mul source · line 323 · raw
@a:F32Array -> @b:F32Array -> Pair(F32Array, Pair(F32Array, Bool))
a[i] * b[i], into a, as zip_with.
def sum.cell source · line 326 · raw
@c:Cell -> F32
def sum.merge source · line 330 · raw
@r:Pair(Array<Cell>, F32) -> @+x:F32 -> Pair(Array<Cell>, F32)
def sum.block source · line 334 · raw
@n:Nat -> @r:Pair(Array<Cell>, Cell) -> @+i:U32 -> @acc:F32 -> Pair(Array<Cell>, F32)
def sum.right source · line 344 · raw
@next:(@_:Array<Cell> -> Pair(Array<Cell>, F32)) -> @r:Pair(Array<Cell>, F32) -> Pair(Array<Cell>, F32)
def sum.range source · line 348 · raw
@d:Nat -> @+n:U32 -> @+i:U32 -> @a:Array<Cell> -> Pair(Array<Cell>, F32)
def sum.fin source · line 356 · raw
@+len:U32 -> @r:Pair(Array<Cell>, F32) -> Pair(F32Array, F32)
def sum source · line 361 · raw
@a:F32Array -> Pair(F32Array, F32)
ponytail: at most 16 cell totals run sequentially; use finer leaves if their measured rounding error matters.
def max.go source · line 366 · raw
@n:Nat -> @+k:U32 -> @r:Pair(Array<Cell>, Cell) -> @+i:U32 -> @m0:F32 -> @m1:F32 -> @m2:F32 -> @m3:F32 -> Pair(Array<Cell>, F32)
Four running maxima over n whole cells, then the first k lanes of the next cell.
def max.fin source · line 375 · raw
@+len:U32 -> @r:Pair(Array<Cell>, F32) -> Pair(F32Array, Maybe<&2, F32>)
def max.if source · line 379 · raw
@some:Bool -> @+len:U32 -> @buf:Array<Cell> -> @+x:F32 -> Pair(F32Array, Maybe<&2, F32>)
def max.first source · line 386 · raw
@+len:U32 -> @r:Pair(Array<Cell>, F32) -> Pair(F32Array, Maybe<&2, F32>)
def max source · line 391 · raw
@a:F32Array -> Pair(F32Array, Maybe<&2, F32>)
The largest element by Base F32.max, or None when empty. Four running maxima all start at a[0], so a NaN is kept only when it comes first.
def dot.cell source · line 395 · raw
@a:Cell -> @b:Cell -> F32
def dot.merge source · line 400 · raw
@r:Pair(Array<Cell>, Pair(Array<Cell>, F32)) -> @+x:F32 -> Pair(Array<Cell>, Pair(Array<Cell>, F32))
def dot.block source · line 404 · raw
@n:Nat -> @r:Pair(Array<Cell>, Cell) -> @s:Pair(Array<Cell>, Cell) -> @+i:U32 -> @acc:F32 -> Pair(Array<Cell>, Pair(Array<Cell>, F32))
def dot.right source · line 416 · raw
@next:(@_:Array<Cell> -> @_:Array<Cell> -> Pair(Array<Cell>, Pair(Array<Cell>, F32))) -> @r:Pair(Array<Cell>, Pair(Array<Cell>, F32)) -> Pair(Array<Cell>, Pair(Array<Cell>, F32))
def dot.range source · line 420 · raw
@d:Nat -> @+n:U32 -> @+i:U32 -> @a:Array<Cell> -> @b:Array<Cell> -> Pair(Array<Cell>, Pair(Array<Cell>, F32))
def dot.fin source · line 428 · raw
@+la:U32 -> @+lb:U32 -> @r:Pair(Array<Cell>, Pair(Array<Cell>, F32)) -> Pair(F32Array, Pair(F32Array, Maybe<&2, F32>))
def dot.if source · line 432 · raw
@same:Bool -> @+la:U32 -> @xa:Array<Cell> -> @+lb:U32 -> @ya:Array<Cell> -> Pair(F32Array, Pair(F32Array, Maybe<&2, F32>))
def dot source · line 440 · raw
@a:F32Array -> @b:F32Array -> Pair(F32Array, Pair(F32Array, Maybe<&2, F32>))
Both arrays back, and the pairwise sum of a[i] * b[i]. None when the lengths differ.
def from_bytes.le source · line 499 · raw
@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&1, F32Array>
Four bytes per element, least significant first. None when the length is not a multiple of 4.
def from_bytes.be source · line 504 · raw
@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&1, F32Array>
Four bytes per element, most significant first. None when the length is not a multiple of 4.
def to.fin source · line 530 · raw
@+n:U32 -> @r:Pair(Array<Cell>, Array<U32>) -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes
def to_bytes.le source · line 540 · raw
@a:F32Array -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes
Each element as four bytes, least significant first. len must be below 2^30.
def to_bytes.be source · line 544 · raw
@a:F32Array -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes
Each element as four bytes, most significant first. len must be below 2^30.
Templates
template map.cell source · line 226 · raw
@-f:(@_:F32 -> F32) -> @c:Cell -> Cell
template map.step source · line 230 · raw
@-f:(@_:F32 -> F32) -> @+i:U32 -> @r:Pair(Array<Cell>, Cell) -> Array<Cell>
template map.go source · line 235 · raw
@-f:(@_:F32 -> F32) -> @n:Nat -> @a:Array<Cell> -> @+i:U32 -> Array<Cell>
Each pass reads and writes its own cell; the form that read the next cell ahead ran 4x slower.
template map source · line 243 · raw
@-f:(@_:F32 -> F32) -> @a:F32Array -> F32Array
f on each element, in place.
template fold.cell source · line 247 · raw
@-A:Data -> @-f:(@_:A -> @_:F32 -> A) -> @acc:A -> @c:Cell -> A
template fold.lanes source · line 252 · raw
@-A:Data -> @-f:(@_:A -> @_:F32 -> A) -> @n:Nat -> @+c:Cell -> @+j:U32 -> @acc:A -> A
Lanes j .. j + n - 1 of c.
template fold.go source · line 260 · raw
@-A:Data -> @-f:(@_:A -> @_:F32 -> A) -> @n:Nat -> @+k:U32 -> @r:Pair(Array<Cell>, Cell) -> @+i:U32 -> @acc:A -> Pair(Array<Cell>, A)
n whole cells from cell i, then the first k lanes of the next one; r holds cell i.
template fold source · line 274 · raw
@-A:Data -> @-f:(@_:A -> @_:F32 -> A) -> @a:F32Array -> @init:A -> Pair(F32Array, A)
f(...f(f(init, a[0]), a[1])..., a[len-1]), left to right.
template zip.step source · line 278 · raw
@-f:(@_:F32 -> @_:F32 -> F32) -> @+i:U32 -> @r:Pair(Array<Cell>, Cell) -> @s:Pair(Array<Cell>, Cell) -> Pair(Array<Cell>, Array<Cell>)
template zip.at source · line 283 · raw
@-f:(@_:F32 -> @_:F32 -> F32) -> @+i:U32 -> @ab:Pair(Array<Cell>, Array<Cell>) -> Pair(Array<Cell>, Array<Cell>)
template zip.go source · line 288 · raw
@-f:(@_:F32 -> @_:F32 -> F32) -> @n:Nat -> @ab:Pair(Array<Cell>, Array<Cell>) -> @+i:U32 -> Pair(Array<Cell>, Array<Cell>)
f(a's cell i, b's cell i) goes into a.
template zip.if source · line 299 · raw
@-f:(@_:F32 -> @_:F32 -> F32) -> @same:Bool -> @+la:U32 -> @xa:Array<Cell> -> @+lb:U32 -> @ya:Array<Cell> -> Pair(F32Array, Pair(F32Array, Bool))
template zip_with source · line 307 · raw
@-f:(@_:F32 -> @_:F32 -> F32) -> @a:F32Array -> @b:F32Array -> Pair(F32Array, Pair(F32Array, Bool))
f(a[i], b[i]) for each i, written into a, and b back. When the lengths differ, both come back unchanged beside False.
template from.c7 source · line 446 · raw
@-f:(@_:U32 -> F32) -> @+j:U32 -> @r:Pair(Array<U32>, U32) -> @+x0:U32 -> @+x1:U32 -> @+x2:U32 -> @+x3:U32 -> @+x4:U32 -> @+x5:U32 -> @+x6:U32 -> Pair(Array<U32>, Cell)
Words j .. j + 7 of a Bytes buffer as one cell; r holds word j.
template from.c6 source · line 450 · raw
@-f:(@_:U32 -> F32) -> @+j:U32 -> @r:Pair(Array<U32>, U32) -> @+x0:U32 -> @+x1:U32 -> @+x2:U32 -> @+x3:U32 -> @+x4:U32 -> @+x5:U32 -> Pair(Array<U32>, Cell)
template from.c5 source · line 454 · raw
@-f:(@_:U32 -> F32) -> @+j:U32 -> @r:Pair(Array<U32>, U32) -> @+x0:U32 -> @+x1:U32 -> @+x2:U32 -> @+x3:U32 -> @+x4:U32 -> Pair(Array<U32>, Cell)
template from.c4 source · line 458 · raw
@-f:(@_:U32 -> F32) -> @+j:U32 -> @r:Pair(Array<U32>, U32) -> @+x0:U32 -> @+x1:U32 -> @+x2:U32 -> @+x3:U32 -> Pair(Array<U32>, Cell)
template from.c3 source · line 462 · raw
@-f:(@_:U32 -> F32) -> @+j:U32 -> @r:Pair(Array<U32>, U32) -> @+x0:U32 -> @+x1:U32 -> @+x2:U32 -> Pair(Array<U32>, Cell)
template from.c2 source · line 466 · raw
@-f:(@_:U32 -> F32) -> @+j:U32 -> @r:Pair(Array<U32>, U32) -> @+x0:U32 -> @+x1:U32 -> Pair(Array<U32>, Cell)
template from.c1 source · line 470 · raw
@-f:(@_:U32 -> F32) -> @+j:U32 -> @r:Pair(Array<U32>, U32) -> @+x0:U32 -> Pair(Array<U32>, Cell)
template from.c0 source · line 474 · raw
@-f:(@_:U32 -> F32) -> @+j:U32 -> @r:Pair(Array<U32>, U32) -> Pair(Array<U32>, Cell)
template from.go source · line 479 · raw
@-f:(@_:U32 -> F32) -> @n:Nat -> @r:Pair(Array<U32>, Cell) -> @out:Array<Cell> -> @+i:U32 -> Array<Cell>
r holds cell i; each pass writes cell i and reads cell i + 1.
template from_bytes.if source · line 490 · raw
@-f:(@_:U32 -> F32) -> @aligned:Bool -> @+len:U32 -> @buf:Array<U32> -> Maybe<&1, F32Array>
Reads past the words wrap around, so the last cell is trimmed.
template to.cell source · line 508 · raw
@-g:(@_:F32 -> U32) -> @c:Cell -> @w:Array<U32> -> @+j:U32 -> Array<U32>
template to.tail source · line 513 · raw
@-g:(@_:F32 -> U32) -> @n:Nat -> @+c:Cell -> @w:Array<U32> -> @+j:U32 -> @+l:U32 -> Array<U32>
The first n lanes of c, from lane l, into words j ..
template to.go source · line 521 · raw
@-g:(@_:F32 -> U32) -> @n:Nat -> @+k:U32 -> @r:Pair(Array<Cell>, Cell) -> @w:Array<U32> -> @+i:U32 -> Pair(Array<Cell>, Array<U32>)
n whole cells from cell i, then the first k lanes of the next one, so no write runs past the words.
template to_bytes.with source · line 534 · raw
@-g:(@_:F32 -> U32) -> @a:F32Array -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes