~/bend-docscommunity

tensor_view.bend checks

raw source on the hub · import stelliferous@0.0.4.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

type View source · line 10 · raw

Data

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 removed_axis source · line 57 · raw

@axes:List<&2, Axis> -> @axis:Nat -> List<&2, Axis>

The axes without the one at axis.

def stride_at source · line 64 · raw

@axes:List<&2, Axis> -> @axis:Nat -> U32

The stride of the axis at axis, and 0 past the axes.

def shape source · line 70 · raw

@view:View -> 0xa2af805348d03b11eb853850859654f6/tensor_shape.Shape

def numel source · line 74 · raw

@view:View -> Maybe<&2, U32>

def rank source · line 77 · raw

@view:View -> Nat

def build_axes source · line 80 · raw

@reversed:List<&2, U32> -> @stride:Maybe<&2, U32> -> @axes:List<&2, Axis> -> @offset:U32 -> Maybe<&2, View>

def contiguous_count source · line 87 · raw

@count:Maybe<&2, U32> -> @extents:List<&2, U32> -> @offset:U32 -> Maybe<&2, View>

def contiguous source · line 93 · raw

@+dimensions:0xa2af805348d03b11eb853850859654f6/tensor_shape.Shape -> @offset:U32 -> Maybe<&2, View>

def contiguous_product source · line 97 · raw

@valid:Bool -> @extent:U32 -> @inner_count:U32 -> Maybe<&2, U32>

def contiguous_axis source · line 102 · raw

@+extent:U32 -> @stride:U32 -> @inner:Maybe<&2, U32> -> Maybe<&2, U32>

def contiguous_size source · line 109 · 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 114 · raw

@count:Maybe<&2, U32> -> Bool

def contiguous_nonempty source · line 119 · raw

@empty:Bool -> @+axes:List<&2, Axis> -> Bool

def is_contiguous source · line 124 · raw

@view:View -> Bool

def last_coordinates source · line 128 · raw

@axes:List<&2, Axis> -> List<&2, U32>

def fits_nonempty source · line 133 · raw

@empty:Bool -> @+view:View -> @+logical_length:U32 -> Bool

def axis_extents_of source · line 144 · 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 148 · raw

@view:View -> @logical_length:U32 -> Bool

def flag source · line 156 · 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 161 · raw

@flags:List<&2, Bool> -> List<&2, Bool>

def drop_flags source · line 168 · 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 directed source · line 173 · raw

@reverse:Bool -> @stride:U32 -> U32

def mirrored_start source · line 178 · raw

@reverse:Bool -> @+extent:U32 -> @stride:U32 -> @+offset:U32 -> U32

def mirrored_axes source · line 183 · raw

@axes:List<&2, Axis> -> @+flags:List<&2, Bool> -> List<&2, Axis>

def mirrored_offset source · line 188 · raw

@axes:List<&2, Axis> -> @+flags:List<&2, Bool> -> @offset:U32 -> U32

def mirrored source · line 193 · raw

@view:View -> @+flags:List<&2, Bool> -> View

def contains_index source · line 197 · raw

@indices:List<&2, Nat> -> @+axis:Nat -> Bool

def unique_axes source · line 202 · raw

@order:List<&2, Nat> -> Bool

def prepend_axis source · line 207 · raw

@axis:Maybe<&2, Axis> -> @view:Maybe<&2, View> -> Maybe<&2, View>

def reorder source · line 212 · raw

@order:List<&2, Nat> -> @+axes:List<&2, Axis> -> @offset:U32 -> Maybe<&2, View>

def permute_when source · line 218 · raw

@valid:Bool -> @view:View -> @order:List<&2, Nat> -> Maybe<&2, View>

def permute source · line 226 · 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 231 · raw

@zero:Bool -> @+start:U32 -> @+count:U32 -> @+step:U32 -> @+size:U32 -> Bool

def sliced_axis source · line 238 · 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 243 · raw

@shift:Maybe<&2, U32> -> @+offset:U32 -> Maybe<&2, U32>

def slice_axes source · line 248 · raw

@axes:List<&2, Axis> -> @axis:Nat -> @+start:U32 -> @+count:U32 -> @+step:U32 -> @+offset:U32 -> Maybe<&2, View>

def slice source · line 259 · 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 265 · 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 271 · raw

@axis:Maybe<&2, Axis> -> @rest:Maybe<&2, List<&2, Axis>> -> Maybe<&2, List<&2, Axis>>

def stretch_axes source · line 276 · raw

@axes:List<&2, Axis> -> @target:List<&2, U32> -> Maybe<&2, List<&2, Axis>>

def with_rank source · line 284 · 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 287 · raw

@axes:Maybe<&2, List<&2, Axis>> -> @offset:U32 -> Maybe<&2, View>

def stretch source · line 295 · 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.