~/bend-docscommunity

src/autograd/broadcast_pointwise_LAWS.bend open laws/TODOs

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

9 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/LAWS.bend as Contracts
import ../tensor/contracts/replayed.bend as Replayed
import ../tensor/contracts/broadcast.bend as PointwiseBroadcast
import ./broadcast.bend as Broadcast

Laws

law broadcast_to_pointwise provedin PROOF.bendsource · line 80 · raw

@+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+target:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @planned:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.broadcast_checked(shape, target) == 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(target) : 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} -> BroadcastToContract<target, shape, index => 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.value(shape, fill, ops, U32.from_nat(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/broadcast.left_map(plan, index))), other => 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.value(shape, fill, ops, other), 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/broadcast.broadcast_to(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Packed{shape, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.TTensor{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.storage(shape, fill, ops), fits}}, target)>

Pointwise family, broadcast_to instance: when the input shape broadcasts to exactly the target, broadcasting a replayed input succeeds with the target's dimensions, output index i holds the input word at left_map(plan, i), its right-aligned broadcast projection, and the returned input keeps every word.

law broadcast_to_replayed provedin PROOF.bendsource · line 101 · raw

@+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+target:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @planned:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.broadcast_checked(shape, target) == 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(target) : 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} -> @-P:(@_:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/broadcast.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Type) -> @h:BroadcastWith(plan, shape, fill, ops, P) -> P(0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/broadcast.broadcast_to(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Packed{shape, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.TTensor{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.storage(shape, fill, ops), fits}}, target))

The broadcast_to result is replayed: for every P, if P holds for every result that hands back the input with its words and gives an output of the plan's shape whose words are cells, then P holds for broadcast_to. The output word at k is the input word at left_map(plan, k), whatever split of the output into parallel halves the build takes, and the output is a replayed tensor, so a later law about a replayed contribution, such as reduce_to_fiber, applies to it.

Types

type BroadcastToContract source · line 38 · raw

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

What broadcast_to promises, stated only through the result: it succeeds with the target's dimensions, every in-bounds output index i holds cell(i), and the returned input still holds every word.

Definitions

def succeeded source · line 11 · raw

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

def output_dimensions source · line 15 · raw

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

def output_point source · line 23 · raw

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

def input_point source · line 31 · raw

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

def cells source · line 50 · raw

@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+fill:F32 -> @+ops:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/LAWS.Op> -> @+count:Nat -> List<&2, F32>

The words of broadcast_to's output in index order: word k is the input word at left_map(plan, k), its right-aligned broadcast projection.

def BroadcastWith source · line 62 · raw

@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+fill:F32 -> @+ops:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/LAWS.Op> -> @-P:(@_:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/broadcast.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Type) -> Type

What the transport form of broadcast_to_replayed asks of P: P holds for the input, replayed with any history that keeps its words, next to an output of the plan's shape, replayed over +0.0 with any history whose words are cells.