~/bend-docscommunity

shape.bend checks

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

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

def ndim source · line 35 · raw

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

def bpick source · line 42 · 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 53 · raw

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

def mcons source · line 56 · raw

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

def bcast_rev source · line 64 · 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 75 · 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 83 · 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 87 · 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 96 · raw

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

def reshape_pick source · line 101 · raw

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

def reshape source · line 108 · raw

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

def axis_pick source · line 113 · raw

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

def axis_of source · line 121 · raw

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

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

def nth source · line 124 · raw

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

def drop_at source · line 133 · raw

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

def set_at source · line 142 · raw

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

def insert_at source · line 151 · raw

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

def reduce_keep source · line 161 · 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 170 · raw

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

def once_each source · line 178 · raw

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

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

def is_perm source · line 185 · raw

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

def permute source · line 188 · raw

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

def perm_pick source · line 195 · raw

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

def transpose source · line 203 · 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 208 · raw

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

def slice_len source · line 212 · 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 217 · raw

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

def same_but source · line 227 · 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 238 · raw

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

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