shape.bend checks
raw source on the hub · import bend-ndarray@0.1.3.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
DI32DType
DU32DType
DU8DType
DBoolDType
type NdErr source · line 14 · 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 33 · raw
@s:List<&2, Nat> -> Nat
def ndim source · line 40 · raw
@s:List<&2, Nat> -> Nat
def bpick source · line 47 · 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 58 · raw
@+x:Nat -> @+y:Nat -> Maybe<&2, Nat>
def mcons source · line 61 · raw
@m:Maybe<&2, Nat> -> @r:Maybe<&2, List<&2, Nat>> -> Maybe<&2, List<&2, Nat>>
def bcast_rev source · line 69 · 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 80 · 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 88 · 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 92 · 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 101 · raw
@a:List<&2, Nat> -> @s:List<&2, Nat> -> Bool
def reshape_pick source · line 106 · raw
@ok:Bool -> @+a:List<&2, Nat> -> @+b:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>
def reshape source · line 113 · raw
@+a:List<&2, Nat> -> @+b:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>
def axis_pick source · line 118 · raw
@ok:Bool -> @+axis:Nat -> @+n:Nat -> Result<&2, &2, NdErr, Nat>
def axis_of source · line 126 · raw
@+axis:Nat -> @+n:Nat -> Result<&2, &2, NdErr, Nat>
axis of a shape with n dimensions: 0 .. n - 1
def nth source · line 129 · raw
@s:List<&2, Nat> -> @i:Nat -> Nat
def drop_at source · line 138 · raw
@s:List<&2, Nat> -> @i:Nat -> List<&2, Nat>
def set_at source · line 147 · raw
@s:List<&2, Nat> -> @i:Nat -> @+v:Nat -> List<&2, Nat>
def insert_at source · line 156 · raw
@s:List<&2, Nat> -> @i:Nat -> @+v:Nat -> List<&2, Nat>
def reduce_keep source · line 166 · 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 175 · raw
@+x:Nat -> @p:List<&2, Nat> -> Nat
def once_each source · line 183 · raw
@k:Nat -> @+p:List<&2, Nat> -> Bool
each of 0 .. k - 1 occurs exactly once in p
def is_perm source · line 190 · raw
@+p:List<&2, Nat> -> @+n:Nat -> Bool
def permute source · line 193 · raw
@+s:List<&2, Nat> -> @p:List<&2, Nat> -> List<&2, Nat>
def perm_pick source · line 200 · raw
@ok:Bool -> @+s:List<&2, Nat> -> @+p:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>
def transpose source · line 208 · 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 213 · raw
@+x:Nat -> @+n:Nat -> Nat
def slice_len source · line 217 · 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 222 · raw
@s:List<&2, Nat> -> @t:List<&2, Nat> -> Bool
def same_but source · line 232 · 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 243 · raw
@ok:Bool -> @+axis:Nat -> @+a:List<&2, Nat> -> @+b:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>
def concat source · line 251 · 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)