Skip to content

Commit bd1e695

Browse files
committed
Add specification for moving array axes to new positions
1 parent 2056a94 commit bd1e695

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

spec/draft/API_specification/manipulation_functions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Objects in API
2323
concat
2424
expand_dims
2525
flip
26+
moveaxis
2627
permute_dims
2728
reshape
2829
roll

src/array_api_stubs/_draft/manipulation_functions.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ def flip(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None) ->
9999
"""
100100

101101

102+
def moveaxis(x: array, source: Union[int, Tuple[int, ...]], destination: Union[int, Tuple[int, ...]], /) -> array:
103+
"""
104+
Moves array axes (dimensions) to new positions, while leaving other axes in their original positions.
105+
106+
Parameters
107+
----------
108+
x: array
109+
input array.
110+
source: Union[int, Tuple[int, ...]]
111+
Axes to move. Provided axes must be unique. If ``x`` has rank (i.e, number of dimensions) ``N``, a valid axis must reside on the open-interval ``(-N, N)``.
112+
destination: Union[int, Tuple[int, ...]]
113+
indices defining the desired positions for each respective ``source`` axis index. Provided indices must be unique. If ``x`` has rank (i.e, number of dimensions) ``N``, a valid axis must reside on the open-interval ``(-N, N)``.
114+
115+
Returns
116+
-------
117+
out: array
118+
an array containing reordered axes. The returned array must have the same data type as ``x``.
119+
"""
120+
121+
102122
def permute_dims(x: array, /, axes: Tuple[int, ...]) -> array:
103123
"""
104124
Permutes the axes (dimensions) of an array ``x``.
@@ -240,6 +260,7 @@ def unstack(x: array, /, *, axis: int = 0) -> Tuple[array, ...]:
240260
"concat",
241261
"expand_dims",
242262
"flip",
263+
"moveaxis",
243264
"permute_dims",
244265
"reshape",
245266
"roll",

0 commit comments

Comments
 (0)