Skip to content

Commit b823223

Browse files
authored
Merge pull request #656 from kgryte/moveaxis
PR-URL: #656
2 parents 9dbdec0 + 8149b33 commit b823223

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Diff for: spec/draft/API_specification/manipulation_functions.rst

+1
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

Diff for: src/array_api_stubs/_draft/manipulation_functions.py

+26
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"concat",
55
"expand_dims",
66
"flip",
7+
"moveaxis",
78
"permute_dims",
89
"reshape",
910
"roll",
@@ -114,6 +115,31 @@ def flip(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None) ->
114115
"""
115116

116117

118+
def moveaxis(
119+
x: array,
120+
source: Union[int, Tuple[int, ...]],
121+
destination: Union[int, Tuple[int, ...]],
122+
/,
123+
) -> array:
124+
"""
125+
Moves array axes (dimensions) to new positions, while leaving other axes in their original positions.
126+
127+
Parameters
128+
----------
129+
x: array
130+
input array.
131+
source: Union[int, Tuple[int, ...]]
132+
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 half-open interval ``[-N, N)``.
133+
destination: Union[int, Tuple[int, ...]]
134+
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 half-open interval ``[-N, N)``.
135+
136+
Returns
137+
-------
138+
out: array
139+
an array containing reordered axes. The returned array must have the same data type as ``x``.
140+
"""
141+
142+
117143
def permute_dims(x: array, /, axes: Tuple[int, ...]) -> array:
118144
"""
119145
Permutes the axes (dimensions) of an array ``x``.

0 commit comments

Comments
 (0)