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

chore: use xp.take_along_axis if Array API version >=2024.12 #4406

Merged
merged 1 commit into from
Nov 23, 2024
Merged
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
6 changes: 6 additions & 0 deletions deepmd/dpmodel/array_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"""Utilities for the array API."""

import array_api_compat
from packaging.version import (
Version,
)


def support_array_api(version: str) -> callable:
Expand Down Expand Up @@ -45,6 +48,9 @@

def xp_take_along_axis(arr, indices, axis):
xp = array_api_compat.array_namespace(arr)
if Version(xp.__array_api_version__) >= Version("2024.12"):
# see: https://github.com/data-apis/array-api-strict/blob/d086c619a58f35c38240592ef994aa19ca7beebc/array_api_strict/_indexing_functions.py#L30-L39
return xp.take_along_axis(arr, indices, axis=axis)

Check warning on line 53 in deepmd/dpmodel/array_api.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/array_api.py#L53

Added line #L53 was not covered by tests
njzjz marked this conversation as resolved.
Show resolved Hide resolved
arr = xp_swapaxes(arr, axis, -1)
indices = xp_swapaxes(indices, axis, -1)

Expand Down