~/bend-docscommunity

src/tensor/gather_LAWS.bend open laws/TODOs

raw source on the hub · import bendtorch-core@0.1.0.0/src/tensor/gather_LAWS.bend as Gather_LAWS

10 imports
import Base
import ../shape/core.bend as Shape
import ../storage/model.bend as Model
import ../storage/refinement.bend as Refinement
import ./core.bend as Core
import ./layout.bend as Layout
import ./elementwise_totality.bend as Totality
import ./slice.bend as Slice
import ./signed.bend as Signed
import ./gather.bend as Gather

Laws

law index_select_axis_refused provedin PROOF.bendsource · line 90 · raw

@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+entries:List<&2, U32> -> @outside:{Nat.is_lt(axis(input, dim), rank(input)) == False{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.select_plan(input, dim, entries) == Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.LayoutError{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/layout.AxisOutOfBounds{}}} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned>}

index_select(dim, index): an axis outside -rank..rank-1 is refused first, then an entry at or past the extent; any other request is planned.

law index_select_out_of_range provedin PROOF.bendsource · line 98 · raw

@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+entries:List<&2, U32> -> @in_rank:{Nat.is_lt(axis(input, dim), rank(input)) == True{} : Bool} -> @past:{inside(entries, extent(input, axis(input, dim))) == False{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.select_plan(input, dim, entries) == Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.OutOfRange{}} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned>}

law index_select_planned provedin PROOF.bendsource · line 106 · raw

@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+entries:List<&2, U32> -> @in_rank:{Nat.is_lt(axis(input, dim), rank(input)) == True{} : Bool} -> @within:{inside(entries, extent(input, axis(input, dim))) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.select_plan(input, dim, entries) == taken(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Selected{}, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(input), axis(input, dim), length(entries)) : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned>}

law gather_count_refused provedin PROOF.bendsource · line 119 · raw

@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+index:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+entries:List<&2, U32> -> @miscounted:{Nat.is_eq(length(entries), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.elements(index)) == False{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.gather_plan(input, dim, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Index{index, entries}) == Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.TensorError{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.ValueCountMismatch{}}} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned>}

gather(dim, index): an entry count other than the element count of the index's shape is refused first, then the axis, an index of another rank, one with another extent at another axis, and an entry at or past the extent; any other request is planned, with the index's extent at the axis.

law gather_axis_refused provedin PROOF.bendsource · line 128 · raw

@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+index:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+entries:List<&2, U32> -> @counted:{Nat.is_eq(length(entries), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.elements(index)) == True{} : Bool} -> @outside:{Nat.is_lt(axis(input, dim), rank(input)) == False{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.gather_plan(input, dim, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Index{index, entries}) == Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.LayoutError{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/layout.AxisOutOfBounds{}}} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned>}

law gather_rank_refused provedin PROOF.bendsource · line 138 · raw

@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+index:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+entries:List<&2, U32> -> @counted:{Nat.is_eq(length(entries), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.elements(index)) == True{} : Bool} -> @in_rank:{Nat.is_lt(axis(input, dim), rank(input)) == True{} : Bool} -> @ranked:{Nat.is_eq(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.rank_dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(index)), rank(input)) == False{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.gather_plan(input, dim, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Index{index, entries}) == Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.IndexRankMismatch{}} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned>}

law gather_shape_refused provedin PROOF.bendsource · line 149 · raw

@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+index:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+entries:List<&2, U32> -> @counted:{Nat.is_eq(length(entries), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.elements(index)) == True{} : Bool} -> @in_rank:{Nat.is_lt(axis(input, dim), rank(input)) == True{} : Bool} -> @ranked:{Nat.is_eq(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.rank_dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(index)), rank(input)) == True{} : Bool} -> @unmatched:{others(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(input), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(index), axis(input, dim)) == False{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.gather_plan(input, dim, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Index{index, entries}) == Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.IndexShapeMismatch{}} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned>}

law gather_out_of_range provedin PROOF.bendsource · line 161 · raw

@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+index:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+entries:List<&2, U32> -> @counted:{Nat.is_eq(length(entries), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.elements(index)) == True{} : Bool} -> @in_rank:{Nat.is_lt(axis(input, dim), rank(input)) == True{} : Bool} -> @ranked:{Nat.is_eq(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.rank_dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(index)), rank(input)) == True{} : Bool} -> @matched:{others(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(input), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(index), axis(input, dim)) == True{} : Bool} -> @past:{inside(entries, extent(input, axis(input, dim))) == False{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.gather_plan(input, dim, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Index{index, entries}) == Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.OutOfRange{}} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned>}

