Skip to content

Allow __dlpack__ to work with newer versions of NumPy #86

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

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 10 additions & 9 deletions array_api_strict/_array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,15 +586,16 @@ def __dlpack__(
if copy is not _default:
raise ValueError("The copy argument to __dlpack__ requires at least version 2023.12 of the array API")

# Going to wait for upstream numpy support
if max_version not in [_default, None]:
raise NotImplementedError("The max_version argument to __dlpack__ is not yet implemented")
if dl_device not in [_default, None]:
raise NotImplementedError("The device argument to __dlpack__ is not yet implemented")
if copy not in [_default, None]:
raise NotImplementedError("The copy argument to __dlpack__ is not yet implemented")

return self._array.__dlpack__(stream=stream)
if np.__version__ < '2.1':
if max_version not in [_default, None]:
raise NotImplementedError("The max_version argument to __dlpack__ is not yet implemented")
if dl_device not in [_default, None]:
raise NotImplementedError("The device argument to __dlpack__ is not yet implemented")
if copy not in [_default, None]:
raise NotImplementedError("The copy argument to __dlpack__ is not yet implemented")

return self._array.__dlpack__(stream=stream)
return self._array.__dlpack__(stream=stream, max_version=max_version, dl_device=dl_device, copy=copy)

def __dlpack_device__(self: Array, /) -> Tuple[IntEnum, int]:
"""
Expand Down
2 changes: 1 addition & 1 deletion array_api_strict/tests/test_array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def dlpack_2023_12(api_version):
a.__dlpack__()


exception = NotImplementedError if api_version >= '2023.12' else ValueError
exception = NotImplementedError if api_version >= '2023.12' and np.__version__ < '2.1' else ValueError
pytest.raises(exception, lambda:
a.__dlpack__(dl_device=CPU_DEVICE))
pytest.raises(exception, lambda:
Expand Down
Loading