~/bend-docscommunity

src/tensor/permute_build.bend checks

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

5 imports
import Base
import ../shape/core.bend as Shape
import ../storage/model.bend as Model
import ./axis_spec.bend as Axis
import ./parallel.bend as Parallel

Types

type Request source · line 16 · raw

Data

type Pick source · line 23 · raw

Data

How to take one output coordinate out of a row-major index: reduce the index modulo each of mods in turn, then divide by size. Coordinate k of Shape.digits(dims, x) takes the element counts after the first k dimensions as mods and the count after dimension k as size.

type Recipe source · line 74 · raw

Data

Definitions

def widened source · line 26 · raw

@+outer:Nat -> @pick:Pick -> Pick

def widen source · line 30 · raw

@+outer:Nat -> @pick:Maybe<&2, Pick> -> Maybe<&2, Pick>

def pick_at source · line 39 · raw

@+dims:List<&2, Nat> -> @k:Nat -> Maybe<&2, Pick>

The pick of coordinate k of Shape.digits(dims, x); None past the last dimension.

def located source · line 50 · raw

@+dims:List<&2, Nat> -> @position:Maybe<&2, Nat> -> Maybe<&2, Pick>

def picks source · line 59 · raw

@rank:Nat -> @+axes:List<&2, Nat> -> @+out:List<&2, Nat> -> @+cursor:Nat -> Maybe<&2, List<&2, Pick>>

One pick per input axis, from cursor on: the output coordinate that the axes send to it, as Axis.scatter selects it.

def strides source · line 67 · raw

@+dims:List<&2, Nat> -> List<&2, Nat>

The row-major stride of each dimension: the element count after it.

def recipe source · line 77 · raw

@+request:Request -> Recipe

def digit source · line 83 · raw

@+mods:List<&2, Nat> -> @+size:Nat -> @+x:Nat -> Nat

def coordinate source · line 90 · raw

@+pick:Pick -> @+x:Nat -> Nat

def offset source · line 96 · raw

@+strides:List<&2, Nat> -> @+picks:List<&2, Pick> -> @+x:Nat -> Nat

Shape.offset of the scattered coordinates, each through U32 and back as Shape.words and Shape.naturals take it.

def found source · line 103 · raw

@result:Maybe<&2, List<&2, Pick>> -> @+strides:List<&2, Nat> -> @+index:Nat -> Nat

def source source · line 111 · raw

@+recipe:Recipe -> @+index:Nat -> Nat

The input index output cell index reads.

def at source · line 116 · raw

@+recipe:Recipe -> @+position:Nat -> U32

The input word index output cell position reads.

def take source · line 119 · raw

@b:Array<F32> -> @pair:Pair(Array<F32>, F32) -> Pair(F32, Pair(Array<F32>, Array<F32>))

def read source · line 123 · raw

@+recipe:Recipe -> @+position:Nat -> @state:Pair(Array<F32>, Array<F32>) -> Pair(F32, Pair(Array<F32>, Array<F32>))

def cell source · line 129 · raw

@+recipe:Recipe -> @+position:Nat -> @state:Pair(Array<F32>, Array<F32>) -> @inside:Bool -> Pair(F32, Pair(Array<F32>, Array<F32>))

The cell function of the build: the state is the input array and an empty array that only fills the second slot of the state pair.

def halves source · line 136 · raw

@lp:Pair(Array<F32>, Array<F32>) -> @rp:Pair(Array<F32>, Array<F32>) -> Pair(Pair(Array<F32>, Array<F32>), Pair(Array<F32>, Array<F32>))

def split source · line 142 · raw

@state:Pair(Array<F32>, Array<F32>) -> Pair(Pair(Array<F32>, Array<F32>), Pair(Array<F32>, Array<F32>))

Each half of a fork gets its own clone of the input array.

def splits source · line 147 · raw

@+depth:Nat -> Nat

A subtree below the forks holds 2^15 cells, as in the elementwise build.

def build source · line 150 · raw

@+depth:Nat -> @+request:Request -> @+count:Nat -> @a:Array<F32> -> Array<F32>

def balanced source · line 154 · raw

@+depth:Nat -> @+request:Request -> @+count:Nat -> @a:Array<F32> -> 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, depth, build(depth, request, count, a))