~/bend-docscommunity

shape.bend checks

raw source on the hub · import bend-ndarray@0.1.2.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

type NdErr source · line 14 · raw

Data

Definitions

def size source · line 29 · raw

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

def ndim source · line 36 · raw

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

def bpick source · line 43 · 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 54 · raw

@+x:Nat -> @+y:Nat -> Maybe<&2, Nat>

def mcons source · line 57 · raw

@m:Maybe<&2, Nat> -> @r:Maybe<&2, List<&2, Nat>> -> Maybe<&2, List<&2, Nat>>

def bcast_rev source · line 65 · 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 76 · 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 84 · 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 88 · 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 97 · raw

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

def reshape_pick source · line 102 · raw

@ok:Bool -> @+a:List<&2, Nat> -> @+b:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>

def reshape source · line 109 · raw

@+a:List<&2, Nat> -> @+b:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>

def axis_pick source · line 114 · raw

@ok:Bool -> @+axis:Nat -> @+n:Nat -> Result<&2, &2, NdErr, Nat>

def axis_of source · line 122 · raw

@+axis:Nat -> @+n:Nat -> Result<&2, &2, NdErr, Nat>

axis of a shape with n dimensions: 0 .. n - 1

def nth source · line 125 · raw

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

def drop_at source · line 134 · raw

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

def set_at source · line 143 · raw

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

def insert_at source · line 152 · raw

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

def reduce_keep source · line 162 · 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 171 · raw

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

def once_each source · line 179 · raw

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

each of 0 .. k - 1 occurs exactly once in p

def is_perm source · line 186 · raw

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

def permute source · line 189 · raw

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

def perm_pick source · line 196 · raw

@ok:Bool -> @+s:List<&2, Nat> -> @+p:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>

def transpose source · line 204 · 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 209 · raw

@+x:Nat -> @+n:Nat -> Nat

def slice_len source · line 213 · 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 218 · raw

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

def same_but source · line 228 · 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 239 · raw

@ok:Bool -> @+axis:Nat -> @+a:List<&2, Nat> -> @+b:List<&2, Nat> -> Result<&2, &2, NdErr, List<&2, Nat>>

def concat source · line 247 · 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)