TorchLean API

NN.Proofs.RuntimeApprox.NF.BackwardOps.Sparse

Sparse VJP Contexts #

Shape-indexed context builders used by the NF reverse-mode proofs. These helpers write only the positions touched by a local VJP rule and leave every other component at zero, which lets the sparse cases avoid unnecessary rounded additions.

Sparse Contexts For Local VJPs #

A TorchLean.TensorPack filled with zeros (shape-wise), used to build sparse contexts for local VJPs.

Instances For

    Set a single Idx position in a TorchLean.TensorPack, filling all other entries with zeros.

    Instances For
      def Proofs.RuntimeApprox.SparseContext.set2Idx {α : Type} [TorchLean.Storage α] [Zero α] [Add α] {Γ : List Spec.Shape} {s₁ s₂ : Spec.Shape} :
      Idx Γ s₁TorchLean.Tensor α s₁Idx Γ s₂TorchLean.Tensor α s₂TorchLean.TensorPack α Γ

      Set two indices; if they coincide, add the contributions at that position.

      Instances For

        An EList filled with zeros, used for sparse error-bound contexts.

        Instances For

          Set a single Idx position in an EList, filling all other entries with zeros.

          Instances For
            def Proofs.RuntimeApprox.EList.set2Idx {Γ : List Spec.Shape} {s₁ s₂ : Spec.Shape} :
            Idx Γ s₁Idx Γ s₂EList Γ

            Set two indices in an EList; if they coincide, use the supplied combined value eBoth.

            Instances For
              def Proofs.RuntimeApprox.SparseContext.set3IdxNe {α : Type} [TorchLean.Storage α] [Zero α] [Add α] {Γ : List Spec.Shape} {s₁ s₂ s₃ : Spec.Shape} (a : Idx Γ s₁) :
              TorchLean.Tensor α s₁(b : Idx Γ s₂) → TorchLean.Tensor α s₂(c : Idx Γ s₃) → TorchLean.Tensor α s₃a.i b.ia.i c.ib.i c.iTorchLean.TensorPack α Γ

              Set three indices when the positions are pairwise distinct.

              This avoids any context-wise addition: only the three targeted positions are written, and all others are 0. This is important for NF, where even x + 0 would incur rounding.

              Instances For
                def Proofs.RuntimeApprox.EList.set3IdxNe {Γ : List Spec.Shape} {s₁ s₂ s₃ : Spec.Shape} (a : Idx Γ s₁) :
                (b : Idx Γ s₂) → (c : Idx Γ s₃) → a.i b.ia.i c.ib.i c.iEList Γ

                Error list matching SparseContext.set3IdxNe: set three positions and use 0 elsewhere.

                Instances For