def bump_pulls
bendtorch-core@0.1.0.0 · src/autograd/tensor_chain_PROOF.bend:136
import bendtorch-core@0.1.0.0/src/autograd/tensor_chain_PROOF.bend as TensorChainPROOF
import Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
import bendtorch-core@0.1.0.0/src/autograd/gradient.bend as Gradient
import bendtorch-core@0.1.0.0/src/autograd/tensor_backward.bend as Backward
import bendtorch-core@0.1.0.0/src/autograd/tensor_chain_LAWS.bend as Laws
136
137
138def bump_pulls(pending: List<&1, Gradient.Slot>, +count: Nat, +target: Nat, +shape: Shape.Shape, gradient: Core.Dynamic, same: Bool,
139 -slots: List<&1, Gradient.Slot>, -log: Laws.Log(), pulls: Pulls(pending, slots, count, log),
140 decided: {Backward.at_head(count, target) == same : Bool}) -> Bumped<pending, count, target, shape, gradient, same, slots, log>:
141 match pending count same:
142 case Nil{} count same:
143 Bumped{Done{Nil{}}, {==}, pulls}
144 case Con{x, rest} 0n same:
145 Bumped{Done{x <> rest}, {==}, pulls}
146 case Con{x, rest} 1n+below True{}:
147 Cell{w, older, left, at, took, tail} = pulls
148 hit_bumped(x, rest, below, target, shape, gradient, slots, log,
149 hit(Gradient.accumulate(shape, x, gradient), rest, below, target, shape, gradient, slots, log, w, older, left, at, tail,
150 took_hit(below, target, shape, gradient, log, w, x, left, took, decided)))
151 case Con{x, rest} 1n+below False{}:
152 Cell{w, older, left, at, took, tail} = pulls
153 missed(x, rest, below, target, shape, gradient, slots, log, w, older, left, at,
154 took_miss(below, target, shape, gradient, log, w, x, left, took, decided),
155 bump_pulls(rest, below, target, shape, gradient, Backward.at_head(below, target), older, left, tail, {==}))