Skip to content

BUG: take_along_axis: numpy requires an axis #317

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion array_api_compat/cupy/_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ def count_nonzero(
return result


# take_along_axis: axis defaults to -1 but in cupy (and numpy) axis is a required arg
def take_along_axis(x: Array, indices: Array, /, *, axis: int = -1):
return cp.take_along_axis(x, indices, axis=axis)


# These functions are completely new here. If the library already has them
# (i.e., numpy 2.0), use the library version instead of our wrapper.
if hasattr(cp, 'vecdot'):
Expand All @@ -159,6 +164,7 @@ def count_nonzero(
'acos', 'acosh', 'asin', 'asinh', 'atan',
'atan2', 'atanh', 'bitwise_left_shift',
'bitwise_invert', 'bitwise_right_shift',
'bool', 'concat', 'count_nonzero', 'pow', 'sign']
'bool', 'concat', 'count_nonzero', 'pow', 'sign',
'take_along_axis']

_all_ignore = ['cp', 'get_xp']
6 changes: 6 additions & 0 deletions array_api_compat/numpy/_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ def count_nonzero(
return result


# take_along_axis: axis defaults to -1 but in numpy axis is a required arg
def take_along_axis(x: Array, indices: Array, /, *, axis: int = -1):
return np.take_along_axis(x, indices, axis=axis)


# These functions are completely new here. If the library already has them
# (i.e., numpy 2.0), use the library version instead of our wrapper.
if hasattr(np, "vecdot"):
Expand Down Expand Up @@ -175,6 +180,7 @@ def count_nonzero(
"concat",
"count_nonzero",
"pow",
"take_along_axis"
]
__all__ += _aliases.__all__
_all_ignore = ["np", "get_xp"]
Expand Down
3 changes: 3 additions & 0 deletions dask-xfails.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ array_api_tests/test_creation_functions.py::test_linspace
# Shape mismatch
array_api_tests/test_indexing_functions.py::test_take

# missing `take_along_axis`, https://github.com/dask/dask/issues/3663
array_api_tests/test_indexing_functions.py::test_take_along_axis

# Array methods and attributes not already on da.Array cannot be wrapped
array_api_tests/test_has_names.py::test_has_names[array_method-__array_namespace__]
array_api_tests/test_has_names.py::test_has_names[array_method-to_device]
Expand Down
Loading