From 3c472fd64faa98e733ff99e3c94ba08056907c4a Mon Sep 17 00:00:00 2001 From: shbiswas834 Date: Fri, 1 Nov 2024 03:24:16 +0000 Subject: [PATCH 1/6] Changing polyval test tolerance for Assertion error and reverting PR #63 --- cupy/testing/_loops.py | 43 ++++++++++--------- tests/cupy_tests/lib_tests/test_polynomial.py | 2 +- 2 files changed, 23 insertions(+), 22 deletions(-) mode change 100644 => 100755 cupy/testing/_loops.py mode change 100644 => 100755 tests/cupy_tests/lib_tests/test_polynomial.py diff --git a/cupy/testing/_loops.py b/cupy/testing/_loops.py old mode 100644 new mode 100755 index b231771c81a..396377f43fe --- a/cupy/testing/_loops.py +++ b/cupy/testing/_loops.py @@ -14,7 +14,7 @@ from cupy.testing import _parameterized import cupyx import cupyx.scipy.sparse -from cupy_backends.cuda.api import runtime +# from cupy_backends.cuda.api import runtime from cupy.testing._pytest_impl import is_available @@ -511,26 +511,27 @@ def numpy_cupy_allclose(rtol=1e-7, atol=0, err_msg='', verbose=True, def check_func(c, n): rtol1, atol1 = _resolve_tolerance(type_check, c, rtol, atol) - try: - _array.assert_allclose(c, n, rtol1, atol1, err_msg, verbose) - except AssertionError as e: - import numbers - if runtime.is_hip and type(n) is numpy.ndarray and \ - (issubclass(n.dtype.type, numbers.Real) or - issubclass(n.dtype.type, numbers.Complex)): - npc = cupy.asnumpy(c) - diff = numpy.linalg.norm(npc - n, numpy.inf) - norm = numpy.linalg.norm(npc, numpy.inf) - if numpy.any(npc) and numpy.any(n): - min_positive = numpy.finfo(n.dtype).tiny - if (abs(npc) < min_positive).any() or \ - (abs(n) < min_positive).any(): - # Denormal case handling - assert diff <= (atol1 + rtol1 * norm) - else: - raise e - else: - raise e + _array.assert_allclose(c, n, rtol1, atol1, err_msg, verbose) + # try: + # _array.assert_allclose(c, n, rtol1, atol1, err_msg, verbose) + # except AssertionError as e: + # import numbers + # if runtime.is_hip and type(n) is numpy.ndarray and \ + # (issubclass(n.dtype.type, numbers.Real) or + # issubclass(n.dtype.type, numbers.Complex)): + # npc = cupy.asnumpy(c) + # diff = numpy.linalg.norm(npc - n, numpy.inf) + # norm = numpy.linalg.norm(npc, numpy.inf) + # if numpy.any(npc) and numpy.any(n): + # min_positive = numpy.finfo(n.dtype).tiny + # if (abs(npc) < min_positive).any() or \ + # (abs(n) < min_positive).any(): + # # Denormal case handling + # assert diff <= (atol1 + rtol1 * norm) + # else: + # raise e + # else: + # raise e return _make_decorator(check_func, name, type_check, contiguous_check, accept_error, sp_name, scipy_name, _check_sparse_format) diff --git a/tests/cupy_tests/lib_tests/test_polynomial.py b/tests/cupy_tests/lib_tests/test_polynomial.py old mode 100644 new mode 100755 index ed0cab9a453..effa2fd2002 --- a/tests/cupy_tests/lib_tests/test_polynomial.py +++ b/tests/cupy_tests/lib_tests/test_polynomial.py @@ -694,7 +694,7 @@ def test_polyfit_weighted_diff_types(self, xp, dtype1, dtype2, dtype3): class TestPolyval(Poly1dTestBase): @testing.for_all_dtypes() - @testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-2, 'default': 1e-3}) + @testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-2, 'default': 2e-3}) def test_polyval(self, xp, dtype): a1 = self._get_input(xp, self.type_l, dtype, size=5) a2 = self._get_input(xp, self.type_r, dtype, size=5) From d102ee647feddca7ec06b6e22401bb338787fd2c Mon Sep 17 00:00:00 2001 From: shbiswas834 Date: Fri, 1 Nov 2024 03:26:19 +0000 Subject: [PATCH 2/6] removed comments --- cupy/testing/_loops.py | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/cupy/testing/_loops.py b/cupy/testing/_loops.py index 396377f43fe..821be46d173 100755 --- a/cupy/testing/_loops.py +++ b/cupy/testing/_loops.py @@ -512,26 +512,7 @@ def numpy_cupy_allclose(rtol=1e-7, atol=0, err_msg='', verbose=True, def check_func(c, n): rtol1, atol1 = _resolve_tolerance(type_check, c, rtol, atol) _array.assert_allclose(c, n, rtol1, atol1, err_msg, verbose) - # try: - # _array.assert_allclose(c, n, rtol1, atol1, err_msg, verbose) - # except AssertionError as e: - # import numbers - # if runtime.is_hip and type(n) is numpy.ndarray and \ - # (issubclass(n.dtype.type, numbers.Real) or - # issubclass(n.dtype.type, numbers.Complex)): - # npc = cupy.asnumpy(c) - # diff = numpy.linalg.norm(npc - n, numpy.inf) - # norm = numpy.linalg.norm(npc, numpy.inf) - # if numpy.any(npc) and numpy.any(n): - # min_positive = numpy.finfo(n.dtype).tiny - # if (abs(npc) < min_positive).any() or \ - # (abs(n) < min_positive).any(): - # # Denormal case handling - # assert diff <= (atol1 + rtol1 * norm) - # else: - # raise e - # else: - # raise e + return _make_decorator(check_func, name, type_check, contiguous_check, accept_error, sp_name, scipy_name, _check_sparse_format) From bfd707ce7beb68fda07c3c5a21a681fb095101ae Mon Sep 17 00:00:00 2001 From: shbiswas834 Date: Fri, 1 Nov 2024 03:35:42 +0000 Subject: [PATCH 3/6] removed header --- cupy/testing/_loops.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cupy/testing/_loops.py b/cupy/testing/_loops.py index 821be46d173..381258d08b0 100755 --- a/cupy/testing/_loops.py +++ b/cupy/testing/_loops.py @@ -14,7 +14,6 @@ from cupy.testing import _parameterized import cupyx import cupyx.scipy.sparse -# from cupy_backends.cuda.api import runtime from cupy.testing._pytest_impl import is_available From 34ec80201b0abd1f493a9b8a90b76300ab316682 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 5 Nov 2024 16:18:16 +0000 Subject: [PATCH 4/6] Added check for rocm on tolerance change --- tests/cupy_tests/lib_tests/test_polynomial.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/cupy_tests/lib_tests/test_polynomial.py b/tests/cupy_tests/lib_tests/test_polynomial.py index effa2fd2002..285ae3c7b84 100755 --- a/tests/cupy_tests/lib_tests/test_polynomial.py +++ b/tests/cupy_tests/lib_tests/test_polynomial.py @@ -6,6 +6,7 @@ from cupy.cuda import runtime import cupyx from cupy import testing +from cupy_backends.cuda.api import runtime as _runtime @testing.parameterize( @@ -694,7 +695,7 @@ def test_polyfit_weighted_diff_types(self, xp, dtype1, dtype2, dtype3): class TestPolyval(Poly1dTestBase): @testing.for_all_dtypes() - @testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-2, 'default': 2e-3}) + @testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-2, 'default': 2e-3} if _runtime.is_hip else {numpy.float16: 1e-2, 'default': 1e-3}) def test_polyval(self, xp, dtype): a1 = self._get_input(xp, self.type_l, dtype, size=5) a2 = self._get_input(xp, self.type_r, dtype, size=5) From b9a2647d3fa1ddb357b9be249777ee1ebb8e7fd5 Mon Sep 17 00:00:00 2001 From: shbiswas834 Date: Wed, 6 Nov 2024 19:18:26 +0000 Subject: [PATCH 5/6] fix static check --- tests/cupy_tests/lib_tests/test_polynomial.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/cupy_tests/lib_tests/test_polynomial.py b/tests/cupy_tests/lib_tests/test_polynomial.py index 285ae3c7b84..fe44c32827b 100755 --- a/tests/cupy_tests/lib_tests/test_polynomial.py +++ b/tests/cupy_tests/lib_tests/test_polynomial.py @@ -695,7 +695,13 @@ def test_polyfit_weighted_diff_types(self, xp, dtype1, dtype2, dtype3): class TestPolyval(Poly1dTestBase): @testing.for_all_dtypes() - @testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-2, 'default': 2e-3} if _runtime.is_hip else {numpy.float16: 1e-2, 'default': 1e-3}) + @testing.numpy_cupy_allclose( + rtol=( + {numpy.float16: 1e-2, 'default': 2e-3} + if _runtime.is_hip + else {numpy.float16: 1e-2, 'default': 1e-3} + ) + ) def test_polyval(self, xp, dtype): a1 = self._get_input(xp, self.type_l, dtype, size=5) a2 = self._get_input(xp, self.type_r, dtype, size=5) From 9c6dff74c895eede6b7d2c2e5f5dc04102f71e55 Mon Sep 17 00:00:00 2001 From: shbiswas834 Date: Wed, 6 Nov 2024 19:22:59 +0000 Subject: [PATCH 6/6] fix static check autopep8 --- cupy/testing/_loops.py | 0 tests/cupy_tests/lib_tests/test_polynomial.py | 8 ++++---- 2 files changed, 4 insertions(+), 4 deletions(-) mode change 100755 => 100644 cupy/testing/_loops.py mode change 100755 => 100644 tests/cupy_tests/lib_tests/test_polynomial.py diff --git a/cupy/testing/_loops.py b/cupy/testing/_loops.py old mode 100755 new mode 100644 diff --git a/tests/cupy_tests/lib_tests/test_polynomial.py b/tests/cupy_tests/lib_tests/test_polynomial.py old mode 100755 new mode 100644 index fe44c32827b..5eaf0a77cf6 --- a/tests/cupy_tests/lib_tests/test_polynomial.py +++ b/tests/cupy_tests/lib_tests/test_polynomial.py @@ -696,10 +696,10 @@ class TestPolyval(Poly1dTestBase): @testing.for_all_dtypes() @testing.numpy_cupy_allclose( - rtol=( - {numpy.float16: 1e-2, 'default': 2e-3} - if _runtime.is_hip - else {numpy.float16: 1e-2, 'default': 1e-3} + rtol=( + {numpy.float16: 1e-2, 'default': 2e-3} + if _runtime.is_hip + else {numpy.float16: 1e-2, 'default': 1e-3} ) ) def test_polyval(self, xp, dtype):