Concrete pack and unpack checking #
The packing pattern has a fixed leading region, one *, and a fixed trailing
region. Inputs may have different ranks because * captures an arbitrary
middle shape. A checked plan records the common fixed shapes and proves that
every component decomposes as
leadingShape ++ starShape ++ trailingShape.
The same CheckedPack certificate serves both directions. checkPack rejects
an empty input family and obtains the fixed shapes from its first tensor.
checkUnpack obtains them from the packed tensor, resolves requested star
shapes, and therefore also represents the strict empty-metadata case when the
packed axis has length zero.
Requested unpack dimensions are integers so -1 can denote one inferred
dimension. Every other dimension must be nonnegative. Resolution rejects
multiple inferred dimensions, non-divisible residual lengths, underdetermined
zero products, and metadata whose segment lengths do not exactly partition
the packed axis.
The number of fixed axes surrounding * in a packing pattern.
Instances For
The middle shape captured by * in one component.
Checked components have enough dimensions for both fixed regions. The subtraction therefore removes exactly those regions.
Instances For
A pack/unpack shape plan with exactly the invariants used by semantics.
leadingShape and trailingShape are explicit because strict unpacking may
produce an empty component family, from which the fixed dimensions cannot be
recovered. Component star shapes, segment lengths, metadata, offsets, and the
packed output shape remain deterministic derived values.
- pattern : Syntax.PackPattern
Parsed packing pattern shared by pack and unpack.
Shapes of the unpacked components, in segment order.
- leadingShape : Shape
Fixed dimensions preceding every component's star region.
- trailingShape : Shape
Fixed dimensions following every component's star region.
The stored leading shape has the rank written before
*.The stored trailing shape has the rank written after
*.- input_shapes (component : Fin self.inputShapes.length) : self.inputShapes.get component = self.leadingShape ++ packStarShape self.pattern (self.inputShapes.get component) ++ self.trailingShape
Every component decomposes into the shared prefix, its star region, and suffix.
Instances For
The middle shape represented by one checked component.
Instances For
Pack metadata in component order.
Instances For
Flattened lengths of all packed middle regions.
Instances For
The length of the concatenated packed axis.
Instances For
Shape of the packed tensor.
Instances For
Pack metadata has one entry for every input component.
Segment lengths have one entry for every input component.
Match each input component with its metadata segment.
The two lists have equal length by construction. Naming this equivalence keeps the dependent component-to-segment transport identical in checking, semantics, and lowering.
Instances For
Matching a component with its metadata segment preserves its position in the component list.
A segment length is the row-major size of its metadata shape.
The segment selected by an input component has the row-major size of that component's star region.
Looking up the metadata segment selected for a component yields the size of that component's star region.
Pack metadata is exactly the checked star-shape family in input order.
This extensional form is useful when clients consume metadata through finite component indices rather than list lookup.
Flattening the star region into one axis preserves every component's number of scalar entries.
Reshaping one input component to its checked segment shape preserves the number of entries.
Validate rank and fixed-prefix/suffix agreement for every component in a pack family.
Instances For
Bundle validated component decompositions into the dependent CheckedPack
certificate consumed by semantics and lowering.
Instances For
Check a nonempty family of tensor shapes for packing.
The first component determines fixed leading and trailing dimensions. Every other component must agree at those positions, while its star region may have any finite shape, including an empty shape or zero dimensions.
Instances For
Integer star shapes accepted by the public unpack checker.
Instances For
Compute one fully specified requested star-shape size.
Instances For
Multiply the known factors of a requested shape, treating -1 as unknown.
Instances For
Count inferred -1 dimensions across the complete unpack request.
Instances For
Replace the unique inferred dimension by its resolved natural-number value.
Instances For
Find the first unpack dimension smaller than the permitted sentinel -1.
Instances For
Resolve requested unpack metadata against one concrete packed-axis length.
The result contains only natural-number shapes. Success guarantees computationally that their products sum to the packed-axis length; the subsequent checked plan turns that equality into the segment partition used by semantics.
Instances For
Check strict unpack metadata against a concrete packed tensor shape.
Unlike the reference implementation's backend-deferred failures, every segment bound and reshape size is validated before tensor execution.