Heterogeneous Tensor Packs #
TorchLean.TensorPack α shapes stores one tensor for every shape in shapes. Unlike a tensor,
whose entries all have one element type and one rectangular shape, a tensor pack may contain tensors
of different ranks and extents. The shape of every entry is nevertheless known statically.
Tensor packs are the common representation for model parameters, gradients, and typed graph
contexts. Ordinary supervised data uses the named Sample.Supervised record; conversion to a pack
happens only at the graph-runtime boundary. This module owns the datatype and its
representation-independent operations so those layers do not depend on autograd proofs or a
particular runtime.
A heterogeneous sequence containing one tensor for every shape in shapes.
- nil
{α : Type}
[Storage α]
: TensorPack α []
The empty tensor pack.
- cons
{α : Type}
[Storage α]
{s : Spec.Shape}
{ss : List Spec.Shape}
: Tensor α s → TensorPack α ss → TensorPack α (s :: ss)
Add a tensor whose shape becomes the head of the pack's shape list.
Instances For
Construct an empty tensor pack without exposing its recursive representation.
Instances For
Construct a pack containing one tensor.
Instances For
Construct a two-tensor pack without exposing its recursive representation.
Instances For
Return the first tensor in a nonempty pack.
Instances For
Return every tensor after the first in a nonempty pack.
Instances For
Return the tensor at position i; its shape is determined by the pack's shape list.
Instances For
Reading position zero of a cons gives the head tensor.
Reading a later position skips the head and recurses into the tail.
With get_cons_zero, this pair lets simp evaluate any concrete lookup all the way down, which is
what keeps the pack indexing invisible in downstream proofs.
Stack a family of packs, giving every parameter tensor the same leading axes.
Instances For
Evaluate a family of packs in row-major order and stack every parameter tensor.
Instances For
Apply a shape-preserving function to every tensor in a pack.
Instances For
Combine two packs pointwise with a shape-preserving binary function.
Instances For
Concatenate two tensor packs.
Instances For
Split a tensor pack at a statically known shape-list boundary.
Instances For
Splitting a concatenated pair of packs recovers both inputs.
Splitting preserves a shape-preserving conversion on each side of the boundary.
Reading the first tensor commutes with a pack conversion.
Construct the all-zero tensor pack.
Instances For
Construct a tensor pack whose every entry contains value.
Instances For
Print every tensor in a pack in state order, with its statically known shape.
Instances For
Add two tensor packs pointwise.
Instances For
Multiply every tensor entry by the same scalar.
Instances For
Subtract two tensor packs pointwise.
Instances For
Append one tensor to the end of a pack.
Instances For
Separate a nonempty pack into its prefix and final tensor.
Instances For
Transport a tensor pack along an equality between its shape lists.
Instances For
Casting along rfl does nothing.
Two successive casts collapse into one along the composed equality.
A cast followed by its inverse is the identity.
These three lemmas are the whole reason cast is tolerable: casts pile up whenever two packs with
propositionally equal shape lists meet, and as simp lemmas they cancel out on their own instead of
being carried through every proof by hand.
Re-appending the final tensor obtained by unsnoc reconstructs the original pack.
A shape-sharing implementation of snoc, with the same indexed result type.
Instances For
Compile snoc using shared shape-list suffixes while retaining its logical definition.