Skip to content

Commit

Permalink
chore: use xp.take_along_axis is Array API version >=2024.12
Browse files Browse the repository at this point in the history
  • Loading branch information
njzjz committed Nov 22, 2024
1 parent 7bd2e5a commit 2bf4869
Showing 1 changed file with 6 additions and 0 deletions.
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_swapaxes(a, axis1, axis2):

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
arr = xp_swapaxes(arr, axis, -1)
indices = xp_swapaxes(indices, axis, -1)

Expand Down

0 comments on commit 2bf4869

Please sign in to comment.