From 3853605d26eaaa187168c0bbfd738a499c15e3fc Mon Sep 17 00:00:00 2001 From: Vahid Tavanashad Date: Wed, 23 Apr 2025 13:50:46 -0500 Subject: [PATCH] fix issues when running tests with all integer dtypes on GPU w/o support for fp64 --- dpnp/tests/test_linalg.py | 14 +++++--------- .../cupy/creation_tests/test_ranges.py | 2 +- .../third_party/cupy/math_tests/test_explog.py | 6 +++++- .../cupy/math_tests/test_trigonometric.py | 16 ++++++++++++++++ 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/dpnp/tests/test_linalg.py b/dpnp/tests/test_linalg.py index 600a1b658514..0a1e14716741 100644 --- a/dpnp/tests/test_linalg.py +++ b/dpnp/tests/test_linalg.py @@ -311,7 +311,7 @@ def test_basic(self, dtype, shape, p): result = dpnp.linalg.cond(ia, p=p) expected = numpy.linalg.cond(a, p=p) - assert_dtype_allclose(result, expected) + assert_dtype_allclose(result, expected, factor=16) @pytest.mark.parametrize( "p", [None, -dpnp.inf, -2, -1, 1, 2, dpnp.inf, "fro"] @@ -2841,10 +2841,8 @@ def get_tol(self, dtype): tol = 1e-06 if dtype in (dpnp.float32, dpnp.complex64): tol = 1e-03 - elif not has_support_aspect64() and dtype in ( - dpnp.int32, - dpnp.int64, - None, + elif not has_support_aspect64() and ( + dtype is None or dpnp.issubdtype(dtype, dpnp.integer) ): tol = 1e-03 self._tol = tol @@ -3019,10 +3017,8 @@ def get_tol(self, dtype): tol = 1e-06 if dtype in (dpnp.float32, dpnp.complex64): tol = 1e-03 - elif not has_support_aspect64() and dtype in ( - dpnp.int32, - dpnp.int64, - None, + elif not has_support_aspect64() and ( + dtype is None or dpnp.issubdtype(dtype, dpnp.integer) ): tol = 1e-03 self._tol = tol diff --git a/dpnp/tests/third_party/cupy/creation_tests/test_ranges.py b/dpnp/tests/third_party/cupy/creation_tests/test_ranges.py index 06b4ef8dc75a..9e8730b396c6 100644 --- a/dpnp/tests/third_party/cupy/creation_tests/test_ranges.py +++ b/dpnp/tests/third_party/cupy/creation_tests/test_ranges.py @@ -229,7 +229,7 @@ def test_linspace_mixed_start_stop2(self, xp, dtype_range, dtype_out): if xp.dtype(dtype_range).kind in "u": # to avoid overflow, limit `val` to be smaller # than xp.iinfo(dtype).max - if dtype_range == xp.uint8 or dtype_out == xp.uint8: + if dtype_range in [xp.uint8, xp.uint16] or dtype_out == xp.uint8: val = 125 else: val = 160 diff --git a/dpnp/tests/third_party/cupy/math_tests/test_explog.py b/dpnp/tests/third_party/cupy/math_tests/test_explog.py index a377b90e3b22..2d4b539d1fb4 100644 --- a/dpnp/tests/third_party/cupy/math_tests/test_explog.py +++ b/dpnp/tests/third_party/cupy/math_tests/test_explog.py @@ -16,8 +16,12 @@ def check_unary(self, name, xp, dtype, no_complex=False): a = testing.shaped_arange((2, 3), xp, dtype) return getattr(xp, name)(a) + # rtol=1e-3 is added for dpnp to pass the test when dtype is int8/unint8 + # for such a case, output dtype is float16 @testing.for_all_dtypes() - @testing.numpy_cupy_allclose(atol=1e-5, type_check=has_support_aspect64()) + @testing.numpy_cupy_allclose( + rtol=1e-3, atol=1e-5, type_check=has_support_aspect64() + ) def check_binary(self, name, xp, dtype, no_complex=False): if no_complex: if numpy.dtype(dtype).kind == "c": diff --git a/dpnp/tests/third_party/cupy/math_tests/test_trigonometric.py b/dpnp/tests/third_party/cupy/math_tests/test_trigonometric.py index 3579ddb7fe37..9bb8b67870c7 100644 --- a/dpnp/tests/third_party/cupy/math_tests/test_trigonometric.py +++ b/dpnp/tests/third_party/cupy/math_tests/test_trigonometric.py @@ -1,5 +1,7 @@ import unittest +import pytest + from dpnp.tests.helper import has_support_aspect64 from dpnp.tests.third_party.cupy import testing @@ -76,12 +78,26 @@ def test_unwrap_1dim_with_discont(self, xp, dtype): @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose(type_check=has_support_aspect64()) def test_unwrap_1dim_with_period(self, xp, dtype): + if not has_support_aspect64() and dtype in [xp.uint8, xp.uint16]: + # The unwrap function relies on the remainder function, and the + # result of remainder can vary significantly between float32 and + # float64. This discrepancy causes test failures when numpy uses + # float64 and dpnp uses float32, especially with uint8/uint16 + # dtypes where overflow occurs + pytest.skip("skipping due to large difference of result") a = testing.shaped_random((5,), xp, dtype) return xp.unwrap(a, period=1.2) @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose(type_check=has_support_aspect64()) def test_unwrap_1dim_with_discont_and_period(self, xp, dtype): + if not has_support_aspect64() and dtype in [xp.uint8, xp.uint16]: + # The unwrap function relies on the remainder function, and the + # result of remainder can vary significantly between float32 and + # float64. This discrepancy causes test failures when numpy uses + # float64 and dpnp uses float32, especially with uint8/uint16 + # dtypes where overflow occurs + pytest.skip("skipping due to large difference of result") a = testing.shaped_random((5,), xp, dtype) return xp.unwrap(a, discont=1.0, period=1.2)