tensor_view.bend checks
raw source on the hub · import stelliferous@0.0.2.0/tensor_view.bend as Tensor_view
Rank-independent forward-strided metadata. The Array owner is passed separately. A vector, matrix and tensor use the same descriptor and lookup operation.
4 imports
import Base import ./storage_buffer.bend as Storage import ./tensor_shape.bend as Shapes import ./machine_limits.bend as Machine
Types
type Axis source · line 8 · raw
Data
Axis@extent:U32 -> @stride:U32 -> Axis
type View source · line 11 · raw
Data
View@axes:List<&2, Axis> -> @offset:U32 -> View
Definitions
def address_when source · line 16 · raw
@valid:Bool -> @offset:U32 -> @increment:U32 -> Maybe<&2, U32>
Successful addresses are below logical_length. The checked product and the remaining-room comparison prevent multiplication and addition from wrapping.
def finish_address source · line 21 · raw
@valid:Bool -> @offset:U32 -> Maybe<&2, U32>
def advance_product source · line 26 · raw
@product:Maybe<&2, U32> -> @offset:U32 -> @room:U32 -> Maybe<&2, U32>
def advance_inside source · line 31 · raw
@inside:Bool -> @+offset:U32 -> @coordinate:U32 -> @+stride:U32 -> @logical_length:U32 -> Maybe<&2, U32>
def advance source · line 36 · raw
@+offset:U32 -> @coordinate:U32 -> @stride:U32 -> @+logical_length:U32 -> Maybe<&2, U32>
def locate source · line 40 · raw
@axes:List<&2, Axis> -> @coordinates:List<&2, U32> -> @address:Maybe<&2, U32> -> @+logical_length:U32 -> Maybe<&2, U32>
The recursive step consumes one axis and one coordinate; no flattening/copy.
def address source · line 48 · raw
@view:View -> @coordinates:List<&2, U32> -> @logical_length:U32 -> Maybe<&2, U32>
def axis_extents source · line 52 · raw
@axes:List<&2, Axis> -> List<&2, U32>
def shape source · line 57 · raw
@view:View -> 0x9be3b13bf249759bc81e1958bcd1a4c0/tensor_shape.Shape
def numel source · line 61 · raw
@view:View -> Maybe<&2, U32>
def rank source · line 64 · raw
@view:View -> Nat
def extent source · line 67 · raw
@view:View -> @axis:Nat -> Maybe<&2, U32>
def build_axes source · line 70 · raw
@reversed:List<&2, U32> -> @stride:Maybe<&2, U32> -> @axes:List<&2, Axis> -> @offset:U32 -> Maybe<&2, View>
def contiguous_count source · line 77 · raw
@count:Maybe<&2, U32> -> @extents:List<&2, U32> -> @offset:U32 -> Maybe<&2, View>
def contiguous source · line 83 · raw
@+dimensions:0x9be3b13bf249759bc81e1958bcd1a4c0/tensor_shape.Shape -> @offset:U32 -> Maybe<&2, View>
def contiguous_product source · line 87 · raw
@valid:Bool -> @extent:U32 -> @inner_count:U32 -> Maybe<&2, U32>
def contiguous_axis source · line 92 · raw
@+extent:U32 -> @stride:U32 -> @inner:Maybe<&2, U32> -> Maybe<&2, U32>
def contiguous_size source · line 99 · raw
@axes:List<&2, Axis> -> Maybe<&2, U32>
Validate strides from the innermost axis outward. This avoids allocating a second canonical View just to compare its metadata. Empty views bypass it.
def has_count source · line 104 · raw
@count:Maybe<&2, U32> -> Bool
def contiguous_nonempty source · line 109 · raw
@empty:Bool -> @+axes:List<&2, Axis> -> Bool
def is_contiguous source · line 114 · raw
@view:View -> Bool
def last_coordinates source · line 118 · raw
@axes:List<&2, Axis> -> List<&2, U32>
def found source · line 123 · raw
@address:Maybe<&2, U32> -> Bool
def fits_nonempty source · line 128 · raw
@empty:Bool -> @+view:View -> @+logical_length:U32 -> Bool
def axis_extents_of source · line 139 · raw
@view:View -> List<&2, U32>
Forward strides are nonnegative: the last coordinate is the maximum address. Empty views may point exactly one past the logical end, and perform no reads.
def fits source · line 143 · raw
@view:View -> @logical_length:U32 -> Bool
def contains_index source · line 147 · raw
@indices:List<&2, Nat> -> @+axis:Nat -> Bool
def unique_axes source · line 152 · raw
@order:List<&2, Nat> -> Bool
def prepend_axis source · line 157 · raw
@axis:Maybe<&2, Axis> -> @view:Maybe<&2, View> -> Maybe<&2, View>
def reorder source · line 162 · raw
@order:List<&2, Nat> -> @+axes:List<&2, Axis> -> @offset:U32 -> Maybe<&2, View>
def permute_when source · line 168 · raw
@valid:Bool -> @view:View -> @order:List<&2, Nat> -> Maybe<&2, View>
def permute source · line 176 · raw
@+view:View -> @+order:List<&2, Nat> -> Maybe<&2, View>
Order must contain each axis exactly once, including singleton axes.
def slice_step source · line 179 · raw
@zero:Bool -> @+start:U32 -> @+count:U32 -> @+step:U32 -> @+size:U32 -> Bool
def sliced_axis source · line 186 · raw
@valid:Bool -> @count:U32 -> @stride:Maybe<&2, U32> -> @offset:Maybe<&2, U32> -> @tail:List<&2, Axis> -> Maybe<&2, View>
def add_offset source · line 191 · raw
@shift:Maybe<&2, U32> -> @+offset:U32 -> Maybe<&2, U32>
def slice_axes source · line 196 · raw
@axes:List<&2, Axis> -> @axis:Nat -> @+start:U32 -> @+count:U32 -> @+step:U32 -> @+offset:U32 -> Maybe<&2, View>
def slice source · line 207 · raw
@view:View -> @axis:Nat -> @start:U32 -> @count:U32 -> @step:U32 -> Maybe<&2, View>
Explicit start/count/positive step. The resulting view is validated against the actual Buffer at execution time; arithmetic overflow is rejected here.
def stretched_axis source · line 213 · raw
@same:Bool -> @single:Bool -> @size:U32 -> @stride:U32 -> @extent:U32 -> Maybe<&2, Axis>
One axis read as extent elements: unchanged when the extents agree, the single element repeated (stride 0) when the axis has extent 1.
def stretched_prepend source · line 219 · raw
@axis:Maybe<&2, Axis> -> @rest:Maybe<&2, List<&2, Axis>> -> Maybe<&2, List<&2, Axis>>
def stretch_axes source · line 224 · raw
@axes:List<&2, Axis> -> @target:List<&2, U32> -> Maybe<&2, List<&2, Axis>>
def with_rank source · line 232 · raw
@+axes:List<&2, Axis> -> @rank:Nat -> List<&2, Axis>
The axes with leading axes of extent 1 added up to rank; the same elements.
def stretched_view source · line 235 · raw
@axes:Maybe<&2, List<&2, Axis>> -> @offset:U32 -> Maybe<&2, View>
def stretch source · line 243 · raw
@view:View -> @+target:List<&2, U32> -> Maybe<&2, View>
The view read with the extents target under NumPy broadcasting. No element moves: an axis of extent 1 is repeated with stride 0, and so is an axis the view lacks.