@@ -162,7 +162,19 @@ def __array__(self, dtype: None | np.dtype[Any] = None, copy: None | bool = None
162
162
if _allow_array :
163
163
if self ._device != CPU_DEVICE :
164
164
raise RuntimeError (f"Can not convert array on the '{ self ._device } ' device to a Numpy array." )
165
- return np .asarray (self ._array , dtype = dtype , copy = copy )
165
+ # copy keyword is new in 2.0.0; for older versions don't use it
166
+ # retry without that keyword.
167
+ if np .__version__ [0 ] < '2' :
168
+ return np .asarray (self ._array , dtype = dtype )
169
+ elif np .__version__ .startswith ('2.0.0-dev0' ):
170
+ # Handle dev version for which we can't know based on version
171
+ # number whether or not the copy keyword is supported.
172
+ try :
173
+ return np .asarray (self ._array , dtype = dtype , copy = copy )
174
+ except TypeError :
175
+ return np .asarray (self ._array , dtype = dtype )
176
+ else :
177
+ return np .asarray (self ._array , dtype = dtype , copy = copy )
166
178
raise ValueError ("Conversion from an array_api_strict array to a NumPy ndarray is not supported" )
167
179
168
180
# These are various helper functions to make the array behavior match the
@@ -574,14 +586,24 @@ def __dlpack__(
574
586
if copy is not _default :
575
587
raise ValueError ("The copy argument to __dlpack__ requires at least version 2023.12 of the array API" )
576
588
577
- kwargs = {'stream' : stream }
578
- if max_version is not _default :
579
- kwargs ['max_version' ] = max_version
580
- if dl_device is not _default :
581
- kwargs ['dl_device' ] = dl_device
582
- if copy is not _default :
583
- kwargs ['copy' ] = copy
584
- return self ._array .__dlpack__ (** kwargs )
589
+ if np .__version__ [0 ] < '2.1' :
590
+ if max_version not in [_default , None ]:
591
+ raise NotImplementedError ("The max_version argument to __dlpack__ is not yet implemented" )
592
+ if dl_device not in [_default , None ]:
593
+ raise NotImplementedError ("The device argument to __dlpack__ is not yet implemented" )
594
+ if copy not in [_default , None ]:
595
+ raise NotImplementedError ("The copy argument to __dlpack__ is not yet implemented" )
596
+
597
+ return self ._array .__dlpack__ (stream = stream )
598
+ else :
599
+ kwargs = {'stream' : stream }
600
+ if max_version is not _default :
601
+ kwargs ['max_version' ] = max_version
602
+ if dl_device is not _default :
603
+ kwargs ['dl_device' ] = dl_device
604
+ if copy is not _default :
605
+ kwargs ['copy' ] = copy
606
+ return self ._array .__dlpack__ (** kwargs )
585
607
586
608
def __dlpack_device__ (self : Array , / ) -> Tuple [IntEnum , int ]:
587
609
"""
0 commit comments