~/bend-docscommunity

ndarray.bend checks

raw source on the hub · import bend-ndarray@0.1.4.0/ndarray.bend as Ndarray

bend-ndarray: n-dimensional arrays for Bend 2, in the manner of NumPy.

import bend-ndarray@<version>/ndarray.bend as NP

An ND is a dtype, a shape (a list of Nats) and its elements. Every operation takes its arrays and answers a new one (no views; NP.clone makes two of one). An operation that can fail (shapes that do not broadcast, an axis that does not exist, two dtypes) answers Result<&1, &1, NP.Err, ND>: Done{array} or Fail{why}. dtypes: f32, f64, i32, u32, u8 and bool; an operation takes one dtype (NP.astype converts), and integers wrap around. float64 elements are bend-float64's F64 (two cells each in the tree, tree.bend). Shapes follow NumPy (shape.bend and LAWS.bend: broadcasting proved to be NumPy's rule).

7 imports
import Base
import ./shape.bend as S
import ./cells.bend as C
import ./tree.bend as T
import ./rng.bend as R
import ./cells64.bend as C64
import bend-float64@0.1.8.0/float64.bend as F

Types

type ND source · line 19 · raw

Type

type RM source · line 1014 · raw

Data

Definitions

def f32 source · line 24 · raw

0xb394b5997edb05025e33977930018c47/shape.DType

def f64 source · line 27 · raw

0xb394b5997edb05025e33977930018c47/shape.DType

def i32 source · line 30 · raw

0xb394b5997edb05025e33977930018c47/shape.DType

def u32 source · line 33 · raw

0xb394b5997edb05025e33977930018c47/shape.DType

def u8 source · line 36 · raw

0xb394b5997edb05025e33977930018c47/shape.DType

def bool source · line 39 · raw

0xb394b5997edb05025e33977930018c47/shape.DType

def dt_eq source · line 42 · raw

@a:0xb394b5997edb05025e33977930018c47/shape.DType -> @b:0xb394b5997edb05025e33977930018c47/shape.DType -> Bool

def dt_name source · line 59 · raw

@dt:0xb394b5997edb05025e33977930018c47/shape.DType -> String

def nat_strs source · line 74 · raw

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

def shape_str source · line 82 · raw

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

a shape as Python writes it: (2, 3), (4,), ()

def cell_str source · line 86 · raw

@dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+x:U32 -> String

an error in words

def why source · line 97 · raw

@e:0xb394b5997edb05025e33977930018c47/shape.NdErr -> String

def ps source · line 135 · raw

@dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> List<&2, Nat>

