shaped-bounds-check ( seq shaped -- seq shaped )


Vocabulary
arrays.shaped

Inputs
seqa sequence
shapeda shaped-array


Outputs
seqa sequence
shapeda shaped-array


Word description
Checks that coordinates contain exactly one integer per axis, with negative indices counted from the end. Returns normalized nonnegative coordinates. Invalid coordinates raise shaped-bounds-error. Element accessors require full coordinates; use shaped-slice-view for partial indexing and slicing.

Definition


:: shaped-bounds-check ( seq shaped -- seq shaped )
shaped shape :> dimensions seq length dimensions length = [
seq dimensions [| index size |
index integer?
[ index size neg >= index size < and ] [ f ] if
] 2all?
] [ f ] if [ seq shaped shaped-bounds-error ] unless
seq dimensions [ swap dup 0 < [ + ] [ nip ] if ] 2map shaped
;