Linear Algebra Helpers #
Rank-polymorphic axis permutations, broadcasted matmul, and shape matching.
Swap adjacent tensor axes at depth and depth + 1.
Instances For
Map an output coordinate back to the input coordinate of an adjacent-axis swap.
At depth zero, an output coordinate (j, i, rest) reads (i, j, rest). At greater
depths, the preceding coordinates stay fixed. If there are fewer than two axes
left to exchange, the coordinate stays unchanged, as in Shape.swapAdjacentAtDepth.
Instances For
Build an adjacent-axis swap by reading each output entry directly from the input.
The recursive specification constructs tensor slices with unstack. Each slice
owns a buffer, so constructing a column of a matrix this way repeatedly copies
input rows. A coordinate pull constructs the output buffer in one pass and reads
the corresponding scalar from the original tensor, without intermediate slices.
Instances For
Adjacent-axis swaps read the input at the coordinate with the same axes exchanged.
Compile the recursive specification as a direct coordinate pull.
Equality is proved for every scalar storage instance, shape, and swap depth. The public definition and its reduction equations remain available to proofs; compiled calls use the equivalent implementation that avoids copying intermediate slices.
Apply adjacent-axis swaps while retaining the resulting shape in the return type.
Instances For
Swapping at depth zero exchanges the two leading axes.
Concatenated shapes add their ranks.
Appending the same suffix preserves equal ranks.
Extend prefix-broadcast evidence across a fixed non-broadcasted tensor suffix.
Batched matmul over an outer axis is the batched matmul of each pair of slices.
Matrix-rank matmul with explicit broadcasting of both batch prefixes.
A has shape batchA ++ [m, n], B has shape batchB ++ [n, p], and both batch
prefixes broadcast to batch. The result has shape batch ++ [m, p].
Instances For
Reverse-mode derivatives for matrix-rank matmul with broadcasted batch prefixes.