TorchLean API

NN.API.Tensor

Shape-Indexed Tensors #

Tensor construction, shape operations, runtime conversion, and executable tensor operators.

Low-level executable ops for verification and compiler-facing examples.

Most model code should use nn.* and Trainer.*. Use Ops.* when writing an explicit TorchLean executable program directly, for example before compiling a hand-built fragment to NN.IR.Graph.

@[reducible, inline]

Construct a shape from its outermost-to-innermost dimensions.

Instances For
    def TorchLean.Tensor.flattenBatchPrefix {α : Type} [Inhabited α] (batch takeDim : ) {source : Shape} (hTake : takeDim source.size) (x : Spec.Tensor α (Spec.Shape.dim batch source)) :

    Flatten each sample in a batch and retain its first takeDim entries.

    The proof hTake rules out truncation beyond the flattened source shape, so the result has the statically known shape batch × takeDim.

    Instances For
      def TorchLean.Tensor.vectorFromArray {α : Type} (n : ) (xs : Array α) (fallback : α) :

      Construct a fixed-length vector from an array.

      Entries beyond the array use fallback; entries beyond length n are ignored. This constructor is useful at runtime data boundaries where the tensor length is fixed by a model type while the source array is checked or padded by the caller.

      Instances For
        @[reducible, inline]
        abbrev TorchLean.Tensor.T (α : Type) :

        Public shorthand for TorchLean's shape-indexed tensor family.

        Instances For
          @[reducible, inline]
          abbrev TorchLean.Tensor.map {α β : Type} {s : Shape} (f : αβ) (x : T α s) :
          T β s

          Apply a scalar function pointwise while preserving the tensor shape.

          Instances For
            def TorchLean.Tensor.castFloat {α : Type} (cast : Floatα) {s : Shape} (t : T Float s) :
            T α s

            Convert a Float tensor pointwise with an explicitly supplied scalar cast.

            Instances For
              def TorchLean.Tensor.fromFloatList {α : Type} [Context α] (cast : Floatα) (dims : List ) (xs : List Float) :

              Construct a tensor from a flat list of Float values and convert each entry to the selected scalar type. The list length must equal the product of dims.

              Instances For
                def TorchLean.Tensor.generateFromFloat {α : Type} [Context α] (cast : Floatα) (dims : List ) (f : Float) :
                T α (Shape.ofDims dims)

                Generate a tensor from its flat element index and convert each generated Float to the selected scalar type.

                Instances For
                  def TorchLean.Tensor.generateFromFloatShape {α : Type} [Context α] (cast : Floatα) (shape : Shape) (f : Float) :
                  T α shape

                  Generate a tensor of a statically known shape from its flat element index.

                  Instances For
                    def TorchLean.Tensor.repeatBatch {α : Type} {s : Shape} (batch : ) (x : T α s) :
                    T α (Spec.Shape.dim batch s)

                    Repeat one tensor across a fixed batch axis.

                    Use this for classifier demos whose checked model consumes a whole batch, while the example wants to inspect one ordinary input.

                    Instances For

                      Convert a runtime tensor back to a Float tensor inside IO.

                      Trainer prediction handles use this so examples can train under executable IEEE32 or another scalar backend, then inspect ordinary Float tensors afterward.

                      Instances For

                        Model construction, training, runtime selection, and verification live in their corresponding TorchLean namespaces.