tensor_tiled_layout.bend checks
raw source on the hub · import stelliferous@0.0.4.0/tensor_tiled_layout.bend as Tensor_tiled_layout
Layout operations of tiled tensors. Gathers compute the view of the call from the extents, as Layout does for its tensors, and read it through TiledView. Writes, padding and reshapes work on the cells with the lanes on an axis the call leaves whole, so the cells move as they are.
10 imports
import Base import ./tensor.bend as Tensors import ./tensor_shape.bend as Shapes import ./tensor_view.bend as Views import ./tensor_layout.bend as Layout import ./tensor_tiled.bend as Tiled import ./tensor_grid.bend as Grid import ./tensor_tiled_view.bend as TiledView import ./tensor_tiled_map.bend as TiledMap import ./kernel_tile.bend as Tile
Types
type Kept source · line 151 · raw
Data
The axes around the lane axis of the source: the elements before it, the lanes and the elements after it.
Kept@outer:U32 -> @lanes:U32 -> @inner:U32 -> @innermost:Bool -> Kept
type Splitting source · line 284 · raw
Data
An axis of the new extents and the next split the lane axis when their extents, both above 1, multiply to the lanes, the axes before them hold as many elements as those before the lane axis and the axes after them as many as those after it.
Splitting@axis:Nat -> @outer:U32 -> @anchors:U32 -> @width:U32 -> @after:U32 -> Splitting
Definitions
def gather_extents source · line 17 · raw
@+name:String -> @status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @source:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.View> -> @+reversed:List<&2, Bool> -> @+shape:List<&2, U32> -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
The gather labelled with the extents of the view.
def transpose source · line 23 · raw
@tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @order:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
The result's axis i is the input axis order[i].
def slice source · line 29 · raw
@tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @axis:U32 -> @start:U32 -> @count:U32 -> @step:U32 -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
count elements from start along axis, every step-th one.
def flip source · line 35 · raw
@tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+axes:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
The elements in reverse order along every listed axis; an axis is listed once.
def broadcast_view source · line 42 · raw
@status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @view:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.View> -> @+shape:List<&2, U32> -> @+target:List<&2, U32> -> @+workers:U32 -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def broadcast_to source · line 49 · raw
@tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+target:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
The tensor repeated to the extents target under NumPy broadcasting: one gather through the stretched view.
def written_cells source · line 58 · raw
@+axis:Nat -> @+start:U32 -> @target:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @part:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
The part, its lanes on the lane axis of the target and its groups at the same position, written into the cells of the target along another axis.
def written_on source · line 63 · raw
@lanes:Bool -> @+axis:Nat -> @+start:U32 -> @target:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @part:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def written_from source · line 68 · raw
@started:Pair(0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled, Nat) -> @+axis:Nat -> @+start:U32 -> @part:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def written source · line 72 · raw
@valid:Bool -> @+shape:List<&2, U32> -> @+part_shape:List<&2, U32> -> @+axis:U32 -> @+start:U32 -> @target:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @part:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def write_status source · line 77 · raw
@target_status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @part_status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @+shape:List<&2, U32> -> @+part_shape:List<&2, U32> -> @+axis:U32 -> @+start:U32 -> @target:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @part:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def set_slice source · line 87 · raw
@target:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+axis:U32 -> @+start:U32 -> @part:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
target[..., start : start + part extent, ...] = part along axis, written into the cells of the target: whole cells along another axis, the lanes the part reaches along the lane axis.
def unpadded_from source · line 96 · raw
@before:List<&2, U32> -> @after:List<&2, U32> -> @+index:Nat -> @+rank:Nat -> Nat
The first axis padding leaves whole, or the unit axis.
def pad_lane source · line 102 · raw
@+lane:Nat -> @+before:List<&2, U32> -> @+after:List<&2, U32> -> @+rank:Nat -> Nat
The lanes stay on their axis when padding leaves it whole.
def cell_border source · line 107 · raw
@border:0xa2af805348d03b11eb853850859654f6/tensor_layout.Border<F32> -> @+unit:Bool -> 0xa2af805348d03b11eb853850859654f6/tensor_layout.Border<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>
The border of the cells: the value in every lane, or in the first lane of a cell of the unit axis.
def grown source · line 113 · raw
@cells:List<&2, U32> -> @before:List<&2, U32> -> @after:List<&2, U32> -> List<&2, U32>
The extents of padded cells.
def padded_cells source · line 120 · raw
@+border:0xa2af805348d03b11eb853850859654f6/tensor_layout.Border<F32> -> @+before:List<&2, U32> -> @+after:List<&2, U32> -> @+rank:Nat -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
Every piece of the padded cells sets the lanes past the extent of the lane axis to +0 as it is filled: cells of the value hold it in every lane.
def padded_from source · line 127 · raw
@started:Pair(0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled, Nat) -> @+border:0xa2af805348d03b11eb853850859654f6/tensor_layout.Border<F32> -> @+before:List<&2, U32> -> @+after:List<&2, U32> -> @+rank:Nat -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def pad_valid source · line 131 · raw
@+border:0xa2af805348d03b11eb853850859654f6/tensor_layout.Border<F32> -> @status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @valid:Bool -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+shape:List<&2, U32> -> @+before:List<&2, U32> -> @+after:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def pad source · line 141 · raw
@+border:0xa2af805348d03b11eb853850859654f6/tensor_layout.Border<F32> -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+before:List<&2, U32> -> @+after:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
before[i] elements are added in front of axis i and after[i] behind it. Both lists have one entry per axis and the padded extents must be allocatable. The cells are padded once with the lanes on an axis the padding leaves whole.
def same_around source · line 157 · raw
@found:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Around> -> @+kept:Kept -> Bool
An axis of the new extents keeps the cells when the axes before it hold as many elements as those before the lane axis, it has the lanes as extent and the axes after it hold as many elements as those after the lane axis.
def mismatched source · line 185 · raw
@+source:List<&2, U32> -> @+shape:List<&2, U32> -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
A usable reshape fails when the extents count other elements.
def reshape_other source · line 190 · raw
@status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @empty:Bool -> @count:Maybe<&2, U32> -> @+source:List<&2, U32> -> @+shape:List<&2, U32> -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
An empty source and empty extents hold no value; a failed source keeps its problem.
def whole_groups source · line 200 · raw
@found:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Around> -> @+kept:Kept -> Bool
Whole groups of a last lane axis keep their cells in order under any number of groups when the groups are innermost: an axis of the new extents fits when it is last and it and the lanes fill their groups.
def regrouped_around source · line 207 · raw
@around:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Around> -> @+axis:Nat -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+shape:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Attempt<0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled>
def regrouped source · line 214 · raw
@found:Maybe<&2, Nat> -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+shape:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Attempt<0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled>
def relabelled source · line 219 · raw
@found:Maybe<&2, Nat> -> @+kept:Kept -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+shape:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Attempt<0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled>
def reshape_around source · line 229 · raw
@axes:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Around> -> @valid:Bool -> @+innermost:Bool -> @status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+source:List<&2, U32> -> @+shape:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Attempt<0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled>
A usable source of as many elements, none of them on an empty axis, keeps its cells when an axis of the new extents keeps the lanes and the axes around them, or holds whole groups of them.
def reshape_positioned source · line 237 · raw
@+source:List<&2, U32> -> @+status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @+axis:Nat -> @started:Pair(0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled, 0xa2af805348d03b11eb853850859654f6/tensor_grid.Position) -> @+shape:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Attempt<0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled>
def reshape_from source · line 243 · raw
@+source:List<&2, U32> -> @+status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @started:Pair(0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled, Nat) -> @+shape:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Attempt<0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled>
def reshape_at source · line 247 · raw
@+shape:List<&2, U32> -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Attempt<0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled>
def kept_around source · line 253 · raw
@axes:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Around> -> @+innermost:Bool -> @+shape:List<&2, U32> -> Bool
Whether an axis of the new extents keeps lanes and the axes around them.
def matched_axis source · line 261 · raw
@remaining:Nat -> @+index:Nat -> @+source:List<&2, U32> -> @+shape:List<&2, U32> -> @+own:Nat -> @+innermost:Bool -> @+best:Nat -> @+extent:U32 -> Nat
The longest axis of the source but own, the later among equal extents, of an extent above 1 whose lanes and the axes around them an axis of the new extents keeps, or the unit axis when there is none.
def reshape_again source · line 269 · raw
@attempt:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Attempt<0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled> -> @+source:List<&2, U32> -> @+shape:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def reshape_relaned source · line 274 · raw
@+source:List<&2, U32> -> @+shape:List<&2, U32> -> @+own:Nat -> @started:Pair(0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled, 0xa2af805348d03b11eb853850859654f6/tensor_grid.Position) -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def split_after source · line 287 · raw
@after:List<&2, U32> -> @+axis:Nat -> @+before:U32 -> @+anchors:U32 -> @+kept:Kept -> Maybe<&2, Splitting>
def split_of source · line 296 · raw
@found:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Around> -> @+axis:Nat -> @+kept:Kept -> Maybe<&2, Splitting>
def split_scan source · line 301 · raw
@remaining:Nat -> @found:Maybe<&2, Splitting> -> @+shape:List<&2, U32> -> @+kept:Kept -> @+axis:Nat -> Maybe<&2, Splitting>
def lane_split source · line 310 · raw
@around:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Around> -> @+shape:List<&2, U32> -> Maybe<&2, Splitting>
The first split of the lane axis among the new extents.
def split_or_relaned source · line 317 · raw
@found:Maybe<&2, Splitting> -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+source:List<&2, U32> -> @+shape:List<&2, U32> -> @+own:Nat -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def reshape_moved source · line 322 · raw
@attempt:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Attempt<0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled> -> @+source:List<&2, U32> -> @+shape:List<&2, U32> -> @+own:Nat -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def reshape_lane source · line 327 · raw
@+shape:List<&2, U32> -> @+source:List<&2, U32> -> @started:Pair(0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled, Nat) -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def reshape_started source · line 331 · raw
@+shape:List<&2, U32> -> @started:Pair(0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled, List<&2, U32>) -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def reshape source · line 342 · raw
@tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+shape:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
Same elements in the same row-major order under new extents: the cells themselves when the lanes keep their axes around them or fill their groups. Extents that split the lane axis in two take the lanes on the second, each cell read from the one or two cells that hold its lanes. Otherwise the lanes move to the longest axis of the source whose lanes and the axes around them an axis of the new extents keeps, or to the unit axis when none does, and the cells take the new extents.
def upsample_checked source · line 347 · raw
@valid:Bool -> @planes:Maybe<&2, U32> -> @+shape:List<&2, U32> -> @+scale:U32 -> @+workers:U32 -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def upsample_status source · line 353 · raw
@status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @+shape:List<&2, U32> -> @+scale:U32 -> @+workers:U32 -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
def upsample_nearest source · line 361 · raw
@tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+scale:U32 -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled
Nearest-neighbour upsampling of the last two axes: one gather through the view that repeats each row and each column scale times, under the extents of that view, then each axis joined with its repeats.
Templates
template scan source · line 166 · raw
@-fits:(@found:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Around> -> @+kept:Kept -> Bool) -> @remaining:Nat -> @found:Bool -> @+shape:List<&2, U32> -> @+kept:Kept -> @+axis:Nat -> Maybe<&2, Nat>
The first axis from axis on that fits, found telling whether axis does; the unit axis past the last is included.
template preferred_found source · line 175 · raw
@-fits:(@found:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Around> -> @+kept:Kept -> Bool) -> @found:Bool -> @+shape:List<&2, U32> -> @+kept:Kept -> @+preferred:Nat -> Maybe<&2, Nat>
The lane axis of the new rank is tried first.
template axis_fitting source · line 180 · raw
@-fits:(@found:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Around> -> @+kept:Kept -> Bool) -> @+shape:List<&2, U32> -> @+kept:Kept -> Maybe<&2, Nat>