Static tensor shapes and coordinates #
This module gives the finite geometry used by every TorchLean.Tensor.Internal denotation. A shape is an outermost-first list of natural-number dimensions. Its coordinates are the corresponding iterated product of finite types:
Coord [d0, ..., dn] = Fin d0 x ... x Fin dn x PUnit.
The empty shape therefore has one coordinate, while a shape containing a
zero-length axis has none. Coord.equivFin uses mathlib's
finProdFinEquiv, so linear indices follow the conventional row-major order.
The representation is intentionally self-contained. Static shape expressions and their coordinate spaces are the shared foundation for semantics, lowering, and native execution.
References #
The row-major grouping convention follows einops v0.8.2, especially the
reshape stages in einops.einops._reconstruct_from_shape_uncached and
einops.einops._apply_recipe, pinned at commit
8e911db71f2e693a0c434b041180388c685ed06f.
A tensor shape, listed from the outermost axis to the innermost axis.
Instances For
The number of scalar entries in a shape. The empty product is one.
Instances For
The number of axes in a shape.
Instances For
Coordinates of every finite shape have decidable equality.
Coordinates of every finite shape can be enumerated.
The coordinate type has exactly as many elements as the shape specifies.
Unlinearizing and then linearizing recovers the flat index.
Linearizing and then unlinearizing recovers the multidimensional coordinate.
Linearization is injective.
Linearization is surjective.
Project a coordinate from a dimensionwise broadcast target to its source.
Each source dimension must either equal the corresponding target dimension
or be a singleton. Equal dimensions retain the target coordinate; singleton
dimensions select their unique coordinate. Recursion on the two shape lists
keeps the proof in Prop while constructing coordinate data in Type.
Instances For
Broadcasting a coordinate between identical shapes leaves every dimension unchanged, independently of the proof used to certify compatibility.