TorchLean API

NN.Proofs.Autograd.FDeriv.Reindex

Derivatives of tensor coordinate maps #

Slicing, gathering, and broadcasting all read input coordinates through a fixed map. The map need not be injective: repeated reads are precisely why the reverse pass must sum contributions.

These statements use Rep.pull, the coordinate kernel underlying the tensor representation, and the existing Euclidean topology on real tensors. A derivative is therefore stated on the actual tensor type. The coordinate formulas also apply to empty shapes; there is no chosen first element or hidden positivity assumption.

def Proofs.Autograd.Reindex.pullCLM {source target : Spec.Shape} (index : target.Coordsource.Coord) :

The native coordinate pullback, bundled as a continuous linear map.

Instances For
    @[simp]
    theorem Proofs.Autograd.Reindex.pullCLM_apply {source target : Spec.Shape} (index : target.Coordsource.Coord) (x : TorchLean.Tensor source) :

    The bundled map reads exactly the coordinates selected by the native kernel.

    theorem Proofs.Autograd.Reindex.hasFDerivAt_pull {source target : Spec.Shape} (index : target.Coordsource.Coord) (x : TorchLean.Tensor source) :

    Reindexing is linear, so the same coordinate map acts on every input tangent.

    def Proofs.Autograd.Reindex.sumFibers {source target : Spec.Shape} (index : target.Coordsource.Coord) (gradient : TorchLean.Tensor target) :

    A source coordinate receives the sum over all output coordinates which read it.

    There is deliberately no distinctness hypothesis on index. For a gather with repeated indices, every occurrence contributes; for a broadcast, every replicated batch contributes.

    Instances For
      theorem Proofs.Autograd.Reindex.inner_pull_sumFibers {source target : Spec.Shape} (index : target.Coordsource.Coord) (x : TorchLean.Tensor source) (gradient : TorchLean.Tensor target) :
      inner (TorchLean.Tensor.Internal.Rep.pull index x) gradient = inner x (sumFibers index gradient)

      Coordinate pullback and summation over its fibers are adjoint.

      theorem Proofs.Autograd.Reindex.pullCLM_adjoint {source target : Spec.Shape} (index : target.Coordsource.Coord) (gradient : TorchLean.Tensor target) :
      (ContinuousLinearMap.adjoint (pullCLM index)) gradient = sumFibers index gradient

      The analytic adjoint is the concrete accumulation formula, not an unspecified reduction.

      The real spec dot product uses the same inner product as tensor Fréchet derivatives.

      theorem Proofs.Autograd.Reindex.inner_eq_sum_unstack {n : } {shape : Spec.Shape} (x y : TorchLean.Tensor (Spec.Shape.dim n shape)) :
      inner x y = i : Fin n, inner (x.unstack i) (y.unstack i)

      The Euclidean inner product separates over the leading tensor axis.