~/bend-docscommunity

src/autograd/reduce_fold_LAWS.bend open laws/TODOs

raw source on the hub · import bendtorch-core@0.1.0.0/src/autograd/reduce_fold_LAWS.bend as Reduce_fold_LAWS

11 imports
import Base
import ../shape/core.bend as Shape
import ../storage/LAWS.bend as StorageLaws
import ../tensor/core.bend as Core
import ../tensor/lifecycle.bend as Lifecycle
import ../tensor/contracts/replayed.bend as Replayed
import ../tensor/contracts/fold.bend as Fold
import ../tensor/contracts/LAWS.bend as Contracts
import ./reduce.bend as Reduce
import ./reduce_LAWS.bend as ReduceLaws
import ./reduce_fold.bend as ReduceFold

Laws

law reduce_fold_fiber provedin PROOF.bendsource · line 26 · raw

@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @same:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan)) : List<&2, Nat>} -> @+index:U32 -> @+fill:F32 -> @+ops:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/LAWS.Op> -> @-fits:{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/lifecycle.logical_length(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.storage(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan), fill, ops)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan))) : Nat} -> FiberContract<0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan), 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_LAWS.fiber(plan, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/LAWS.words(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan), fill, ops, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan)))), index, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan)))), other => 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.value(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan), fill, ops, other), 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_fold.cell(plan, index, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Packed{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan), 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.TTensor{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.storage(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan), fill, ops), fits}})>

Ordered-fold family, reduce instance: for a plan whose output has the contribution's shape, every target index and every replayed contribution, the reduce cell gives ReduceLaws.fiber over the contribution's words in index order, and returns the contribution with every word kept.

law reduce_to_fiber provedin PROOF.bendsource · line 81 · raw

@+target:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @planned:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.broadcast_checked(target, shape) == Done{plan} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan>} -> @same:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape) : List<&2, U32>} -> @+fill:F32 -> @+ops:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/LAWS.Op> -> @-fits:{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/lifecycle.logical_length(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.storage(shape, fill, ops)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape)) : Nat} -> ReduceToContract<target, shape, index => 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_LAWS.fiber(plan, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/LAWS.words(shape, fill, ops, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape))), index, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape))), other => 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.value(shape, fill, ops, other), 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.reduce_to(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Packed{shape, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.TTensor{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.storage(shape, fill, ops), fits}}, target)>

reduce_to through the ordered-fold family: when the target broadcasts to exactly the contribution's dimensions, reducing a replayed contribution succeeds with the target's dimensions, every target cell holds ReduceLaws.fiber over the contribution's words in index order, the value reduce_fold_fiber states for ReduceFold.cell, and the returned contribution keeps every word.

Types

type FiberContract source · line 15 · raw

@-input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @-expected:Maybe<&2, F32> -> @-word:(@_:U32 -> F32) -> @-result:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, F32>) -> Type

What a reduce cell promises, stated only through the result: it gives expected, and the returned contribution still holds every word.

type ReduceToContract source · line 65 · raw

@-target:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @-input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @-expected:(@_:U32 -> Maybe<&2, F32>) -> @-word:(@_:U32 -> F32) -> @-result:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Type

What reduce_to promises, stated only through the result: it succeeds with the target's dimensions, every in-bounds target cell holds expected, and the returned contribution still holds every word.

Definitions

def output_dimensions source · line 42 · raw

@result:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Maybe<&2, List<&2, U32>>

def output_point source · line 50 · raw

@result:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> @+index:U32 -> Maybe<&2, F32>

def input_point source · line 58 · raw

@result:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> @+index:U32 -> Maybe<&2, F32>