11from enum import Enum
22
3- from hypothesis import given , strategies as st
3+ from hypothesis import given , strategies as st , assume
44from . import _array_module as xp
55from . import pytest_helpers as ph
66from . import hypothesis_helpers as hh
@@ -29,8 +29,9 @@ def _compatible_devices(devices):
2929 # cf https://github.com/data-apis/array-api-compat/issues/337 and
3030 # https://github.com/cupy/cupy/issues/9848
3131 # Luckily, CuPy only supports CUDA devices, and they are all compatible.
32- compatible_ = []
32+ dtype_compatible = []
3333 for device in devices :
34+ compatible_ = []
3435 x = xp .empty (2 , device = device )
3536 try :
3637 x .__dlpack_device__ ()
@@ -41,7 +42,14 @@ def _compatible_devices(devices):
4142 else :
4243 # no exception => device is compatible
4344 compatible_ .append (device )
44- return compatible_
45+
46+
47+ dtype_compatible_ = [
48+ device for device in compatible_
49+ if x .dtype in xp .__array_namespace_info__ ().dtypes (device = device )
50+ ]
51+
52+ return dtype_compatible
4553
4654
4755@given (dtype = hh .all_dtypes , data = st .data ())
@@ -110,6 +118,9 @@ def test_from_dlpack(x, copy_kw, data):
110118 )
111119 tgt_device = tgt_device_kw ['device' ] if tgt_device_kw else None
112120
121+ # the target device may or may not support x.dtype
122+ ### assume(x.dtype in xp.__array_namespace_info__().dtypes(device=tgt_device))
123+
113124 repro_snippet = ph .format_snippet (
114125 f"y = from_dlpack({ x !r} , **tgt_device_kw, **copy_kw) with { tgt_device_kw = } and { copy_kw = } "
115126 )
0 commit comments