Skip to content

Commit 771f9b2

Browse files
authored
Extend a number of supported types to all numeric dtypes in umath tests (#2389)
Previously the umath functions were filtered out to to test only int32, int64, float32, float64 (if supported) in `test_umaths` test. But currently all numeric dtypes in supported by dpnp. Thus it is proposed to enable all numeric dtypes there.
1 parent eb8ebf8 commit 771f9b2

File tree

7 files changed

+49
-33
lines changed

7 files changed

+49
-33
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_cuda.tbl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
tests/test_arithmetic.py::TestArithmetic::test_modf_part1
55
tests/test_arithmetic.py::TestArithmetic::test_modf_part2
66
tests/test_sycl_queue.py::test_modf[cuda:gpu:0]
7-
tests/test_umath.py::test_umaths[('modf', 'f')]
8-
tests/test_umath.py::test_umaths[('modf', 'd')]
97
tests/third_party/cupy/math_tests/test_arithmetic.py::TestArithmeticModf::test_modf
108

119
# random

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_random_state.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
from dpnp.dpnp_array import dpnp_array
1616
from dpnp.random import RandomState
1717

18-
from .helper import assert_dtype_allclose, get_array, is_cpu_device
18+
from .helper import (
19+
assert_dtype_allclose,
20+
get_array,
21+
is_cpu_device,
22+
is_gpu_device,
23+
)
1924

2025
# aspects of default device:
2126
_def_device = dpctl.SyclQueue().sycl_device
@@ -688,7 +693,7 @@ def test_scalar(self, func):
688693
],
689694
)
690695
def test_array_range(self, seed):
691-
if not is_cpu_device():
696+
if is_gpu_device():
692697
pytest.skip("seed as a scalar is only supported on GPU")
693698

694699
size = 15

dpnp/tests/test_umath.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010

1111
import dpnp
12+
import dpnp.backend.extensions.vm._vm_impl as vmi
1213
from dpnp.dpnp_utils import map_dtype_to_device
1314

1415
from .helper import (
@@ -20,21 +21,19 @@
2021
get_float_dtypes,
2122
has_support_aspect16,
2223
has_support_aspect64,
24+
is_cuda_device,
25+
is_gpu_device,
2326
)
2427

2528
# full list of umaths
2629
umaths = [i for i in dir(numpy) if isinstance(getattr(numpy, i), numpy.ufunc)]
2730

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

3938

4039
def check_types(args_str):
@@ -55,7 +54,7 @@ def shaped_arange(shape, xp=numpy, dtype=numpy.float32):
5554
def get_args(args_str, sh, xp=numpy):
5655
args = []
5756
for s in args_str:
58-
args.append(shaped_arange(shape=sh, xp=xp, dtype=types[s]))
57+
args.append(shaped_arange(shape=sh, xp=xp, dtype=numpy.dtype(s)))
5958
return tuple(args)
6059

6160

@@ -75,6 +74,7 @@ def get_id(val):
7574
return val.__str__()
7675

7776

77+
@pytest.mark.filterwarnings("ignore:overflow encountered:RuntimeWarning")
7878
@pytest.mark.usefixtures("suppress_divide_invalid_numpy_warnings")
7979
@pytest.mark.parametrize("test_cases", test_cases, ids=get_id)
8080
def test_umaths(test_cases):
@@ -91,7 +91,7 @@ def test_umaths(test_cases):
9191
iargs = get_args(args_str, sh, xp=dpnp)
9292

9393
if umath == "reciprocal":
94-
if args[0].dtype in [numpy.int32, numpy.int64]:
94+
if numpy.issubdtype(args[0].dtype, numpy.integer):
9595
pytest.skip(
9696
"For integer input array, numpy.reciprocal returns zero."
9797
)
@@ -102,11 +102,32 @@ def test_umaths(test_cases):
102102
and numpy.dtype("l") != numpy.int64
103103
):
104104
pytest.skip("numpy.ldexp doesn't have a loop for the input types")
105+
elif (
106+
umath == "floor_divide"
107+
and args[0].dtype in [dpnp.float16, dpnp.float32]
108+
and is_gpu_device()
109+
):
110+
pytest.skip("dpctl-1652")
111+
elif umath in ["ceil", "floor", "trunc"] and args[0].dtype == dpnp.bool:
112+
pytest.skip("dpctl-2030")
113+
elif (
114+
umath == "tan"
115+
and dpnp.issubdtype(args[0].dtype, dpnp.complexfloating)
116+
and not (vmi._is_available() and has_support_aspect64())
117+
):
118+
pytest.skip("dpctl-2031")
119+
elif umath in ["divmod", "frexp"]:
120+
pytest.skip("Not implemented umath")
121+
elif umath == "modf":
122+
if args[0].dtype == dpnp.float16:
123+
pytest.skip("dpnp.modf is not supported with dpnp.float16")
124+
elif is_cuda_device():
125+
pytest.skip("dpnp.modf is not supported on CUDA device")
105126

106127
expected = getattr(numpy, umath)(*args)
107128
result = getattr(dpnp, umath)(*iargs)
108-
109-
assert_allclose(result, expected, rtol=1e-6)
129+
for x, y in zip(result, expected):
130+
assert_dtype_allclose(x, y)
110131

111132

112133
class TestArctan2:

0 commit comments

Comments
 (0)