tensor_view.bend checks
raw source on the hub · import stelliferous@0.0.3.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.
3 imports
import Base import ./tensor_shape.bend as Shapes import ./machine_limits.bend as Machine
Types
type Axis source · line 7 · raw
Data
Axis@extent:U32 -> @stride:U32 -> Axis
type View source · line 10 · raw
Data
View@axes:List<&2, Axis> -> @offset:U32 -> View
Definitions
def address_when source · line 15 · 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 20 · raw
@valid:Bool -> @offset:U32 -> Maybe<&2, U32>
def advance_product source · line 25 · raw
@product:Maybe<&2, U32> -> @offset:U32 -> @room:U32 -> Maybe<&2, U32>
def advance_inside source · line 30 · raw
@inside:Bool -> @+offset:U32 -> @coordinate:U32 -> @+stride:U32 -> @logical_length:U32 -> Maybe<&2, U32>
def advance source · line 35 · raw
@+offset:U32 -> @coordinate:U32 -> @stride:U32 -> @+logical_length:U32 -> Maybe<&2, U32>
def locate source · line 39 · 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 47 · raw
@view:View -> @coordinates:List<&2, U32> -> @logical_length:U32 -> Maybe<&2, U32>
def axis_extents source · line 51 · raw
@axes:List<&2, Axis> -> List<&2, U32>
def shape source · line 56 · raw
@view:View -> 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_shape.Shape
def numel source · line 60 · raw
@view:View -> Maybe<&2, U32>
def rank source · line 63 · raw
@view:View -> Nat
def extent source · line 66 · raw
@view:View -> @axis:Nat -> Maybe<&2, U32>
def build_axes source · line 69 · raw
@reversed:List<&2, U32> -> @stride:Maybe<&2, U32> -> @axes:List<&2, Axis> -> @offset:U32 -> Maybe<&2, View>
def contiguous_count source · line 76 · raw
@count:Maybe<&2, U32> -> @extents:List<&2, U32> -> @offset:U32 -> Maybe<&2, View>
def contiguous source · line 82 · raw
@+dimensions:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_shape.Shape -> @offset:U32 -> Maybe<&2, View>
def contiguous_product source · line 86 · raw
@valid:Bool -> @extent:U32 -> @inner_count:U32 -> Maybe<&2, U32>
def contiguous_axis source · line 91 · raw
@+extent:U32 -> @stride:U32 -> @inner:Maybe<&2, U32> -> Maybe<&2, U32>
def contiguous_size source · line 98 · 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 103 · raw
@count:Maybe<&2, U32> -> Bool
def contiguous_nonempty source · line 108 · raw
@empty:Bool -> @+axes:List<&2, Axis> -> Bool
def is_contiguous source · line 113 · raw
@view:View -> Bool
def last_coordinates source · line 117 · raw
@axes:List<&2, Axis> -> List<&2, U32>
def found source · line 122 · raw
@address:Maybe<&2, U32> -> Bool
def fits_nonempty source · line 127 · raw
@empty:Bool -> @+view:View -> @+logical_length:U32 -> Bool
def axis_extents_of source · line 138 · 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 142 · raw
@view:View -> @logical_length:U32 -> Bool
def flag source · line 150 · raw
@flags:List<&2, Bool> -> Bool
The view read with the flagged axes in reverse: such an axis starts at its last element and steps by the negated stride, in wrapping U32 arithmetic. Every address a traversal of it reaches is an address of the view. Its strides are not forward strides, so no check of this file accepts it.
def later_flags source · line 155 · raw
@flags:List<&2, Bool> -> List<&2, Bool>
def drop_flags source · line 162 · raw
@count:Nat -> @flags:List<&2, Bool> -> List<&2, Bool>
The flags after the first count, the first count flags, and whether none of those is set.
def fitted_flags source · line 167 · raw
@count:Nat -> @+flags:List<&2, Bool> -> List<&2, Bool>
def forward source · line 172 · raw
@count:Nat -> @+flags:List<&2, Bool> -> Bool
def directed source · line 177 · raw
@reverse:Bool -> @stride:U32 -> U32
def mirrored_start source · line 182 · raw
@reverse:Bool -> @+extent:U32 -> @stride:U32 -> @+offset:U32 -> U32
def mirrored_axes source · line 187 · raw
@axes:List<&2, Axis> -> @+flags:List<&2, Bool> -> List<&2, Axis>
def mirrored_offset source · line 192 · raw
@axes:List<&2, Axis> -> @+flags:List<&2, Bool> -> @offset:U32 -> U32
def mirrored source · line 197 · raw
@view:View -> @+flags:List<&2, Bool> -> View
def contains_index source · line 201 · raw
@indices:List<&2, Nat> -> @+axis:Nat -> Bool
def unique_axes source · line 206 · raw
@order:List<&2, Nat> -> Bool
def prepend_axis source · line 211 · raw
@axis:Maybe<&2, Axis> -> @view:Maybe<&2, View> -> Maybe<&2, View>
def reorder source · line 216 · raw
@order:List<&2, Nat> -> @+axes:List<&2, Axis> -> @offset:U32 -> Maybe<&2, View>
def permute_when source · line 222 · raw
@valid:Bool -> @view:View -> @order:List<&2, Nat> -> Maybe<&2, View>
def permute source · line 230 · 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 233 · raw
@zero:Bool -> @+start:U32 -> @+count:U32 -> @+step:U32 -> @+size:U32 -> Bool
def sliced_axis source · line 240 · 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 245 · raw
@shift:Maybe<&2, U32> -> @+offset:U32 -> Maybe<&2, U32>
def slice_axes source · line 250 · raw
@axes:List<&2, Axis> -> @axis:Nat -> @+start:U32 -> @+count:U32 -> @+step:U32 -> @+offset:U32 -> Maybe<&2, View>
def slice source · line 261 · 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 267 · 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 273 · raw
@axis:Maybe<&2, Axis> -> @rest:Maybe<&2, List<&2, Axis>> -> Maybe<&2, List<&2, Axis>>
def stretch_axes source · line 278 · raw
@axes:List<&2, Axis> -> @target:List<&2, U32> -> Maybe<&2, List<&2, Axis>>
def with_rank source · line 286 · 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 289 · raw
@axes:Maybe<&2, List<&2, Axis>> -> @offset:U32 -> Maybe<&2, View>
def stretch source · line 297 · 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.