You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RFC: allow moveaxis(x, (i, j), (j, i)) when i and j refer to the same axis? #1020
API changeChanges to existing functions or objects in the API.Needs DiscussionNeeds further discussion.RFCRequest for comments. Feature requests and proposed changes.topic: ManipulationArray manipulation and transformation.
This came up in data-apis/array-api-extra#97 (adding swapaxes). If moveaxis(x, (i, j), (j, i)) were allowed when i and j refer to the same axis, e.g. (1, -1) on a 2D array, and returned x unchanged, then swapaxes would be a one-liner on top of moveaxis. array-api-extra would not need it.
None of the libraries I tried allow it:
Library
Version
moveaxis(x, (i, j), (j, i)), same axis
swapaxes(x, i, j), same axis
NumPy
2.5.5
ValueError: repeated axis in `source` argument
returns x
Dask
2026.8.0
ValueError: repeated axis in `source` argument
returns x
JAX
0.12.1
TypeError: transpose permutation isn't a permutation of operand dimensions
returns x
PyTorch
2.15.0
RuntimeError: movedim: repeated dim in `source` ([1, -1])
returns x
array-api-strict
2.6.1
ValueError: repeated axis in `source` argument
no swapaxes
pydata/sparse
0.19.3
ValueError: repeated axis in transpose
no swapaxes
Cases: (i, j) = (1, -1), (0, 0), (-2, 0) on shape (2, 3) and (2, -1) on shape (2, 3, 4), directly and through array-api-compat (Python 3.12.3, Windows). I couldn't run CuPy (no GPU).
The standard requires the source axes to be unique and doesn't specify the error. moveaxis was requested together with swapaxes in #483 and added in #656. swapaxes was left out; in #483 it was noted as problematic (pointing to #228) and as simple to implement in terms of moveaxis. That holds except in the same-axis case, which needs special handling.
Is there room to allow this case, or should it stay an error?
The survey script was written with Claude (Opus 5.5); I ran it myself.
thanks for the investigation @danggeun ! I think it would be ideal if the standard did allow this, but it sounds like it will be a major change for all prominent libraries indeed, so probably not the highest priority change in the short term.
I'd be open to adding swapaxes to array-api-extra to address this use-case in the meantime.
API changeChanges to existing functions or objects in the API.Needs DiscussionNeeds further discussion.RFCRequest for comments. Feature requests and proposed changes.topic: ManipulationArray manipulation and transformation.
Activity
lucascolley commentedon Nov 22, 2026
thanks for the investigation @danggeun ! I think it would be ideal if the standard did allow this, but it sounds like it will be a major change for all prominent libraries indeed, so probably not the highest priority change in the short term.
I'd be open to adding
swapaxesto array-api-extra to address this use-case in the meantime.