Skip to content

fix issues when running tests with all integer dtypes on GPU w/o support for fp64 #2430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions dpnp/tests/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion dpnp/tests/third_party/cupy/math_tests/test_explog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
16 changes: 16 additions & 0 deletions dpnp/tests/third_party/cupy/math_tests/test_trigonometric.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import unittest

import pytest

from dpnp.tests.helper import has_support_aspect64
from dpnp.tests.third_party.cupy import testing

Expand Down Expand Up @@ -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)

Expand Down
Loading