Shape and Concatenation IR Lowering #
Checked lowering for permutations, reshaping, flattening, concatenation, and transpose.
Concatenation along axis 0 reads each parent through a typed index and folds
Tensor.concatAxisSpec over the parents; concatenation along another axis first moves that axis to
the front of every parent, folds, and moves it back. Both branches use
concatLeadingAxisFromInputs, and the output-shape cast is justified by
concatLeadingAxisFromInputs_size_eq_sum rather than by a proof embedded in the runtime code.
The nonzero-axis branch validates each parent exactly as NN.IR.Graph.permuteSomeTensor does and
records that evidence in ConcatFrontInput, so the correctness proof can replay the evaluator's
permutation on every parent.
Each operation has its own small lower* definition. lowerShape only dispatches on the operation
kind, and the lowerShape_* equation lemmas let correctness proofs reduce a dispatch to the branch
they care about without unfolding the whole dispatcher.
Checked lowering for .permute perm through a sequence of adjacent axis swaps.
Instances For
Checked lowering for .reshape inS outS.
Instances For
Checked lowering for .flatten s.
Instances For
Build the leading-axis concat inputs for .concat 0: one typed index per parent, all sharing the
tail shape rest.
Instances For
One validated parent of a nonzero-axis concat: its typed index, the adjacent swaps that move the
concatenated axis to the front, and the resulting leading extent. The proof fields record exactly
the checks the IR evaluator performs in NN.IR.Graph.permuteSomeTensor, so the lowering and the
evaluator permute each parent identically.
- sIn : Spec.Shape
The parent's declared shape.
- ip : Proofs.Idx Γ self.sIn
Typed index of the parent in the runtime context.
Adjacent swaps realizing
permFronton a tensor of ranksIn.rank.- nP : ℕ
Leading extent of the permuted parent.
permFrontis a valid permutation of the parent shape with the shared tail.The swaps were computed for the parent's own rank.
Applying the swaps yields the permuted shape.
Instances For
Read and permute the parent so the concatenated axis comes first.
Instances For
Build the concat inputs for a nonzero axis: every parent is read through a typed index and
permuted by permFront so the concatenated axis comes first, sharing the tail restFront.
Instances For
Fold concat inputs along the leading axis into a tensor of the declared leading extent nOut.
hSum records that the input extents add up to nOut, so the cast is justified by
concatLeadingAxisFromInputs_size_eq_sum.
Instances For
Checked lowering for .concat axis along an arbitrary axis.
Instances For
Checked lowering for .transpose axis₁ axis₂ through a sequence of adjacent axis swaps.
Instances For
Checked lowering for permutations, reshaping, flattening, concatenation, and transpose.
Instances For
Dispatch equation for .permute perm.
Dispatch equation for .reshape inS outS.
Dispatch equation for .flatten s.
Dispatch equation for .concat axis.
Dispatch equation for .transpose axis₁ axis₂.