the shape of the tree: s, and for float64 one more level of 2 (each element's two cells)

def dtype source · line 144 · raw

@a:ND -> Pair(0xb394b5997edb05025e33977930018c47/shape.DType, ND)

def shape source · line 149 · raw

@a:ND -> Pair(List<&2, Nat>, ND)

def clone_got source · line 154 · raw

@+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @p:Pair(Array<U32>, Array<U32>) -> Pair(ND, ND)

def clone source · line 161 · raw

@a:ND -> Pair(ND, ND)

def full source · line 167 · raw

@+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @+v:U32 -> ND

every element the cell v (for float64, v is the high word and the low one is 0; full_f64 takes any float64)

def full_f64 source · line 171 · raw

@+s:List<&2, Nat> -> @x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> ND

every element x, float64

def zeros source · line 176 · raw

@+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> ND

def one_of source · line 179 · raw

@dt:0xb394b5997edb05025e33977930018c47/shape.DType -> U32

def ones source · line 188 · raw

@+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> ND

def count_pick source · line 191 · raw

@ok:Bool -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @xs:List<&2, U32> -> @+got:Nat -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def from_list source · line 200 · raw

@+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @+xs:List<&2, U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

an array of shape s from its elements in row-major order (cells: float32 bits for f32, see cells.bend; float64 as two cells each, the high word first: from_f64s takes F64s)

def words_of source · line 203 · raw

@xs:List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64> -> List<&2, U32>

def f64s_of source · line 210 · raw

@xs:List<&2, U32> -> List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>

def from_f64s source · line 218 · raw

@+s:List<&2, Nat> -> @+xs:List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

a float64 array from bend-float64's F64s

def bits_of source · line 221 · raw

@xs:List<&2, F32> -> List<&2, U32>

def floats_of source · line 228 · raw

@xs:List<&2, U32> -> List<&2, F32>

def from_f32s source · line 236 · raw

@+s:List<&2, Nat> -> @xs:List<&2, F32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

a float32 array from floats

def to_list source · line 240 · raw

@a:ND -> List<&2, U32>

the elements in row-major order (cells; float64 two each, the high word first)

def to_f64s source · line 246 · raw

@a:ND -> List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>

a float64 array's elements in row-major order

def to_f32s source · line 249 · raw

@a:ND -> List<&2, F32>

def range_cells source · line 252 · raw

@+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @i:Nat -> @+n:Nat -> List<&2, U32>

def arange source · line 260 · raw

@+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+n:Nat -> ND

0, 1, ..., n - 1

def lin_cells source · line 263 · raw

@+start:F32 -> @+step:F32 -> @+stop:F32 -> @i:Nat -> @+n:Nat -> List<&2, U32>

def lin64 source · line 272 · raw

@+start:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+step:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+stop:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @i:Nat -> @+n:Nat -> List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>

def linspace_f64 source · line 282 · raw

@+start:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+stop:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+num:Nat -> ND

num float64s from start to stop, both included, as NumPy's linspace computes them: i * step + start, the last stop

def linspace source · line 286 · raw

@+start:F32 -> @+stop:F32 -> @+num:Nat -> ND

num float32s from start to stop, both included

def eye_cells source · line 289 · raw

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

def f64_his source · line 296 · raw

@xs:List<&2, U32> -> List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>

def widen_cells source · line 304 · raw

@dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @xs:List<&2, U32> -> List<&2, U32>

float64: each cell as the high word of an element whose low word is 0

def eye source · line 312 · raw

@+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+n:Nat -> ND

the n x n identity

def out_dt source · line 317 · raw

@op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> 0xb394b5997edb05025e33977930018c47/shape.DType

def bin_shaped source · line 320 · raw

@r:Result<&2, &2, 0xb394b5997edb05025e33977930018c47/shape.NdErr, List<&2, Nat>> -> @+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+sa:List<&2, Nat> -> @+sb:List<&2, Nat> -> @ta:Array<U32> -> @tb:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def bin_typed source · line 327 · raw

@ok:Bool -> @+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+sa:List<&2, Nat> -> @+sb:List<&2, Nat> -> @ta:Array<U32> -> @tb:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def bin_same source · line 334 · raw

@same:Bool -> @+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+da:0xb394b5997edb05025e33977930018c47/shape.DType -> @+db:0xb394b5997edb05025e33977930018c47/shape.DType -> @+sa:List<&2, Nat> -> @+sb:List<&2, Nat> -> @ta:Array<U32> -> @tb:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def binop source · line 342 · raw

@+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

a binary operation (cells.bend's B2), broadcasting a and b

def add source · line 347 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def subtract source · line 350 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def multiply source · line 353 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def divide source · line 357 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

true division, float32 only (integers: floor_divide)

def floor_divide source · line 360 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def remainder source · line 363 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def minimum source · line 366 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def maximum source · line 369 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def power source · line 372 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def equal source · line 375 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def not_equal source · line 378 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def less source · line 381 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def less_equal source · line 384 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def greater source · line 387 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def greater_equal source · line 390 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def logical_and source · line 393 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def logical_or source · line 396 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def logical_xor source · line 399 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def un_typed source · line 402 · raw

@ok:Bool -> @+op:0xb394b5997edb05025e33977930018c47/cells.U1 -> @+name:String -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def negative source · line 409 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def absolute source · line 414 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def logical_not source · line 419 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def math1 source · line 426 · raw

@+f:0xb394b5997edb05025e33977930018c47/cells.MF -> @+name:String -> @a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def exp source · line 431 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def log source · line 434 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def log2 source · line 437 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def log10 source · line 440 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def sqrt source · line 443 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def sin source · line 446 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def cos source · line 449 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def tan source · line 452 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def arcsin source · line 455 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def arccos source · line 458 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def arctan source · line 461 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def sinh source · line 464 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def cosh source · line 467 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def tanh source · line 470 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def floor source · line 473 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def ceil source · line 476 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def trunc source · line 479 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def rint source · line 482 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def reciprocal source · line 485 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def round source · line 489 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

NumPy's round with no decimals: rint

def square source · line 493 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

x * x, every numeric dtype (integers wrap)

def sign source · line 499 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

-1, 0 or 1, every numeric dtype (float32: nan stays nan)

def arctan2 source · line 505 · raw

@y:ND -> @x:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

the angle of (x, y) from y's sign and the ratio, float32: arctan2(y, x)

def hypot source · line 509 · raw

@a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

sqrt(x * x + y * y) without overflow, float32

def astype source · line 514 · raw

@a:ND -> @+to:0xb394b5997edb05025e33977930018c47/shape.DType -> ND

the same elements as another dtype (floats to integers round toward zero; to uint8 wraps; to bool: nonzero; float64 to float32 rounds to nearest, ties to even; to float64 is exact)

def relaid source · line 522 · raw

@dense:Bool -> @+s:List<&2, Nat> -> @+s2:List<&2, Nat> -> @d:Array<U32> -> Array<U32>

s and s2 are the trees' shapes (ps)

def reshaped source · line 530 · raw

@r:Result<&2, &2, 0xb394b5997edb05025e33977930018c47/shape.NdErr, List<&2, Nat>> -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

between two shapes without padding the tree is already in row-major order, so it stays as it is

def reshape source · line 538 · raw

@a:ND -> @+s2:List<&2, Nat> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

the same elements, in row-major order, in shape s2

def index_of source · line 543 · raw

@+x:Nat -> @xs:List<&2, Nat> -> Nat

def down source · line 551 · raw

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

k, ..., j - 1 counted down: the adjacent swaps that bring position j to k

def move source · line 558 · raw

@+cur:List<&2, Nat> -> @+j:Nat -> @+k:Nat -> List<&2, Nat>

def iota source · line 561 · raw

@i:Nat -> @+n:Nat -> List<&2, Nat>

def plan source · line 569 · raw

@perm:List<&2, Nat> -> @+k:Nat -> @+cur:List<&2, Nat> -> List<&2, Nat>

the adjacent swaps (i with i + 1) that turn axes 0 .. n - 1 into perm

def swap_dims source · line 576 · raw

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

def apply_swaps source · line 579 · raw

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

def transposed source · line 586 · raw

@r:Result<&2, &2, 0xb394b5997edb05025e33977930018c47/shape.NdErr, List<&2, Nat>> -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @+perm:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def transpose source · line 594 · raw

@a:ND -> @+perm:List<&2, Nat> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

axes permuted: result axis k is a's axis perm[k]

def rev_iota source · line 599 · raw

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

def t source · line 607 · raw

@a:ND -> ND

the axes reversed (NumPy's a.T)

def expanded source · line 612 · raw

@ok:Bool -> @+axis:Nat -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def expand_dims source · line 620 · raw

@a:ND -> @+axis:Nat -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

a new axis of length 1 at axis (0 .. ndim)

def squeezed source · line 625 · raw

@ok:Bool -> @+axis:Nat -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def squeeze source · line 633 · raw

@a:ND -> @+axis:Nat -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

axis removed; it must have length 1

def bto_pick source · line 638 · raw

@ok:Bool -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @+s2:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def broadcast_to source · line 646 · raw

@a:ND -> @+s2:List<&2, Nat> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

a stretched to shape s2 (a must fit s2)

def sliced2 source · line 651 · raw

@+m:Nat -> @+ax:Nat -> @+start:Nat -> @+step:Nat -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def sliced source · line 654 · raw

@ok:Bool -> @+ax:Nat -> @+start:Nat -> @+stop:Nat -> @+step:Nat -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def slice source · line 662 · raw

@a:ND -> @+axis:Nat -> @+start:Nat -> @+stop:Nat -> @+step:Nat -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

a[..., start:stop:step, ...] along axis (step >= 1; start and stop clamped to the axis, as Python's slices)

def joined source · line 667 · raw

@r:Result<&2, &2, 0xb394b5997edb05025e33977930018c47/shape.NdErr, List<&2, Nat>> -> @+ax:Nat -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+sa:List<&2, Nat> -> @+sb:List<&2, Nat> -> @ta:Array<U32> -> @tb:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def join_same source · line 675 · raw

@same:Bool -> @+ax:Nat -> @+da:0xb394b5997edb05025e33977930018c47/shape.DType -> @+db:0xb394b5997edb05025e33977930018c47/shape.DType -> @+sa:List<&2, Nat> -> @+sb:List<&2, Nat> -> @ta:Array<U32> -> @tb:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def concatenate source · line 683 · raw

@+axis:Nat -> @a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

a and b joined along axis (equal on every other axis)

def stack_same source · line 688 · raw

@same:Bool -> @+ax:Nat -> @a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def stack_go source · line 695 · raw

@+ax:Nat -> @a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def stack source · line 701 · raw

@+axis:Nat -> @a:ND -> @b:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

a and b (the same shape) joined along a new axis

def identity source · line 707 · raw

@op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> Maybe<&2, U32>

the cells an empty reduction gives: sum 0, prod 1, all true, any false; min and max have none

def red_empty source · line 720 · raw

@m:Maybe<&2, U32> -> @+ax:Nat -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s2:List<&2, Nat> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def red_n source · line 727 · raw

@empty:Bool -> @+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+ax:Nat -> @+keep:Bool -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def red_ok source · line 734 · raw

@ok:Bool -> @+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+name:String -> @+ax:Nat -> @+keep:Bool -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def red_dt source · line 741 · raw

@op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @dt:0xb394b5997edb05025e33977930018c47/shape.DType -> Bool

def reduce source · line 751 · raw

@+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+name:String -> @a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

a reduction along axis, the axis kept as length 1 with keep; pairs combine left to right, as a balanced tree

def sum source · line 756 · raw

@a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def prod source · line 759 · raw

@a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def min source · line 762 · raw

@a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def max source · line 765 · raw

@a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def all source · line 768 · raw

@a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def any source · line 771 · raw

@a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def scale_by source · line 774 · raw

@r:Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND> -> @+n:Nat -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def mean_ok source · line 781 · raw

@ok:Bool -> @a:ND -> @+axis:Nat -> @+keep:Bool -> @+n:Nat -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def mean source · line 789 · raw

@a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

the mean along axis, floats only (of a 0-length axis: nan, as NumPy)

def red_all_go source · line 795 · raw

@k:Nat -> @+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+name:String -> @r:Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

a reduction over every element: the axes reduced one at a time, the last first (a 0-d result)

def ndim_of source · line 802 · raw

@a:ND -> Pair(Nat, ND)

def red_all_at source · line 807 · raw

@p:Pair(Nat, ND) -> @+op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+name:String -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def sum_all source · line 812 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def prod_all source · line 815 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def min_all source · line 818 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def max_all source · line 821 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def all_all source · line 824 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def any_all source · line 827 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def mean_all_ok source · line 830 · raw

@ok:Bool -> @+n:Nat -> @a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

def mean_all source · line 838 · raw

@a:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

the mean of every element, floats only

def in_bounds source · line 845 · raw

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

def cell_index source · line 855 · raw

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

the cell index of element idx: each axis's index in its dep(n) bits, the first axis's highest

def got source · line 862 · raw

@+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @r:Pair(Array<U32>, U32) -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, Pair(U32, ND)>

def get_ok source · line 867 · raw

@ok:Bool -> @+idx:List<&2, Nat> -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, Pair(U32, ND)>

def get_dt source · line 874 · raw

@w:Bool -> @+idx:List<&2, Nat> -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, Pair(U32, ND)>

def get source · line 882 · raw

@a:ND -> @+idx:List<&2, Nat> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, Pair(U32, ND)>

element idx (one index per axis) and the array back (not float64: get_f64)

def got2 source · line 887 · raw

@+s:List<&2, Nat> -> @+h:U32 -> @r:Pair(Array<U32>, U32) -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, Pair(0x72aa159312099184b98e33378b057a0a/float64.F64, ND)>

def got1 source · line 892 · raw

@+s:List<&2, Nat> -> @+i:Nat -> @r:Pair(Array<U32>, U32) -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, Pair(0x72aa159312099184b98e33378b057a0a/float64.F64, ND)>

def get64_ok source · line 897 · raw

@ok:Bool -> @+idx:List<&2, Nat> -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, Pair(0x72aa159312099184b98e33378b057a0a/float64.F64, ND)>

def get_f64 source · line 905 · raw

@a:ND -> @+idx:List<&2, Nat> -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, Pair(0x72aa159312099184b98e33378b057a0a/float64.F64, ND)>

element idx of a float64 array and the array back

def and_then source · line 913 · raw

@r:Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND> -> @f:(@_:ND -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>) -> Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>

f applied to r's array, or r's error

def strs_of source · line 921 · raw

@+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @xs:List<&2, U32> -> List<&2, String>

one element as NumPy prints it

def stake source · line 928 · raw

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

def sdrop source · line 935 · raw

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

def groups source · line 943 · raw

@k:Nat -> @+n:Nat -> @+sep:String -> @+xs:List<&2, String> -> List<&2, String>

k groups of n strings, each joined by sep in brackets

def times source · line 950 · raw

@k:Nat -> @+s:String -> String

def sep source · line 958 · raw

@+i:Nat -> @+d:Nat -> String

NumPy's separator between the items of axis i of d: a space innermost, else newlines and an indent

def first_str source · line 961 · raw

@xs:List<&2, String> -> String

def fmt source · line 969 · raw

@rs:List<&2, Nat> -> @+d:Nat -> @+strs:List<&2, String> -> String

the axes from the innermost out (rs reversed), grouping the strings at each

def strs64 source · line 976 · raw

@xs:List<&2, U32> -> List<&2, String>

def strs_k source · line 983 · raw

@w:Bool -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @xs:List<&2, U32> -> List<&2, String>

def to_string source · line 991 · raw

@a:ND -> String

the array as NumPy prints it: [[0 1 2]\n [3 4 5]] (float64 elements as Python's repr writes them)

def show source · line 997 · raw

@r:Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND> -> String

a result as text: the array, or "error: " and why

def rng source · line 1008 · raw

@+seed:U32 -> 0xb394b5997edb05025e33977930018c47/rng.Gen

def rng64 source · line 1011 · raw

@+hi:U32 -> @+lo:U32 -> 0xb394b5997edb05025e33977930018c47/rng.Gen

def rm_of source · line 1018 · raw

@rs:List<&2, Nat> -> @+p:Nat -> @+stride:Nat -> @+acc:Nat -> @ok:Bool -> RM

a tree position's row-major index (rs: the shape reversed), and whether it is an element (not padding)

def leaf source · line 1026 · raw

@m:RM -> @+d:0xb394b5997edb05025e33977930018c47/rng.Dist -> @+k0:U32 -> @+k1:U32 -> @+n:U32 -> U32

def gtab source · line 1033 · raw

@h:Nat -> @+lo:Nat -> @+rs:List<&2, Nat> -> @+d:0xb394b5997edb05025e33977930018c47/rng.Dist -> @+k0:U32 -> @+k1:U32 -> @+n:U32 -> Array<U32>

def draw source · line 1041 · raw

@+d:0xb394b5997edb05025e33977930018c47/rng.Dist -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @g:0xb394b5997edb05025e33977930018c47/rng.Gen -> @+s:List<&2, Nat> -> Pair(ND, 0xb394b5997edb05025e33977930018c47/rng.Gen)

def random source · line 1047 · raw

@g:0xb394b5997edb05025e33977930018c47/rng.Gen -> @+s:List<&2, Nat> -> Pair(ND, 0xb394b5997edb05025e33977930018c47/rng.Gen)

float32 uniform in [0, 1): 24 random bits, as NumPy's float32 random

def uniform source · line 1051 · raw

@g:0xb394b5997edb05025e33977930018c47/rng.Gen -> @+s:List<&2, Nat> -> @+low:F32 -> @+high:F32 -> Pair(ND, 0xb394b5997edb05025e33977930018c47/rng.Gen)

float32 uniform in [low, high): low + (high - low) * random (rounding can give high itself, as in NumPy)

def standard_normal source · line 1055 · raw

@g:0xb394b5997edb05025e33977930018c47/rng.Gen -> @+s:List<&2, Nat> -> Pair(ND, 0xb394b5997edb05025e33977930018c47/rng.Gen)

float32 normal, mean 0 and standard deviation 1 (Box-Muller)

def normal source · line 1058 · raw

@g:0xb394b5997edb05025e33977930018c47/rng.Gen -> @+s:List<&2, Nat> -> @+mean:F32 -> @+std:F32 -> Pair(ND, 0xb394b5997edb05025e33977930018c47/rng.Gen)

def leaf64 source · line 1061 · raw

@m:RM -> @+d:0xb394b5997edb05025e33977930018c47/rng.Dist64 -> @+k0:U32 -> @+k1:U32 -> @+n:U32 -> Array<U32>

def gtab64 source · line 1068 · raw

@h:Nat -> @+lo:Nat -> @+rs:List<&2, Nat> -> @+d:0xb394b5997edb05025e33977930018c47/rng.Dist64 -> @+k0:U32 -> @+k1:U32 -> @+n:U32 -> Array<U32>

def draw64 source · line 1076 · raw

@+d:0xb394b5997edb05025e33977930018c47/rng.Dist64 -> @g:0xb394b5997edb05025e33977930018c47/rng.Gen -> @+s:List<&2, Nat> -> Pair(ND, 0xb394b5997edb05025e33977930018c47/rng.Gen)

def random_f64 source · line 1082 · raw

@g:0xb394b5997edb05025e33977930018c47/rng.Gen -> @+s:List<&2, Nat> -> Pair(ND, 0xb394b5997edb05025e33977930018c47/rng.Gen)

float64 uniform in [0, 1): 53 random bits, as NumPy's float64 random

def uniform_f64 source · line 1086 · raw

@g:0xb394b5997edb05025e33977930018c47/rng.Gen -> @+s:List<&2, Nat> -> @+low:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+high:0x72aa159312099184b98e33378b057a0a/float64.F64 -> Pair(ND, 0xb394b5997edb05025e33977930018c47/rng.Gen)

float64 uniform in [low, high): low + (high - low) * random_f64

def standard_normal_f64 source · line 1090 · raw

@g:0xb394b5997edb05025e33977930018c47/rng.Gen -> @+s:List<&2, Nat> -> Pair(ND, 0xb394b5997edb05025e33977930018c47/rng.Gen)

float64 normal, mean 0 and standard deviation 1 (Box-Muller, with bend-float64's correctly rounded log, sqrt and cos)

def normal_f64 source · line 1093 · raw

@g:0xb394b5997edb05025e33977930018c47/rng.Gen -> @+s:List<&2, Nat> -> @+mean:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+std:0x72aa159312099184b98e33378b057a0a/float64.F64 -> Pair(ND, 0xb394b5997edb05025e33977930018c47/rng.Gen)

def int_mask source · line 1096 · raw

@dt:0xb394b5997edb05025e33977930018c47/shape.DType -> U32

def int_dt source · line 1103 · raw

@dt:0xb394b5997edb05025e33977930018c47/shape.DType -> Bool

def range_ok source · line 1115 · raw

@+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+low:U32 -> @+high:U32 -> Bool

high above low: signed for int32; for uint8, high at most 256

def ints_drawn source · line 1118 · raw

@p:Pair(ND, 0xb394b5997edb05025e33977930018c47/rng.Gen) -> Pair(Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>, 0xb394b5997edb05025e33977930018c47/rng.Gen)

def ints_ok source · line 1123 · raw

@ok:Bool -> @+rok:Bool -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @g:0xb394b5997edb05025e33977930018c47/rng.Gen -> @+s:List<&2, Nat> -> @+low:U32 -> @+high:U32 -> Pair(Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>, 0xb394b5997edb05025e33977930018c47/rng.Gen)

def integers source · line 1133 · raw

@g:0xb394b5997edb05025e33977930018c47/rng.Gen -> @+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @+low:U32 -> @+high:U32 -> Pair(Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, ND>, 0xb394b5997edb05025e33977930018c47/rng.Gen)

integers in [low, high) of an integer dtype (low and high as that dtype's cells), every value equally likely

def nat_cells source · line 1136 · raw

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

def permutation source · line 1144 · raw

@g:0xb394b5997edb05025e33977930018c47/rng.Gen -> @+n:Nat -> Pair(ND, 0xb394b5997edb05025e33977930018c47/rng.Gen)

0 .. n - 1 (int32) in a random order, every order equally likely