law gather_planned provedin PROOF.bendsource · line 174 · raw

@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+index:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+entries:List<&2, U32> -> @counted:{Nat.is_eq(length(entries), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.elements(index)) == True{} : Bool} -> @in_rank:{Nat.is_lt(axis(input, dim), rank(input)) == True{} : Bool} -> @ranked:{Nat.is_eq(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.rank_dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(index)), rank(input)) == True{} : Bool} -> @matched:{others(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(input), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(index), axis(input, dim)) == True{} : Bool} -> @within:{inside(entries, extent(input, axis(input, dim))) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.gather_plan(input, dim, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Index{index, entries}) == taken(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Gathered{}, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(input), axis(input, dim), 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.axis_extent(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(index), axis(input, dim))) : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned>}

law gather_index_shaped provedin PROOF.bendsource · line 199 · raw

@+dimensions:List<&2, U32> -> @+entries:List<&2, U32> -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.index(dimensions, entries) == index_of(entries, dimensions, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.construct(dimensions)) : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Index>}

law index_select_refused provedin PROOF.bendsource · line 205 · raw

@input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+entries:List<&2, U32> -> @error:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error -> @refused:{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.select_plan(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_totality.dynamic_shape(input), dim, entries) == Fail{error} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned>} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.index_select(input, dim, entries) == (input, Fail{error}) : Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)}

A refused plan fails the copy with its error and hands the input back.

law gather_refused provedin PROOF.bendsource · line 213 · raw

@input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+index:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+entries:List<&2, U32> -> @error:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error -> @refused:{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.gather_plan(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_totality.dynamic_shape(input), dim, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Index{index, entries}) == Fail{error} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned>} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.gather(input, dim, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Index{index, entries}) == (input, Fail{error}) : Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)}

law gather_build_cells provedin PROOF.bendsource · line 241 · raw

@+depth:Nat -> @+splits:Nat -> @+kind:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Lookup -> @+outer:Nat -> @+rows:Nat -> @+inner:Nat -> @+count:Nat -> @+cells:Nat -> @+base:Nat -> @+da:Nat -> @-A:Array<F32> -> @a:Array<F32> -> @same:{a == A : Array<F32>} -> @valid:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, da, A) -> @+di:Nat -> @-I:Array<U32> -> @index:Array<U32> -> @same_index:{index == I : Array<U32>} -> @index_valid:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(U32, di, I) -> @+path:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Path(depth) -> @+o:Nat -> @+k:Nat -> @+r:Nat -> @k_below:{Nat.is_lt(k, count) == True{} : Bool} -> @r_below:{Nat.is_lt(r, inner) == True{} : Bool} -> @at:{Nat.add(0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.offset(depth, path), base) == position(count, inner, o, k, r) : Nat} -> @in_count:{Nat.is_lt(Nat.add(0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.offset(depth, path), base), cells) == True{} : Bool} -> @+j:U32 -> @read:{0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.observe(U32, di, I, 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/refinement.route(di, U32.from_nat(entry_at(kind, count, inner, o, k, r)))) == Some{j} : Maybe<&2, U32>} -> Holds<{0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.observe(F32, depth, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.build(depth, splits, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Plan{kind, outer, rows, inner, count}, cells, base, a, index), path) == 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.observe(F32, da, A, 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/refinement.route(da, U32.from_nat(position(rows, inner, o, U32.to_nat(j), r)))) : Maybe<&2, F32>}>

For a balanced input array A, a balanced index array I and every split, the slot of the forward build that holds output cell (o, k, r), below the count, holds input cell (o, j, r), where j is the entry the cell reads: the word PyTorch's index_select and gather put there.

law gather_scatter_cells provedin PROOF.bendsource · line 310 · raw

@+depth:Nat -> @+splits:Nat -> @+kind:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Lookup -> @+outer:Nat -> @+rows:Nat -> @+inner:Nat -> @+count:Nat -> @+cells:Nat -> @+base:Nat -> @+dg:Nat -> @-G:Array<F32> -> @g:Array<F32> -> @same:{g == G : Array<F32>} -> @valid:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, dg, G) -> @+di:Nat -> @-I:Array<U32> -> @index:Array<U32> -> @same_index:{index == I : Array<U32>} -> @index_valid:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(U32, di, I) -> @+path:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Path(depth) -> @+o:Nat -> @+i:Nat -> @+r:Nat -> @i_below:{Nat.is_lt(i, rows) == True{} : Bool} -> @r_below:{Nat.is_lt(r, inner) == True{} : Bool} -> @at:{Nat.add(0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.offset(depth, path), base) == position(rows, inner, o, i, r) : Nat} -> @in_count:{Nat.is_lt(Nat.add(0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.offset(depth, path), base), cells) == True{} : Bool} -> Summed<depth, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.scatter_build(depth, splits, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Plan{kind, outer, rows, inner, count}, cells, base, g, index), path, dg, G, di, I, kind, count, inner, o, i, r>

