TorchLean API

NN.Runtime.Autograd.LeadingAxis

Leading-Axis Reference Maps #

A backend-independent recursion for applying an operation pointwise over the outer axis of a shape-typed reference. Eager and compiled runtimes supply their own slicing, reshaping, and concatenation operations; the traversal itself remains shared.

@[irreducible]
def Runtime.Autograd.mapLeadingAxisWith {m : TypeType} [Monad m] {Ref : Spec.ShapeType} {σ τ : Spec.Shape} (empty : m (Ref (Spec.Shape.dim 0 τ))) (slice : {n : } → Ref (Spec.Shape.dim n σ)(start len : ) → len + start nm (Ref (Spec.Shape.dim len σ))) (reshape : {s₁ s₂ : Spec.Shape} → Ref s₁s₁.size = s₂.sizem (Ref s₂)) (concat : {n k : } → Ref (Spec.Shape.dim n τ)Ref (Spec.Shape.dim k τ)m (Ref (Spec.Shape.dim (n + k) τ))) (f : Ref σm (Ref τ)) {n : } (x : Ref (Spec.Shape.dim n σ)) :
m (Ref (Spec.Shape.dim n τ))

Apply a reference-level operation independently to every entry of a leading axis.

The callbacks isolate the four structural operations needed by the recursion. Device backends may replace this reference traversal with a fused primitive when the fused operation has the same per-entry semantics.

Instances For