Skip to content

Commit a015842

Browse files
committed
Skip device-unsupported dtypes in for_dtypes_combination
for_dtypes already skips dtypes the default device cannot represent natively (float64/complex128 without fp64 support, float16 without fp16 support), but for_dtypes_combination did not, so combination tests could attempt to allocate an unsupported-dtype array and fail with a device ValueError instead of exercising the intended code path. This surfaced in the new bincount empty-with-weights test. Factor the per-dtype check into a shared helper and apply it in both decorators so combination tests skip such dtypes consistently.
1 parent e5966bc commit a015842

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

dpnp/tests/third_party/cupy/testing/_loops.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,16 @@ def test_func(*args, **kw):
991991
return decorator
992992

993993

994+
def _dtype_supported_by_default_device(dtype):
995+
"""Skip dtypes the default device cannot represent natively."""
996+
dtype = numpy.dtype(dtype).type
997+
if dtype in (numpy.float64, numpy.complex128):
998+
return has_support_aspect64()
999+
if dtype == numpy.float16:
1000+
return select_default_device().has_aspect_fp16
1001+
return True
1002+
1003+
9941004
def for_dtypes(dtypes, name="dtype", xfail_dtypes=None):
9951005
"""Decorator for parameterized dtype test.
9961006
@@ -1008,16 +1018,7 @@ def decorator(impl):
10081018
@_wraps_partial(impl, name)
10091019
def test_func(*args, **kw):
10101020
for dtype in dtypes:
1011-
if (
1012-
numpy.dtype(dtype).type in (numpy.float64, numpy.complex128)
1013-
and not has_support_aspect64()
1014-
):
1015-
continue
1016-
1017-
if (
1018-
numpy.dtype(dtype).type == numpy.float16
1019-
and not select_default_device().has_aspect_fp16
1020-
):
1021+
if not _dtype_supported_by_default_device(dtype):
10211022
continue
10221023

10231024
try:
@@ -1331,6 +1332,12 @@ def decorator(impl):
13311332
@_wraps_partial(impl, *names)
13321333
def test_func(*args, **kw):
13331334
for dtypes in combination:
1335+
if not all(
1336+
_dtype_supported_by_default_device(dtype)
1337+
for dtype in dtypes.values()
1338+
):
1339+
continue
1340+
13341341
kw_copy = kw.copy()
13351342
kw_copy.update(dtypes)
13361343

0 commit comments

Comments
 (0)