ndarray.bend checks
raw source on the hub · import bend-ndarray@0.1.3.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, i32, u32, u8 and bool; an operation takes one dtype (NP.astype converts), and integers wrap around. Shapes follow NumPy (shape.bend and LAWS.bend: broadcasting proved to be NumPy's rule).
5 imports
import Base import ./shape.bend as S import ./cells.bend as C import ./tree.bend as T import ./rng.bend as R
Types
type ND source · line 16 · raw
Type
ND@dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @shape:List<&2, Nat> -> @data:Array<U32> -> ND
type RM source · line 890 · raw
Data
RM@ok:Bool -> @idx:Nat -> RM
Definitions
def f32 source · line 21 · raw
0xcc7fe2a980487676abb11c4601fc801f/shape.DType
def i32 source · line 24 · raw
0xcc7fe2a980487676abb11c4601fc801f/shape.DType
def u32 source · line 27 · raw
0xcc7fe2a980487676abb11c4601fc801f/shape.DType
def u8 source · line 30 · raw
0xcc7fe2a980487676abb11c4601fc801f/shape.DType
def bool source · line 33 · raw
0xcc7fe2a980487676abb11c4601fc801f/shape.DType
def dt_eq source · line 36 · raw
@a:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @b:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> Bool
def dt_name source · line 51 · raw
@dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> String
def nat_strs source · line 64 · raw
@s:List<&2, Nat> -> List<&2, String>
def shape_str source · line 72 · raw
@+s:List<&2, Nat> -> String
a shape as Python writes it: (2, 3), (4,), ()
def cell_str source · line 76 · raw
@dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+x:U32 -> String
an error in words
def why source · line 87 · raw
@e:0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr -> String
def dtype source · line 126 · raw
@a:ND -> Pair(0xcc7fe2a980487676abb11c4601fc801f/shape.DType, ND)
def shape source · line 131 · raw
@a:ND -> Pair(List<&2, Nat>, ND)
def clone_got source · line 136 · raw
@+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @p:Pair(Array<U32>, Array<U32>) -> Pair(ND, ND)
def clone source · line 143 · raw
@a:ND -> Pair(ND, ND)
def full source · line 148 · raw
@+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @+v:U32 -> ND
def zeros source · line 151 · raw
@+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> ND
def one_of source · line 154 · raw
@dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> U32
def ones source · line 161 · raw
@+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> ND
def count_pick source · line 164 · raw
@ok:Bool -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @xs:List<&2, U32> -> @+got:Nat -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def from_list source · line 172 · raw
@+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @+xs:List<&2, U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
an array of shape s from its elements in row-major order (cells: float32 bits for f32, see cells.bend)
def bits_of source · line 175 · raw
@xs:List<&2, F32> -> List<&2, U32>
def floats_of source · line 182 · raw
@xs:List<&2, U32> -> List<&2, F32>
def from_f32s source · line 190 · raw
@+s:List<&2, Nat> -> @xs:List<&2, F32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
a float32 array from floats
def to_list source · line 194 · raw
@a:ND -> List<&2, U32>
the elements in row-major order (cells)
def to_f32s source · line 199 · raw
@a:ND -> List<&2, F32>
def range_cells source · line 202 · raw
@+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @i:Nat -> @+n:Nat -> List<&2, U32>
def arange source · line 210 · raw
@+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+n:Nat -> ND
0, 1, ..., n - 1
def lin_cells source · line 213 · raw
@+start:F32 -> @+step:F32 -> @+stop:F32 -> @i:Nat -> @+n:Nat -> List<&2, U32>
def linspace source · line 223 · raw
@+start:F32 -> @+stop:F32 -> @+num:Nat -> ND
num float32s from start to stop, both included
def eye_cells source · line 226 · raw
@+one:U32 -> @i:Nat -> @+n:Nat -> List<&2, U32>
def eye source · line 234 · raw
@+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+n:Nat -> ND
the n x n identity
def out_dt source · line 239 · raw
@op:0xcc7fe2a980487676abb11c4601fc801f/cells.B2 -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> 0xcc7fe2a980487676abb11c4601fc801f/shape.DType
def bin_shaped source · line 242 · raw
@r:Result<&2, &2, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, List<&2, Nat>> -> @+op:0xcc7fe2a980487676abb11c4601fc801f/cells.B2 -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+sa:List<&2, Nat> -> @+sb:List<&2, Nat> -> @ta:Array<U32> -> @tb:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def bin_typed source · line 249 · raw
@ok:Bool -> @+op:0xcc7fe2a980487676abb11c4601fc801f/cells.B2 -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+sa:List<&2, Nat> -> @+sb:List<&2, Nat> -> @ta:Array<U32> -> @tb:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def bin_same source · line 256 · raw
@same:Bool -> @+op:0xcc7fe2a980487676abb11c4601fc801f/cells.B2 -> @+da:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+db:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+sa:List<&2, Nat> -> @+sb:List<&2, Nat> -> @ta:Array<U32> -> @tb:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def binop source · line 264 · raw
@+op:0xcc7fe2a980487676abb11c4601fc801f/cells.B2 -> @a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
a binary operation (cells.bend's B2), broadcasting a and b
def add source · line 269 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def subtract source · line 272 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def multiply source · line 275 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def divide source · line 279 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
true division, float32 only (integers: floor_divide)
def floor_divide source · line 282 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def remainder source · line 285 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def minimum source · line 288 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def maximum source · line 291 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def power source · line 294 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def equal source · line 297 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def not_equal source · line 300 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def less source · line 303 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def less_equal source · line 306 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def greater source · line 309 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def greater_equal source · line 312 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def logical_and source · line 315 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def logical_or source · line 318 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def logical_xor source · line 321 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def un_typed source · line 324 · raw
@ok:Bool -> @+op:0xcc7fe2a980487676abb11c4601fc801f/cells.U1 -> @+name:String -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def negative source · line 331 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def absolute source · line 336 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def logical_not source · line 341 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def math1 source · line 348 · raw
@+f:0xcc7fe2a980487676abb11c4601fc801f/cells.MF -> @+name:String -> @a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def exp source · line 353 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def log source · line 356 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def log2 source · line 359 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def log10 source · line 362 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def sqrt source · line 365 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def sin source · line 368 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def cos source · line 371 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def tan source · line 374 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def arcsin source · line 377 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def arccos source · line 380 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def arctan source · line 383 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def sinh source · line 386 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def cosh source · line 389 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def tanh source · line 392 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def floor source · line 395 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def ceil source · line 398 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def trunc source · line 401 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def rint source · line 404 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def reciprocal source · line 407 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def round source · line 411 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
NumPy's round with no decimals: rint
def square source · line 415 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
x * x, every numeric dtype (integers wrap)
def sign source · line 421 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
-1, 0 or 1, every numeric dtype (float32: nan stays nan)
def arctan2 source · line 427 · raw
@y:ND -> @x:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
the angle of (x, y) from y's sign and the ratio, float32: arctan2(y, x)
def hypot source · line 431 · raw
@a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
sqrt(x * x + y * y) without overflow, float32
def astype source · line 435 · raw
@a:ND -> @+to:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> ND
the same elements as another dtype (float32 to integers rounds toward zero; to uint8 wraps; to bool: nonzero)
def relaid source · line 442 · raw
@dense:Bool -> @+s:List<&2, Nat> -> @+s2:List<&2, Nat> -> @d:Array<U32> -> Array<U32>
def reshaped source · line 450 · raw
@r:Result<&2, &2, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, List<&2, Nat>> -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/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 458 · raw
@a:ND -> @+s2:List<&2, Nat> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
the same elements, in row-major order, in shape s2
def index_of source · line 463 · raw
@+x:Nat -> @xs:List<&2, Nat> -> Nat
def down source · line 471 · 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 478 · raw
@+cur:List<&2, Nat> -> @+j:Nat -> @+k:Nat -> List<&2, Nat>
def iota source · line 481 · raw
@i:Nat -> @+n:Nat -> List<&2, Nat>
def plan source · line 489 · 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 496 · raw
@+s:List<&2, Nat> -> @+i:Nat -> List<&2, Nat>
def apply_swaps source · line 499 · raw
@sw:List<&2, Nat> -> @+s:List<&2, Nat> -> @t:Array<U32> -> Array<U32>
def transposed source · line 506 · raw
@r:Result<&2, &2, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, List<&2, Nat>> -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @+perm:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def transpose source · line 514 · raw
@a:ND -> @+perm:List<&2, Nat> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
axes permuted: result axis k is a's axis perm[k]
def rev_iota source · line 519 · raw
@i:Nat -> List<&2, Nat>
def t source · line 527 · raw
@a:ND -> ND
the axes reversed (NumPy's a.T)
def expanded source · line 532 · raw
@ok:Bool -> @+axis:Nat -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def expand_dims source · line 540 · raw
@a:ND -> @+axis:Nat -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
a new axis of length 1 at axis (0 .. ndim)
def squeezed source · line 545 · raw
@ok:Bool -> @+axis:Nat -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def squeeze source · line 553 · raw
@a:ND -> @+axis:Nat -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
axis removed; it must have length 1
def bto_pick source · line 558 · raw
@ok:Bool -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @+s2:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def broadcast_to source · line 566 · raw
@a:ND -> @+s2:List<&2, Nat> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
a stretched to shape s2 (a must fit s2)
def sliced2 source · line 571 · raw
@+m:Nat -> @+ax:Nat -> @+start:Nat -> @+step:Nat -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def sliced source · line 574 · raw
@ok:Bool -> @+ax:Nat -> @+start:Nat -> @+stop:Nat -> @+step:Nat -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def slice source · line 582 · raw
@a:ND -> @+axis:Nat -> @+start:Nat -> @+stop:Nat -> @+step:Nat -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/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 587 · raw
@r:Result<&2, &2, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, List<&2, Nat>> -> @+ax:Nat -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+sa:List<&2, Nat> -> @+sb:List<&2, Nat> -> @ta:Array<U32> -> @tb:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def join_same source · line 595 · raw
@same:Bool -> @+ax:Nat -> @+da:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+db:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+sa:List<&2, Nat> -> @+sb:List<&2, Nat> -> @ta:Array<U32> -> @tb:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def concatenate source · line 603 · raw
@+axis:Nat -> @a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
a and b joined along axis (equal on every other axis)
def stack_same source · line 608 · raw
@same:Bool -> @+ax:Nat -> @a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def stack_go source · line 615 · raw
@+ax:Nat -> @a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def stack source · line 621 · raw
@+axis:Nat -> @a:ND -> @b:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
a and b (the same shape) joined along a new axis
def identity source · line 627 · raw
@op:0xcc7fe2a980487676abb11c4601fc801f/cells.B2 -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/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 640 · raw
@m:Maybe<&2, U32> -> @+ax:Nat -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s2:List<&2, Nat> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def red_n source · line 647 · raw
@empty:Bool -> @+op:0xcc7fe2a980487676abb11c4601fc801f/cells.B2 -> @+ax:Nat -> @+keep:Bool -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def red_ok source · line 654 · raw
@ok:Bool -> @+op:0xcc7fe2a980487676abb11c4601fc801f/cells.B2 -> @+name:String -> @+ax:Nat -> @+keep:Bool -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def red_dt source · line 661 · raw
@op:0xcc7fe2a980487676abb11c4601fc801f/cells.B2 -> @dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> Bool
def reduce source · line 671 · raw
@+op:0xcc7fe2a980487676abb11c4601fc801f/cells.B2 -> @+name:String -> @a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/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 676 · raw
@a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def prod source · line 679 · raw
@a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def min source · line 682 · raw
@a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def max source · line 685 · raw
@a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def all source · line 688 · raw
@a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def any source · line 691 · raw
@a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def scale_by source · line 694 · raw
@r:Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND> -> @+n:Nat -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def mean_ok source · line 701 · raw
@ok:Bool -> @a:ND -> @+axis:Nat -> @+keep:Bool -> @+n:Nat -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def mean source · line 709 · raw
@a:ND -> @+axis:Nat -> @+keep:Bool -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
the mean along axis, float32 only (of a 0-length axis: nan, as NumPy)
def red_all_go source · line 715 · raw
@k:Nat -> @+op:0xcc7fe2a980487676abb11c4601fc801f/cells.B2 -> @+name:String -> @r:Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/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 722 · raw
@a:ND -> Pair(Nat, ND)
def red_all_at source · line 727 · raw
@p:Pair(Nat, ND) -> @+op:0xcc7fe2a980487676abb11c4601fc801f/cells.B2 -> @+name:String -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def sum_all source · line 732 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def prod_all source · line 735 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def min_all source · line 738 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def max_all source · line 741 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def all_all source · line 744 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def any_all source · line 747 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def mean_all_ok source · line 750 · raw
@ok:Bool -> @+n:Nat -> @a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
def mean_all source · line 758 · raw
@a:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
the mean of every element, float32 only
def in_bounds source · line 765 · raw
@idx:List<&2, Nat> -> @s:List<&2, Nat> -> Bool
def cell_index source · line 775 · 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 782 · raw
@+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @r:Pair(Array<U32>, U32) -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, Pair(U32, ND)>
def get_ok source · line 787 · raw
@ok:Bool -> @+idx:List<&2, Nat> -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @d:Array<U32> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, Pair(U32, ND)>
def get source · line 795 · raw
@a:ND -> @+idx:List<&2, Nat> -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, Pair(U32, ND)>
element idx (one index per axis) and the array back
def and_then source · line 803 · raw
@r:Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND> -> @f:(@_:ND -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>) -> Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>
f applied to r's array, or r's error
def strs_of source · line 811 · raw
@+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @xs:List<&2, U32> -> List<&2, String>
one element as NumPy prints it
def stake source · line 818 · raw
@n:Nat -> @xs:List<&2, String> -> List<&2, String>
def sdrop source · line 825 · raw
@n:Nat -> @xs:List<&2, String> -> List<&2, String>
def groups source · line 833 · 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 840 · raw
@k:Nat -> @+s:String -> String
def sep source · line 848 · 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 851 · raw
@xs:List<&2, String> -> String
def fmt source · line 859 · 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 to_string source · line 867 · raw
@a:ND -> String
the array as NumPy prints it: [[0 1 2]\n [3 4 5]]
def show source · line 873 · raw
@r:Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND> -> String
a result as text: the array, or "error: " and why
def rng source · line 884 · raw
@+seed:U32 -> 0xcc7fe2a980487676abb11c4601fc801f/rng.Gen
def rng64 source · line 887 · raw
@+hi:U32 -> @+lo:U32 -> 0xcc7fe2a980487676abb11c4601fc801f/rng.Gen
def rm_of source · line 894 · 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 902 · raw
@m:RM -> @+d:0xcc7fe2a980487676abb11c4601fc801f/rng.Dist -> @+k0:U32 -> @+k1:U32 -> @+n:U32 -> U32
def gtab source · line 909 · raw
@h:Nat -> @+lo:Nat -> @+rs:List<&2, Nat> -> @+d:0xcc7fe2a980487676abb11c4601fc801f/rng.Dist -> @+k0:U32 -> @+k1:U32 -> @+n:U32 -> Array<U32>
def draw source · line 917 · raw
@+d:0xcc7fe2a980487676abb11c4601fc801f/rng.Dist -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @g:0xcc7fe2a980487676abb11c4601fc801f/rng.Gen -> @+s:List<&2, Nat> -> Pair(ND, 0xcc7fe2a980487676abb11c4601fc801f/rng.Gen)
def random source · line 923 · raw
@g:0xcc7fe2a980487676abb11c4601fc801f/rng.Gen -> @+s:List<&2, Nat> -> Pair(ND, 0xcc7fe2a980487676abb11c4601fc801f/rng.Gen)
float32 uniform in [0, 1): 24 random bits, as NumPy's float32 random
def uniform source · line 927 · raw
@g:0xcc7fe2a980487676abb11c4601fc801f/rng.Gen -> @+s:List<&2, Nat> -> @+low:F32 -> @+high:F32 -> Pair(ND, 0xcc7fe2a980487676abb11c4601fc801f/rng.Gen)
float32 uniform in [low, high): low + (high - low) * random (rounding can give high itself, as in NumPy)
def standard_normal source · line 931 · raw
@g:0xcc7fe2a980487676abb11c4601fc801f/rng.Gen -> @+s:List<&2, Nat> -> Pair(ND, 0xcc7fe2a980487676abb11c4601fc801f/rng.Gen)
float32 normal, mean 0 and standard deviation 1 (Box-Muller)
def normal source · line 934 · raw
@g:0xcc7fe2a980487676abb11c4601fc801f/rng.Gen -> @+s:List<&2, Nat> -> @+mean:F32 -> @+std:F32 -> Pair(ND, 0xcc7fe2a980487676abb11c4601fc801f/rng.Gen)
def int_mask source · line 937 · raw
@dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> U32
def int_dt source · line 944 · raw
@dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> Bool
def range_ok source · line 956 · raw
@+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+low:U32 -> @+high:U32 -> Bool
high above low: signed for int32; for uint8, high at most 256
def ints_drawn source · line 959 · raw
@p:Pair(ND, 0xcc7fe2a980487676abb11c4601fc801f/rng.Gen) -> Pair(Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>, 0xcc7fe2a980487676abb11c4601fc801f/rng.Gen)
def ints_ok source · line 964 · raw
@ok:Bool -> @+rok:Bool -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @g:0xcc7fe2a980487676abb11c4601fc801f/rng.Gen -> @+s:List<&2, Nat> -> @+low:U32 -> @+high:U32 -> Pair(Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>, 0xcc7fe2a980487676abb11c4601fc801f/rng.Gen)
def integers source · line 974 · raw
@g:0xcc7fe2a980487676abb11c4601fc801f/rng.Gen -> @+dt:0xcc7fe2a980487676abb11c4601fc801f/shape.DType -> @+s:List<&2, Nat> -> @+low:U32 -> @+high:U32 -> Pair(Result<&1, &1, 0xcc7fe2a980487676abb11c4601fc801f/shape.NdErr, ND>, 0xcc7fe2a980487676abb11c4601fc801f/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 977 · raw
@xs:List<&2, Nat> -> List<&2, U32>
def permutation source · line 985 · raw
@g:0xcc7fe2a980487676abb11c4601fc801f/rng.Gen -> @+n:Nat -> Pair(ND, 0xcc7fe2a980487676abb11c4601fc801f/rng.Gen)
0 .. n - 1 (int32) in a random order, every order equally likely