def sweep

bendtorch-core@0.1.0.0 · src/autograd/tensor_backward.bend:780

import bendtorch-core@0.1.0.0/src/autograd/tensor_backward.bend as TensorBackward
import Base
import bendtorch-core@0.1.0.0/src/autograd/gradient.bend as Gradient

780# Visits entries newest first with their working gradients. Once a step
781# fails, the remaining entries pass through unchanged.
782def sweep(entries: List<&1, Entry>, state: Result<&2, &1, Error, List<&1, Gradient.Slot>>, +count: Nat) -> Swept():
783  match entries state count:
784    case Nil{} state count:
785      (Nil{}, state)
786    case Con{entry, rest} Fail{error} count:
787      (entry <> rest, Fail{error})
788    case Con{entry, rest} Done{Nil{}} count:
789      (entry <> rest, Done{Nil{}})
790    case Con{entry, rest} Done{Con{gradient, pending}} 0n:
791      (entry <> rest, Done{Nil{}})
792    case Con{Entry{+node, +shape, value, saved, slot}, rest} Done{Con{gradient, pending}} 1n+below:
793      visited(node, shape, value, saved, slot, gradient, below, pending, state => sweep(rest, state, below))

Uses (9)

Used by (14)