Skip to content

BUG: from_dlpack: fix default device #108

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 1 commit into from
Dec 11, 2024
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
2 changes: 2 additions & 0 deletions array_api_strict/_creation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ def from_dlpack(
# Going to wait for upstream numpy support
if device is not _default:
_check_device(device)
else:
device = None
if copy not in [_default, None]:
raise NotImplementedError("The copy argument to from_dlpack is not yet implemented")

Expand Down
7 changes: 7 additions & 0 deletions array_api_strict/tests/test_creation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,10 @@ def from_dlpack_2023_12(api_version):
pytest.raises(exception, lambda: from_dlpack(capsule, copy=False))
pytest.raises(exception, lambda: from_dlpack(capsule, copy=True))
pytest.raises(exception, lambda: from_dlpack(capsule, copy=None))


def test_from_dlpack_default_device():
x = asarray([1, 2, 3])
y = from_dlpack(x)
z = from_dlpack(np.asarray([1, 2, 3]))
assert x.device == y.device == z.device == CPU_DEVICE
Loading