Skip to content

Commit 19205fc

Browse files
committed
Extend a number of supported types to all numeric dtypes in umath tests
1 parent 563108e commit 19205fc

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

dpnp/tests/helper.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,14 @@ def is_cuda_device(device=None):
346346
return dev.backend == dpctl.backend_type.cuda
347347

348348

349+
def is_gpu_device(device=None):
350+
"""
351+
Return True if a test is running on GPU device, False otherwise.
352+
"""
353+
dev = dpctl.select_default_device() if device is None else device
354+
return dev.has_aspect_gpu
355+
356+
349357
def is_win_platform():
350358
"""
351359
Return True if a test is running on Windows OS, False otherwise.

dpnp/tests/skipped_tests.tbl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,3 @@ tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.
1010
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.asarray(x).astype(dpnp.int8)]
1111

1212
tests/third_party/intel/test_zero_copy_test1.py::test_dpnp_interaction_with_dpctl_memory
13-
14-
tests/test_umath.py::test_umaths[('divmod', 'ii')]
15-
tests/test_umath.py::test_umaths[('divmod', 'll')]
16-
tests/test_umath.py::test_umaths[('divmod', 'ff')]
17-
tests/test_umath.py::test_umaths[('divmod', 'dd')]
18-
tests/test_umath.py::test_umaths[('frexp', 'f')]
19-
tests/test_umath.py::test_umaths[('frexp', 'd')]

dpnp/tests/skipped_tests_gpu.tbl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,4 @@ tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: (dpnp
1717
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.asarray([(i, i) for i in x], [("a", object), ("b", dpnp.int32)])]]
1818
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.asarray(x).astype(dpnp.int8)]
1919

20-
tests/test_umath.py::test_umaths[('divmod', 'ii')]
21-
tests/test_umath.py::test_umaths[('divmod', 'll')]
22-
tests/test_umath.py::test_umaths[('divmod', 'ff')]
23-
tests/test_umath.py::test_umaths[('divmod', 'dd')]
24-
tests/test_umath.py::test_umaths[('floor_divide', 'ff')]
25-
tests/test_umath.py::test_umaths[('frexp', 'f')]
26-
tests/test_umath.py::test_umaths[('frexp', 'd')]
27-
2820
tests/third_party/intel/test_zero_copy_test1.py::test_dpnp_interaction_with_dpctl_memory

dpnp/tests/skipped_tests_gpu_no_fp64.tbl

Lines changed: 0 additions & 1 deletion
This file was deleted.

dpnp/tests/test_umath.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,18 @@
1919
get_float_dtypes,
2020
has_support_aspect16,
2121
has_support_aspect64,
22+
is_gpu_device,
2223
)
2324

2425
# full list of umaths
2526
umaths = [i for i in dir(numpy) if isinstance(getattr(numpy, i), numpy.ufunc)]
2627

27-
types = {
28-
"d": numpy.float64,
29-
"f": numpy.float32,
30-
"l": numpy.int64,
31-
"i": numpy.int32,
32-
}
33-
34-
supported_types = "fli"
28+
supported_types = "?bBhHiIlLkK"
29+
if has_support_aspect16():
30+
supported_types += "e"
31+
supported_types += "fF"
3532
if has_support_aspect64():
36-
supported_types += "d"
33+
supported_types += "dD"
3734

3835

3936
def check_types(args_str):
@@ -54,7 +51,7 @@ def shaped_arange(shape, xp=numpy, dtype=numpy.float32):
5451
def get_args(args_str, sh, xp=numpy):
5552
args = []
5653
for s in args_str:
57-
args.append(shaped_arange(shape=sh, xp=xp, dtype=types[s]))
54+
args.append(shaped_arange(shape=sh, xp=xp, dtype=numpy.dtype(s)))
5855
return tuple(args)
5956

6057

@@ -74,6 +71,7 @@ def get_id(val):
7471
return val.__str__()
7572

7673

74+
@pytest.mark.filterwarnings("ignore:overflow encountered:RuntimeWarning")
7775
@pytest.mark.usefixtures("suppress_divide_invalid_numpy_warnings")
7876
@pytest.mark.parametrize("test_cases", test_cases, ids=get_id)
7977
def test_umaths(test_cases):
@@ -90,7 +88,7 @@ def test_umaths(test_cases):
9088
iargs = get_args(args_str, sh, xp=dpnp)
9189

9290
if umath == "reciprocal":
93-
if args[0].dtype in [numpy.int32, numpy.int64]:
91+
if numpy.issubdtype(args[0].dtype, numpy.integer):
9492
pytest.skip(
9593
"For integer input array, numpy.reciprocal returns zero."
9694
)
@@ -101,11 +99,21 @@ def test_umaths(test_cases):
10199
and numpy.dtype("l") != numpy.int64
102100
):
103101
pytest.skip("numpy.ldexp doesn't have a loop for the input types")
102+
elif (
103+
umath == "floor_divide"
104+
and args[0].dtype in [dpnp.float16, dpnp.float32]
105+
and is_gpu_device()
106+
):
107+
pytest.skip("dpctl-1652")
108+
elif umath in ["divmod", "frexp"]:
109+
pytest.skip("Not implemented umath")
110+
elif umath == "modf" and args[0].dtype == dpnp.float16:
111+
pytest.skip("dpnp.modf is not supported with dpnp.float16")
104112

105113
expected = getattr(numpy, umath)(*args)
106114
result = getattr(dpnp, umath)(*iargs)
107-
108-
assert_allclose(result, expected, rtol=1e-6)
115+
for x, y in zip(result, expected):
116+
assert_dtype_allclose(x, y)
109117

110118

111119
def _get_output_data_type(dtype):

0 commit comments

Comments
 (0)