Skip to content

Commit 6a81e55

Browse files
authored
fix issues when running tests with all integer dtypes on GPU w/o support for fp64 (#2430)
The following tests fails when running the test suite with all integer dtypes included on a GPU device that does not support fp64. FAILED dpnp/tests/test_linalg.py::TestCond::test_basic FAILED dpnp/tests/test_linalg.py::TestSvd::test_svd FAILED dpnp/tests/test_linalg.py::TestPinv::test_pinv FAILED dpnp/tests/third_party/cupy/creation_tests/test_ranges.py::TestRanges::test_linspace_mixed_start_stop2 FAILED dpnp/tests/third_party/cupy/math_tests/test_explog.py::TestExplog::test_logaddexp2 FAILED dpnp/tests/third_party/cupy/math_tests/test_trigonometric.py::TestUnwrap::test_unwrap_1dim_with_discont_and_period FAILED dpnp/tests/third_party/cupy/math_tests/test_trigonometric.py::TestUnwrap::test_unwrap_1dim_with_period This PR fixes them all.
1 parent 4d2be8c commit 6a81e55

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

dpnp/tests/test_linalg.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def test_basic(self, dtype, shape, p):
311311

312312
result = dpnp.linalg.cond(ia, p=p)
313313
expected = numpy.linalg.cond(a, p=p)
314-
assert_dtype_allclose(result, expected)
314+
assert_dtype_allclose(result, expected, factor=16)
315315

316316
@pytest.mark.parametrize(
317317
"p", [None, -dpnp.inf, -2, -1, 1, 2, dpnp.inf, "fro"]
@@ -2841,10 +2841,8 @@ def get_tol(self, dtype):
28412841
tol = 1e-06
28422842
if dtype in (dpnp.float32, dpnp.complex64):
28432843
tol = 1e-03
2844-
elif not has_support_aspect64() and dtype in (
2845-
dpnp.int32,
2846-
dpnp.int64,
2847-
None,
2844+
elif not has_support_aspect64() and (
2845+
dtype is None or dpnp.issubdtype(dtype, dpnp.integer)
28482846
):
28492847
tol = 1e-03
28502848
self._tol = tol
@@ -3019,10 +3017,8 @@ def get_tol(self, dtype):
30193017
tol = 1e-06
30203018
if dtype in (dpnp.float32, dpnp.complex64):
30213019
tol = 1e-03
3022-
elif not has_support_aspect64() and dtype in (
3023-
dpnp.int32,
3024-
dpnp.int64,
3025-
None,
3020+
elif not has_support_aspect64() and (
3021+
dtype is None or dpnp.issubdtype(dtype, dpnp.integer)
30263022
):
30273023
tol = 1e-03
30283024
self._tol = tol

dpnp/tests/third_party/cupy/creation_tests/test_ranges.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def test_linspace_mixed_start_stop2(self, xp, dtype_range, dtype_out):
229229
if xp.dtype(dtype_range).kind in "u":
230230
# to avoid overflow, limit `val` to be smaller
231231
# than xp.iinfo(dtype).max
232-
if dtype_range == xp.uint8 or dtype_out == xp.uint8:
232+
if dtype_range in [xp.uint8, xp.uint16] or dtype_out == xp.uint8:
233233
val = 125
234234
else:
235235
val = 160

dpnp/tests/third_party/cupy/math_tests/test_explog.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ def check_unary(self, name, xp, dtype, no_complex=False):
1616
a = testing.shaped_arange((2, 3), xp, dtype)
1717
return getattr(xp, name)(a)
1818

19+
# rtol=1e-3 is added for dpnp to pass the test when dtype is int8/unint8
20+
# for such a case, output dtype is float16
1921
@testing.for_all_dtypes()
20-
@testing.numpy_cupy_allclose(atol=1e-5, type_check=has_support_aspect64())
22+
@testing.numpy_cupy_allclose(
23+
rtol=1e-3, atol=1e-5, type_check=has_support_aspect64()
24+
)
2125
def check_binary(self, name, xp, dtype, no_complex=False):
2226
if no_complex:
2327
if numpy.dtype(dtype).kind == "c":

dpnp/tests/third_party/cupy/math_tests/test_trigonometric.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import unittest
22

3+
import pytest
4+
35
from dpnp.tests.helper import has_support_aspect64
46
from dpnp.tests.third_party.cupy import testing
57

@@ -76,12 +78,26 @@ def test_unwrap_1dim_with_discont(self, xp, dtype):
7678
@testing.for_all_dtypes(no_complex=True)
7779
@testing.numpy_cupy_allclose(type_check=has_support_aspect64())
7880
def test_unwrap_1dim_with_period(self, xp, dtype):
81+
if not has_support_aspect64() and dtype in [xp.uint8, xp.uint16]:
82+
# The unwrap function relies on the remainder function, and the
83+
# result of remainder can vary significantly between float32 and
84+
# float64. This discrepancy causes test failures when numpy uses
85+
# float64 and dpnp uses float32, especially with uint8/uint16
86+
# dtypes where overflow occurs
87+
pytest.skip("skipping due to large difference of result")
7988
a = testing.shaped_random((5,), xp, dtype)
8089
return xp.unwrap(a, period=1.2)
8190

8291
@testing.for_all_dtypes(no_complex=True)
8392
@testing.numpy_cupy_allclose(type_check=has_support_aspect64())
8493
def test_unwrap_1dim_with_discont_and_period(self, xp, dtype):
94+
if not has_support_aspect64() and dtype in [xp.uint8, xp.uint16]:
95+
# The unwrap function relies on the remainder function, and the
96+
# result of remainder can vary significantly between float32 and
97+
# float64. This discrepancy causes test failures when numpy uses
98+
# float64 and dpnp uses float32, especially with uint8/uint16
99+
# dtypes where overflow occurs
100+
pytest.skip("skipping due to large difference of result")
85101
a = testing.shaped_random((5,), xp, dtype)
86102
return xp.unwrap(a, discont=1.0, period=1.2)
87103

0 commit comments

Comments
 (0)