Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specification for moving array axes to new positions #656

Merged
merged 5 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/draft/API_specification/manipulation_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Objects in API
concat
expand_dims
flip
moveaxis
permute_dims
reshape
roll
Expand Down
26 changes: 26 additions & 0 deletions src/array_api_stubs/_draft/manipulation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"concat",
"expand_dims",
"flip",
"moveaxis",
"permute_dims",
"reshape",
"roll",
Expand Down Expand Up @@ -114,6 +115,31 @@ def flip(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None) ->
"""


def moveaxis(
x: array,
source: Union[int, Tuple[int, ...]],
destination: Union[int, Tuple[int, ...]],
/,
) -> array:
"""
Moves array axes (dimensions) to new positions, while leaving other axes in their original positions.

Parameters
----------
x: array
input array.
source: Union[int, Tuple[int, ...]]
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)``.
destination: Union[int, Tuple[int, ...]]
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)``.

Returns
-------
out: array
an array containing reordered axes. The returned array must have the same data type as ``x``.
"""


def permute_dims(x: array, /, axes: Tuple[int, ...]) -> array:
"""
Permutes the axes (dimensions) of an array ``x``.
Expand Down