shape.bend checks
raw source on the hub · import bend-ndarray@0.1.4.0/shape.bend as Shape
bend-ndarray's shape rules, pure: broadcasting, reshape, transpose, reductions, slices and concatenation decide the result's shape (or why there is none) here, before any data moves. LAWS.bend states what they guarantee.
1 import
import Base
Types
type DType source · line 7 · raw
Data
DF32DType
DF64DType
DI32DType
DU32DType
DU8DType
DBoolDType
type NdErr source · line 15 · raw
Data
NoBroadcast@a:List<&2, Nat> -> @b:List<&2, Nat> -> NdErr
BadReshape@from:List<&2, Nat> -> @to:List<&2, Nat> -> NdErr
BadAxis@axis:Nat -> @ndim:Nat -> NdErr
BadPerm@perm:List<&2, Nat> -> @ndim:Nat -> NdErr
BadConcat@axis:Nat -> @a:List<&2, Nat> -> @b:List<&2, Nat> -> NdErr
BadCount@need:Nat -> @got:Nat -> NdErr
BadDType@op:String -> @dt:DType -> NdErr
MixedDTypes@a:DType -> @b:DType -> NdErr
EmptyReduce@axis:Nat -> NdErr
BadStep@step:Nat -> NdErr
BadIndex@index:List<&2, Nat> -> @shape:List<&2, Nat> -> NdErr
BadRange@low:U32 -> @high:U32 -> @dt:DType -> NdErr
BadNpy@why:String -> NdErr
NpyDType@descr:String -> NdErr
NpyValue@descr:String -> @index:Nat -> NdErr
FileErr@why:String -> NdErr
NoArraysNdErr
Definitions
def size source · line 34 · raw
@s:List<&2, Nat> -> Nat
def ndim source · line 41 · raw
@s:List<&2, Nat> -> Nat
def bpick source · line 48 · raw
@x1:Bool -> @y1:Bool -> @e:Bool -> @+x:Nat -> @+y:Nat -> Maybe<&2, Nat>
one aligned pair, given its three tests: x is 1, y is 1, x equals y
def bdim source · line 59 · raw
@+x:Nat -> @+y:Nat -> Maybe<&2, Nat>
def mcons source · line 62 · raw
@m:Maybe<&2, Nat> -> @r:Maybe<&2, List<&2, Nat>> -> Maybe<&2, List<&2, Nat>>
def bcast_rev source · line 70 · raw
@ra:List<&2, Nat> -> @rb:List<&2, Nat> -> Maybe<&2, List<&2, Nat>>
broadcasting on shapes written last dimension first
def bcast_done source · line 81 · raw
@m:Maybe<&2, List<&2, Nat>> -> @a:List<&2, Nat> -> @b:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>
def broadcast source · line 89 · raw
@+a:List<&2, Nat> -> @+b:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>
the shape a and b broadcast to, or NoBroadcast{a, b}
def fits_rev source · line 93 · raw
@ra:List<&2, Nat> -> @rs:List<&2, Nat> -> Bool
a fits s: a broadcasts to s unchanged (each of a's dimensions, aligned at the end, is 1 or s's; a is no longer)
def fits source · line 102 · raw
@a:List<&2, Nat> -> @s:List<&2, Nat> -> Bool
def reshape_pick source · line 107 · raw
@ok:Bool -> @+a:List<&2, Nat> -> @+b:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>
def reshape source · line 114 · raw
@+a:List<&2, Nat> -> @+b:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>
def axis_pick source · line 119 · raw
@ok:Bool -> @+axis:Nat -> @+n:Nat -> Result<&2, &2, NdErr, Nat>
def axis_of source · line 127 · raw
@+axis:Nat -> @+n:Nat -> Result<&2, &2, NdErr, Nat>
axis of a shape with n dimensions: 0 .. n - 1
def nth source · line 130 · raw
@s:List<&2, Nat> -> @i:Nat -> Nat
def drop_at source · line 139 · raw
@s:List<&2, Nat> -> @i:Nat -> List<&2, Nat>
def set_at source · line 148 · raw
@s:List<&2, Nat> -> @i:Nat -> @+v:Nat -> List<&2, Nat>
def insert_at source · line 157 · raw
@s:List<&2, Nat> -> @i:Nat -> @+v:Nat -> List<&2, Nat>
def reduce_keep source · line 167 · raw
@k:Bool -> @+s:List<&2, Nat> -> @+axis:Nat -> List<&2, Nat>
the shape after reducing axis (kept as a 1 with keep)
def count_of source · line 176 · raw
@+x:Nat -> @p:List<&2, Nat> -> Nat
def once_each source · line 184 · raw
@k:Nat -> @+p:List<&2, Nat> -> Bool
each of 0 .. k - 1 occurs exactly once in p
def is_perm source · line 191 · raw
@+p:List<&2, Nat> -> @+n:Nat -> Bool
def permute source · line 194 · raw
@+s:List<&2, Nat> -> @p:List<&2, Nat> -> List<&2, Nat>
def perm_pick source · line 201 · raw
@ok:Bool -> @+s:List<&2, Nat> -> @+p:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>
def transpose source · line 209 · raw
@+s:List<&2, Nat> -> @+p:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>
the shape after transposing s by perm p: result axis k is s's axis p[k]
def clamp source · line 214 · raw
@+x:Nat -> @+n:Nat -> Nat
def slice_len source · line 218 · raw
@+n:Nat -> @+start:Nat -> @+stop:Nat -> @+step:Nat -> Nat
how many of start, start + step, ... are below stop (step >= 1)
def eq_dims source · line 223 · raw
@s:List<&2, Nat> -> @t:List<&2, Nat> -> Bool
def same_but source · line 233 · raw
@s:List<&2, Nat> -> @t:List<&2, Nat> -> @i:Nat -> Bool
s and t have the same number of dimensions and agree on every one but axis i
def concat_pick source · line 244 · raw
@ok:Bool -> @+axis:Nat -> @+a:List<&2, Nat> -> @+b:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>
def concat source · line 252 · raw
@+axis:Nat -> @+a:List<&2, Nat> -> @+b:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>
the shape of a and b joined along axis (which must be one of their axes)