TorchLean API

NN.Runtime.Autograd.Torch.Core.Functional.Curried

Curried Tensor and Reference Arguments #

Convert between shape-indexed packs and curried arguments for tensors or any reference family.

Type of a curried function accepting one tensor argument per shape in ss.

For example, Fn α [s₁, s₂] β is Tensor α s₁ → Tensor α s₂ → β.

Instances For
    def Runtime.Autograd.Torch.Curried.curry {α : Type} [TorchLean.Storage α] {β : Type} {ss : List Spec.Shape} :
    (TorchLean.TensorPack α ssβ)Fn α ss β

    Convert a function on tensor-pack inputs into its curried form.

    Instances For

      Convert a curried function into a function on tensor-pack inputs.

      Instances For

        A pack of references indexed by their shapes, analogous to TensorPack.

        Instances For
          def Runtime.Autograd.Torch.RefList.append {Ref : Spec.ShapeType} {ss₁ ss₂ : List Spec.Shape} :
          RefList Ref ss₁RefList Ref ss₂RefList Ref (ss₁ ++ ss₂)

          Append two RefLists.

          Instances For
            def Runtime.Autograd.Torch.RefList.split {Ref : Spec.ShapeType} {ss₁ ss₂ : List Spec.Shape} :
            RefList Ref (ss₁ ++ ss₂)RefList Ref ss₁ × RefList Ref ss₂

            Split a RefList Ref (ss₁ ++ ss₂) into its left and right parts.

            Instances For
              def Runtime.Autograd.Torch.RefList.splitLast {Ref : Spec.ShapeType} {ss : List Spec.Shape} {τ : Spec.Shape} :
              RefList Ref (ss ++ [τ])RefList Ref ss × Ref τ

              Split a RefList Ref (ss ++ [τ]) into its prefix and last element.

              Instances For
                @[simp]
                theorem Runtime.Autograd.Torch.RefList.split_append {Ref : Spec.ShapeType} {ss₁ ss₂ : List Spec.Shape} (xs : RefList Ref ss₁) (ys : RefList Ref ss₂) :
                (xs.append ys).split = (xs, ys)

                Splitting concatenated references recovers the original state blocks.

                @[simp]
                theorem Runtime.Autograd.Torch.RefList.splitLast_append {Ref : Spec.ShapeType} {ss : List Spec.Shape} {τ : Spec.Shape} (xs : RefList Ref ss) (x : Ref τ) :
                (xs.append (cons x nil)).splitLast = (xs, x)

                The final reference remains separate from the preceding model state.

                @[simp]
                theorem Runtime.Autograd.Torch.RefList.append_split {Ref : Spec.ShapeType} {ss₁ ss₂ : List Spec.Shape} (xs : RefList Ref (ss₁ ++ ss₂)) :
                xs.split.1.append xs.split.2 = xs

                Reassembling the two state blocks restores every original reference.

                theorem Runtime.Autograd.Torch.RefList.append_assoc {Ref : Spec.ShapeType} {a b c : List Spec.Shape} (xs : RefList Ref a) (ys : RefList Ref b) (zs : RefList Ref c) :
                (xs.append ys).append zs = xs.append (ys.append zs)

                Reassociating state blocks changes only their shape-list witness, not their references.

                A curried function accepting one Ref s argument per shape in ss.

                Instances For
                  def Runtime.Autograd.Torch.CurriedRef.uncurry {Ref : Spec.ShapeType} {β : Type} {ss : List Spec.Shape} :
                  CurriedRef Ref ss βRefList Ref ssβ

                  Uncurry a curried reference function to accept a RefList.

                  Instances For
                    def Runtime.Autograd.Torch.CurriedRef.curry {Ref : Spec.ShapeType} {β : Type} {ss : List Spec.Shape} :
                    (RefList Ref ssβ)CurriedRef Ref ss β

                    Curry a reference function that consumes a RefList.

                    Instances For
                      @[simp]
                      theorem Runtime.Autograd.Torch.CurriedRef.uncurry_curry {Ref : Spec.ShapeType} {β : Type} {ss : List Spec.Shape} (f : RefList Ref ssβ) (xs : RefList Ref ss) :
                      (curry f).uncurry xs = f xs

                      Binding the curried arguments preserves the complete reference-list computation.

                      Apply a tensor-valued CurriedRef to its shape-indexed tensor pack.

                      Instances For