For a balanced gradient array G, a balanced index array I and every split, the slot of the backward build that holds input cell (o, i, r), below the count, holds the gradient words of the cells (o, k, r) whose entry is i, added to +0.0 in increasing k, and +0.0 where no entry is i: PyTorch's one-thread index_add and scatter_add.

Types

type Holds source · line 18 · raw

@-P:Type -> Data

type AddStep source · line 286 · raw

@-dg:Nat -> @-G:Array<F32> -> @-di:Nat -> @-I:Array<U32> -> @-kind:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Lookup -> @-count:Nat -> @-inner:Nat -> @-o:Nat -> @-i:Nat -> @-r:Nat -> @-rest:Nat -> @-k:Nat -> @-acc:F32 -> @-value:F32 -> Data

type Summed source · line 300 · raw

@-depth:Nat -> @-out:Array<F32> -> @-path:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Path(depth) -> @-dg:Nat -> @-G:Array<F32> -> @-di:Nat -> @-I:Array<U32> -> @-kind:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Lookup -> @-count:Nat -> @-inner:Nat -> @-o:Nat -> @-i:Nat -> @-r:Nat -> Data

A slot that holds value, the sum Added names from +0.0 over every k.

Definitions

def axis source · line 22 · raw

@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> Nat

The axis a request names: its signed dim wrapped among the input's rank.

def rank source · line 25 · raw

@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> Nat

def extent source · line 28 · raw

@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+at:Nat -> Nat

def length source · line 32 · raw

@entries:List<&2, U32> -> Nat

How many entries an index holds.

def inside source · line 40 · raw

@entries:List<&2, U32> -> @+bound:Nat -> Bool

Whether every entry lies below the extent.

def equal source · line 48 · raw

@left:List<&2, U32> -> @right:List<&2, U32> -> Bool

Whether two lists of extents are equal, extent by extent.

def others source · line 58 · raw

@dimensions:List<&2, U32> -> @index:List<&2, U32> -> @+at:Nat -> Bool

Whether a gather index has the input's extent at every axis but at.

def viewed source · line 69 · raw

@+kind:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Lookup -> @+given:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.View -> @+count:Nat -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Plan

The plan of a request the checks take: the row-major view of the input around the axis, slice.bend's, and the length of the output's axis ...

def output source · line 75 · raw

@-dimensions:List<&2, U32> -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Plan -> @built:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.ConstructResult<dimensions> -> Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned>

... and its output, the input's dimensions with that length at the axis, or the refusal of the shape's own checks (rank and capacity).

def taken source · line 83 · raw

@+kind:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Lookup -> @+dimensions:List<&2, U32> -> @+at:Nat -> @+count:Nat -> Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned>

def index_of source · line 191 · raw

@+entries:List<&2, U32> -> @-dimensions:List<&2, U32> -> @built:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.ConstructResult<dimensions> -> Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Index>

A gather index is built as a tensor of its dimensions is: refused past rank 4 or 2^20 elements with the shape's own error, else it holds the shape of those dimensions.

def position source · line 225 · raw

@+rows:Nat -> @+inner:Nat -> @+o:Nat -> @+k:Nat -> @+r:Nat -> Nat

The cells of the builds, in the coordinates of the views: cell (o, k, r) of [outer, rows, inner] sits at (o * rows + k) * inner + r.

def entry_at source · line 230 · raw

@+kind:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Lookup -> @+count:Nat -> @+inner:Nat -> @+o:Nat -> @+k:Nat -> @+r:Nat -> Nat

The entry output cell (o, k, r) of [outer, length, inner] reads: entry k of an index_select's index, the entry at the cell itself of a gather's.

def Added source · line 278 · raw

@+dg:Nat -> @-G:Array<F32> -> @+di:Nat -> @-I:Array<U32> -> @+kind:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Lookup -> @+count:Nat -> @+inner:Nat -> @+o:Nat -> @+i:Nat -> @+r:Nat -> @left:Nat -> @+k:Nat -> @+acc:F32 -> @+value:F32 -> Type

The backward of input cell (o, i, r): from gradient cell (o, k, r) on, for left more k, a cell whose entry is i adds its word to the sum, in increasing k; a cell whose entry is another skips. value is the sum at the end.