TorchLean API

NN.Tensor.Internal.Elab.Einsum.Partition

Certified contiguous output partitions #

This module proves the general array theorem used by task-parallel einsum output generation. A partition may contain any number of adjacent chunks. Folding their arrays together in source order reconstructs the original finite function exactly.

structure TorchLean.Tensor.Internal.Elab.Impl.CertifiedFlatBuffer {α : Type u} [storage : Storage α] (length : ) (values : Fin lengthα) :

One named physical output buffer together with its complete finite-function semantics.

Generated sequential kernels name this record as one auxiliary definition. Executable code projects produce, while certificates project toArray_produce; neither side needs to unfold the complete native loop.

Instances For
    @[inline]
    def TorchLean.Tensor.Internal.Elab.Impl.flatRange {α : Type u} (total start length : ) (hRange : start + length total) (values : Fin totalα) :
    Fin lengthα

    Select a contiguous subrange of a finite function.

    The range proof is erased. At runtime this adds start to the local index and reads the corresponding value.

    Instances For
      structure TorchLean.Tensor.Internal.Elab.Impl.CertifiedFlatPart {α : Type u} [storage : Storage α] (total start length : ) (hRange : start + length total) (values : Fin totalα) :

      One named parallel chunk together with its exact finite-function semantics.

      Generated code names this record as one auxiliary definition. Executable code projects produce, while certificates project toArray_produce; neither side needs to unfold the named chunk body.

      Instances For
        inductive TorchLean.Tensor.Internal.Elab.Impl.OrderedFlatPartition {α : Type u} [storage : Storage α] (total : ) (values : Fin totalα) :
        List (UnitStorage.Buffer α)Prop

        An ordered list of chunk producers covering the interval from start through total.

        Each producer returns exactly one contiguous physical-buffer range, and the recursive index ensures that adjacent ranges have no gap or overlap. The final constructor requires the accumulated start to equal total, so the partition is complete.

        Instances For
          @[inline]

          Append a complete physical source buffer to a physical output buffer.

          Instances For

            Observing a complete physical-buffer append gives ordinary array append.

            Appending to a fresh empty physical buffer returns the source buffer.

            theorem TorchLean.Tensor.Internal.Elab.Impl.OrderedFlatPartition.foldl_append_eq_array_ofFn {α : Type u} [storage : Storage α] {total start : } {values : Fin totalα} {parts : List (UnitStorage.Buffer α)} (partition : OrderedFlatPartition total values start parts) (initial : Storage.Buffer α) (hStart : start total) (hInitial : Storage.toArray initial = Array.ofFn (flatRange total 0 start values)) :
            Storage.toArray (List.foldl (fun (output : Storage.Buffer α) (part : UnitStorage.Buffer α) => appendBuffer (part ()) output) initial parts) = Array.ofFn values

            Appending every producer in an ordered partition after an existing prefix reconstructs the complete finite-function array.