Problem
After the Tensor work lands, the project carries two parallel C implementations of "dense array of doubles": one rank-2 (Matrix), one N-D (Tensor). Every arithmetic op, every aggregate, every cross-interpreter round-trip exists twice. New work has to be added in both places, or one side drifts. This is sustainable for one release; it is not sustainable as a long-term shape for the library.
Desired functionality
The two types share a single C representation and a single set of inner loops. Matrix becomes the rank-2 face of that shared machinery. The Python-level Matrix API — constructor, methods, return types, repr, type identity — looks identical to today from the outside; existing user code, existing examples, and existing downstream C consumers keep working unmodified.
Constraints
- Zero public API breakage. Every existing
Matrix test, every example, every downstream C ABI consumer must keep working unchanged.
- No measurable performance regression on
Matrix-shaped workloads.
Matrix keeps its own Python type. isinstance(x, Matrix) keeps working.
- Rank-2-only algebra (matmul, transpose,
T, axis-0 / axis-1 aggregate sugar) stays on Matrix.
Out of scope
Generalising rank-2 algebra onto Tensor (matmul on Tensor, batched matmul, transpose(axes=...), swapaxes). Removing or renaming any public Matrix surface. Treating Matrix as deprecated.
Open questions
- Whether
Matrix and Tensor should be silently interchangeable in each other's arithmetic dunders, or whether the user has to step through an explicit conversion.
- Whether to expose explicit
Matrix.to_tensor() / Tensor.to_matrix() helpers regardless.
Problem
After the Tensor work lands, the project carries two parallel C implementations of "dense array of doubles": one rank-2 (
Matrix), one N-D (Tensor). Every arithmetic op, every aggregate, every cross-interpreter round-trip exists twice. New work has to be added in both places, or one side drifts. This is sustainable for one release; it is not sustainable as a long-term shape for the library.Desired functionality
The two types share a single C representation and a single set of inner loops.
Matrixbecomes the rank-2 face of that shared machinery. The Python-levelMatrixAPI — constructor, methods, return types, repr, type identity — looks identical to today from the outside; existing user code, existing examples, and existing downstream C consumers keep working unmodified.Constraints
Matrixtest, every example, every downstream C ABI consumer must keep working unchanged.Matrix-shaped workloads.Matrixkeeps its own Python type.isinstance(x, Matrix)keeps working.T, axis-0 / axis-1 aggregate sugar) stays onMatrix.Out of scope
Generalising rank-2 algebra onto
Tensor(matmul on Tensor, batched matmul,transpose(axes=...),swapaxes). Removing or renaming any publicMatrixsurface. TreatingMatrixas deprecated.Open questions
MatrixandTensorshould be silently interchangeable in each other's arithmetic dunders, or whether the user has to step through an explicit conversion.Matrix.to_tensor()/Tensor.to_matrix()helpers regardless.