Closed
Description
There are multiple problems, both related to adoption due to conflicting definitions, and because NumPy's transpose
does something no one really wants (namely, swap all axes).
The current array API transpose
may not be correct:
- https://data-apis.org/array-api/latest/API_specification/linear_algebra_functions.html#transpose-x-axes-none says "swap all axes"
- Linear Algebra design overview #147 claims the intent is to only swap the last two axes, to be consistent with all other
linalg
functions.
PyTorch names the numpy.transpose
equivalent permute
, and PyTorch's transpose
is np.swapaxes
. Relevant issues PyTorch issues:
- torch.transpose is divergent from np.transpose pytorch/pytorch#50275
- [ux] Proposal to have t() === transpose(-1, -2), since batches are very frequent pytorch/pytorch#51280
Relevant NumPy issues:
- Feature request:
T
method for transposition applying to 1D vectors numpy/numpy#9530 - ENH: ndarray.T2 for 2D transpose. numpy/numpy#7495
- Hermitian Transpose Syntax numpy/numpy#13797 (note that there's
np.linalg.linalg.transpose
which is private but does have the desired behavior)
There's multiple ways of dealing with this problem:
- Accept the status quo
- Remove
transpose
completely, and usepermute
or some other function name with the behavior we want by default (do the right thing for batches of 2-D matrices) - Add both, by adding a
matrix_transpose
function and a corresponding.mT
(or.MT
) attribute
I searched the JAX and TensorFlow issue trackers as well and, somewhat surprisingly, didn't find an issue about this topic.