law reduce_to_fiber

bendtorch-core@0.1.0.0 · src/autograd/reduce_fold_LAWS.bend:75

import bendtorch-core@0.1.0.0/src/autograd/reduce_fold_LAWS.bend as ReduceFoldLAWS
import Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
import bendtorch-core@0.1.0.0/src/storage/LAWS.bend as StorageLaws
import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
import bendtorch-core@0.1.0.0/src/tensor/lifecycle.bend as Lifecycle
import bendtorch-core@0.1.0.0/src/tensor/contracts/replayed.bend as Replayed
import bendtorch-core@0.1.0.0/src/tensor/contracts/LAWS.bend as Contracts
import bendtorch-core@0.1.0.0/src/autograd/reduce.bend as Reduce
import bendtorch-core@0.1.0.0/src/autograd/reduce_LAWS.bend as ReduceLaws
import bendtorch-core@0.1.0.0/src/autograd/reduce_fold.bend as ReduceFold

75# reduce_to through the ordered-fold family: when the target broadcasts to
76# exactly the contribution's dimensions, reducing a replayed contribution
77# succeeds with the target's dimensions, every target cell holds
78# `ReduceLaws.fiber` over the contribution's words in index order, the value
79# `reduce_fold_fiber` states for `ReduceFold.cell`, and the returned
80# contribution keeps every word.
81law reduce_to_fiber:
82  for +target: Shape.Shape
83  for +shape: Shape.Shape
84  for +plan: Shape.BroadcastPlan
85  for planned: {Shape.broadcast_checked(target, shape) == Done{plan} : Result<&2, &2, Shape.Error, Shape.BroadcastPlan>}
86  for same: {Shape.dimensions(Shape.output_shape(plan)) == Shape.dimensions(shape) : List<&2, U32>}
87  for +fill: F32
88  for +ops: List<&2, StorageLaws.Op>
89  for -fits: {Lifecycle.logical_length(Replayed.storage(shape, fill, ops)) == Shape.logical_numel(Shape.dimensions(shape)) : Nat}
90  ReduceToContract<target, shape,
91    index => ReduceLaws.fiber(plan, Contracts.words(shape, fill, ops, Shape.logical_numel(Shape.dimensions(shape))),
92      index, Shape.logical_numel(Shape.dimensions(shape))),
93    other => Replayed.value(shape, fill, ops, other),
94    Reduce.reduce_to(Core.Packed{shape, Core.TTensor{Replayed.storage(shape, fill, ops), fits}}, target)>

Uses (23)

Used by (1)