tensor_band_reduce.bend checks
raw source on the hub · import stelliferous@0.0.3.0/tensor_band_reduce.bend as Tensor_band_reduce
A reduction runs on the lines of a view of its input: the view puts the reduced axes last, and line k holds their values at index k of the kept axes. The view is classified over the input's bands as a gather is: when the bands keep their images and rows and the reduced axes lie after the rows, every band folds the lines of its own rows through its local view; otherwise the input arrives as one band, which folds every line.
9 imports
import Base import ./storage_buffer.bend as Storage import ./tensor_view.bend as Views import ./tensor_operations.bend as Operations import ./tensor_band.bend as Bands import ./tensor_band_view.bend as BandViews import ./traversal_partition.bend as Partition import ./tensor.bend as Tensors import ./tensor_band_schedule.bend as BandSchedule
Types
type Context source · line 20 · raw
@-Accumulator:Data -> @-Element:Data -> Data
What every band of a reduction shares: the banded view of the input geometry, the number of reduced axes, the initial accumulator and the fill of fresh storage.
Context@-Accumulator:Data -> @-Element:Data -> @banded:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band_view.Banded -> @reduced:Nat -> @geometry:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Geometry -> @initial:Accumulator -> @fill:Element -> Context<Accumulator, Element>
Definitions
def kept_axes source · line 31 · raw
@+axes:List<&2, 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_view.Axis> -> @+reduced:Nat -> List<&2, 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_view.Axis>
The axes of a view before its last reduced axes.
def output source · line 65 · raw
@+banded:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band_view.Banded -> @+geometry:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Geometry -> @+reduced:Nat -> 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Geometry
The geometry of the outputs: the same images, the axes before the rows as channels, each row repeated, the kept axes after the rows as columns.
def in_band source · line 72 · raw
@found:Maybe<&2, 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band_view.Banded> -> @+reduced:Nat -> Maybe<&2, 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band_view.Banded>
The banded view when the reduced axes lie among the axes after the rows.
Templates
template checked source · line 25 · raw
@-Element:Data -> @+first:U32 -> @+rows:U32 -> @result:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_operations.Outcome<Pair(0xd6aaab858a4fbd1461bd0fee27b97184/storage_buffer.Buffer<Element>, 0xd6aaab858a4fbd1461bd0fee27b97184/storage_buffer.Buffer<Element>)> -> 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Transformed(Element)
A band's folds as a checked band: its outputs beside whether the call accepted.
template folded_view source · line 34 · raw
@-Element:Data -> @-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:Element -> Accumulator) -> @-finish:(@_:Accumulator -> Element) -> @+reduced:Nat -> @+initial:Accumulator -> @+fill:Element -> @+first:U32 -> @+rows:U32 -> @local:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_view.View -> @input:0xd6aaab858a4fbd1461bd0fee27b97184/storage_buffer.Buffer<Element> -> 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Transformed(Element)
template folded_rows source · line 44 · raw
@-Element:Data -> @-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:Element -> Accumulator) -> @-finish:(@_:Accumulator -> Element) -> @empty:Bool -> @+banded:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band_view.Banded -> @+reduced:Nat -> @+geometry:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Geometry -> @+initial:Accumulator -> @+fill:Element -> @+first:U32 -> @+rows:U32 -> @input:0xd6aaab858a4fbd1461bd0fee27b97184/storage_buffer.Buffer<Element> -> 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Transformed(Element)
The band of rows [first, first + rows) folds the lines of its rows; its output band holds their folds. A band of no rows has no line.
template leaf source · line 56 · raw
@-Element:Data -> @-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:Element -> Accumulator) -> @-finish:(@_:Accumulator -> Element) -> @context:Context<Accumulator, Element> -> @first:U32 -> @rows:U32 -> @input:0xd6aaab858a4fbd1461bd0fee27b97184/storage_buffer.Buffer<Element> -> 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Transformed(Element)
template banded_lines source · line 80 · raw
@-Element:Data -> @-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:Element -> Accumulator) -> @-finish:(@_:Accumulator -> Element) -> @+name:String -> @+operations:F32 -> @+initial:Accumulator -> @+reduced:Nat -> @+banded:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band_view.Banded -> @+geometry:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Geometry -> @+shape:List<&2, U32> -> @+fill:Element -> @+workers:U32 -> @bands:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Bands(Element) -> 0xd6aaab858a4fbd1461bd0fee27b97184/tensor.Tensor<Element>
Every band folds its own lines. operations prices the combination of one value, beside the read of it.
template whole_lines source · line 87 · raw
@-Element:Data -> @-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:Element -> Accumulator) -> @-finish:(@_:Accumulator -> Element) -> @+name:String -> @+operations:F32 -> @+initial:Accumulator -> @+reduced:Nat -> @found:Maybe<&2, 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band_view.Banded> -> @+whole:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Geometry -> @+shape:List<&2, U32> -> @+fill:Element -> @+workers:U32 -> @tensor:0xd6aaab858a4fbd1461bd0fee27b97184/tensor.Tensor<Element> -> 0xd6aaab858a4fbd1461bd0fee27b97184/tensor.Tensor<Element>
template found_lines source · line 96 · raw
@-Element:Data -> @-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:Element -> Accumulator) -> @-finish:(@_:Accumulator -> Element) -> @+name:String -> @+operations:F32 -> @+initial:Accumulator -> @+reduced:Nat -> @found:Maybe<&2, 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band_view.Banded> -> @+axes:List<&2, 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_view.Axis> -> @+offset:U32 -> @bands:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Bands(Element) -> @+geometry:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Geometry -> @+source_shape:List<&2, U32> -> @+source_fill:Element -> @+source_workers:U32 -> @+shape:List<&2, U32> -> @+fill:Element -> @+workers:U32 -> 0xd6aaab858a4fbd1461bd0fee27b97184/tensor.Tensor<Element>
template lines_when source · line 108 · raw
@-Element:Data -> @-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:Element -> Accumulator) -> @-finish:(@_:Accumulator -> Element) -> @+name:String -> @empty:Bool -> @+operations:F32 -> @+count:U32 -> @+initial:Accumulator -> @+reduced:Nat -> @+axes:List<&2, 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_view.Axis> -> @+offset:U32 -> @bands:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Bands(Element) -> @+geometry:0xd6aaab858a4fbd1461bd0fee27b97184/tensor_band.Geometry -> @+source_shape:List<&2, U32> -> @+source_fill:Element -> @+source_workers:U32 -> @+shape:List<&2, U32> -> @+fill:Element -> @+workers:U32 -> 0xd6aaab858a4fbd1461bd0fee27b97184/tensor.Tensor<Element>
No output, or lines of no value, leave every output at finish(initial).
template lines source · line 122 · raw
@-Element:Data -> @-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:Element -> Accumulator) -> @-finish:(@_:Accumulator -> Element) -> @+name:String -> @+operations:F32 -> @+count:U32 -> @+length:U32 -> @+initial:Accumulator -> @+shape:List<&2, U32> -> @+fill:Element -> @+workers:U32 -> @tensor:0xd6aaab858a4fbd1461bd0fee27b97184/tensor.Tensor<Element> -> @view:Maybe<&2, 0xd6aaab858a4fbd1461bd0fee27b97184/tensor_view.View> -> @+reduced:Nat -> 0xd6aaab858a4fbd1461bd0fee27b97184/tensor.Tensor<Element>
count outputs of shape: output k folds the length values of line k of the view, the values of its last reduced axes at index k of the axes before them, in row-major order from initial, and holds finish of the fold. A failed tensor keeps its problem.