TorchLean API

NN.Spec.Core.Tensor.Vec

Vector tensors (Spec.Vec) #

TorchLean’s spec tensor type is shape-indexed:

Spec.Tensor α s

For many developments we need the special case “a length-n vector of scalars”, i.e.

Spec.Tensor α (.dim n .scalar).

This file packages that case up as Spec.Vec n α and provides basic, representation-agnostic helpers:

These utilities are used by learning-theory code (datasets as vectors of examples) and are also generally handy for connecting tensor-shaped objects to Fin-indexed mathlib APIs.

References / analogies:

@[reducible, inline]
abbrev Spec.Vec (n : ) (α : Type) :

A length-n vector of scalar entries α as a spec tensor.

Instances For
    @[reducible, inline]
    abbrev Spec.Vec.toFn {n : } {α : Type} (v : Vec n α) :
    Fin nα

    View a vector tensor as a function Fin n → α.

    Instances For
      @[reducible, inline]
      abbrev Spec.Vec.ofFn {n : } {α : Type} (f : Fin nα) :
      Vec n α

      Build a vector tensor from a function Fin n → α.

      Instances For
        @[simp]
        theorem Spec.Vec.toFn_ofFn {n : } {α : Type} (f : Fin nα) :
        (ofFn f).toFn = f
        @[simp]
        theorem Spec.Vec.ofFn_toFn {n : } {α : Type} (v : Vec n α) :
        ofFn v.toFn = v
        @[reducible, inline]
        abbrev Spec.Vec.get {n : } {α : Type} (v : Vec n α) (i : Fin n) :
        α

        Coordinate access for vector tensors.

        Instances For
          @[simp]
          theorem Spec.Vec.get_ofFn {n : } {α : Type} (f : Fin nα) (i : Fin n) :
          (ofFn f).get i = f i
          def Spec.Vec.update {n : } {α : Type} [DecidableEq (Fin n)] (v : Vec n α) (i : Fin n) (a' : α) :
          Vec n α

          Update one coordinate (total, using Fin indices).

          Instances For
            def Spec.Vec.removeAt {n : } {α : Type} (v : Vec (n + 1) α) (i : Fin (n + 1)) :
            Vec n α

            Remove one coordinate from a vector of length n+1.

            This uses Fin.succAbove to reindex the remaining entries into Fin n.

            Instances For