Skip to content

Commit 845382d

Browse files
Adapt from_dlpack to NumPy 2.1.0 behavior
NumPy 2.1.0 supports DLPack 1.0 now, and raises ValueError if __dlpack__ method gets unsupport dl_device value. Function from_dlpack now handles ValueError, the same way as it handles BufferError
1 parent 6e81050 commit 845382d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

dpctl/tensor/_dlpack.pyx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,9 +1083,10 @@ def from_dlpack(x, /, *, device=None, copy=None):
10831083
except TypeError:
10841084
# exporter does not support max_version keyword
10851085
got_type_error = True
1086-
except (BufferError, NotImplementedError):
1087-
# Either dl_device, or copy can be satisfied
1086+
except (BufferError, NotImplementedError, ValueError) as e:
1087+
# Either dl_device, or copy cannot be satisfied
10881088
got_buffer_error = True
1089+
saved_exception = e
10891090
except Exception as e:
10901091
got_other_error = True
10911092
saved_exception = e
@@ -1144,6 +1145,8 @@ def from_dlpack(x, /, *, device=None, copy=None):
11441145
raise BufferError(
11451146
"Importing data via DLPack requires copying, but copy=False was provided"
11461147
)
1148+
if dl_device is None:
1149+
raise saved_exception
11471150
# must copy via host
11481151
if dl_device[0] != device_OneAPI:
11491152
raise BufferError(f"Can not import to requested device {dl_device}")

0 commit comments

Comments
 (0)