From d33ce7daa2d479781c9a361c1466eb55633f62f4 Mon Sep 17 00:00:00 2001 From: Vahid Tavanashad Date: Thu, 18 Jan 2024 21:08:43 -0600 Subject: [PATCH 1/3] update tests update more tests rename varibale update test hypot --- tests/test_mathematical.py | 22 +++++++++---------- tests/test_umath.py | 14 ++++++------ .../cupy/core_tests/test_ndarray_unary_op.py | 7 +++++- .../cupy/math_tests/test_rounding.py | 7 ++++-- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/tests/test_mathematical.py b/tests/test_mathematical.py index 86c31dc25ae3..879a2657c370 100644 --- a/tests/test_mathematical.py +++ b/tests/test_mathematical.py @@ -1160,7 +1160,7 @@ def test_invalid_dtype(self, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.ceil(dp_array, out=dp_out) @pytest.mark.parametrize("dtype", get_float_dtypes()) @@ -1200,7 +1200,7 @@ def test_invalid_dtype(self, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.floor(dp_array, out=dp_out) @pytest.mark.parametrize("dtype", get_float_dtypes()) @@ -1240,7 +1240,7 @@ def test_invalid_dtype(self, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.trunc(dp_array, out=dp_out) @pytest.mark.parametrize("dtype", get_float_dtypes()) @@ -1291,7 +1291,7 @@ def test_out_dtypes(self, dtype): dp_out = dpnp.empty(size, dtype=dpnp.complex64) if dtype != dpnp.complex64: # dtype of out mismatches types of input arrays - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.add(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type @@ -1388,7 +1388,7 @@ def test_out_dtypes(self, dtype): check_dtype = True if dtype != dpnp.complex64: # dtype of out mismatches types of input arrays - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.divide(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type @@ -1489,7 +1489,7 @@ def test_out_dtypes(self, dtype): dp_out = dpnp.empty(size, dtype=dpnp.complex64) if dtype != dpnp.complex64: # dtype of out mismatches types of input arrays - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.floor_divide(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type @@ -1749,7 +1749,7 @@ def test_out_dtypes(self, dtype): dp_out = dpnp.empty(size, dtype=dpnp.float32) if dtype != dpnp.float32: # dtype of out mismatches types of input arrays - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.hypot(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type @@ -1917,7 +1917,7 @@ def test_out_dtypes(self, dtype): dp_out = dpnp.empty(size, dtype=dpnp.complex64) if dtype != dpnp.complex64: # dtype of out mismatches types of input arrays - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.maximum(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type @@ -1998,7 +1998,7 @@ def test_out_dtypes(self, dtype): dp_out = dpnp.empty(size, dtype=dpnp.complex64) if dtype != dpnp.complex64: # dtype of out mismatches types of input arrays - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.minimum(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type @@ -2079,7 +2079,7 @@ def test_out_dtypes(self, dtype): dp_out = dpnp.empty(size, dtype=dpnp.complex64) if dtype != dpnp.complex64: # dtype of out mismatches types of input arrays - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.multiply(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type @@ -2174,7 +2174,7 @@ def test_out_dtypes(self, dtype): dp_out = dpnp.empty(size, dtype=dpnp.complex64) if dtype != dpnp.complex64: # dtype of out mismatches types of input arrays - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.power(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type diff --git a/tests/test_umath.py b/tests/test_umath.py index d9bbacdf4ef3..70c9b65e4986 100644 --- a/tests/test_umath.py +++ b/tests/test_umath.py @@ -205,7 +205,7 @@ def test_invalid_dtype(self, func_params, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(TypeError): + with pytest.raises(ValueError): getattr(dpnp, func_name)(dp_array, out=dp_out) @pytest.mark.parametrize( @@ -250,7 +250,7 @@ def test_invalid_dtype(self, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.cbrt(dp_array, out=dp_out) @pytest.mark.parametrize( @@ -296,7 +296,7 @@ def test_invalid_dtype(self, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.rsqrt(dp_array, out=dp_out) @pytest.mark.parametrize( @@ -337,7 +337,7 @@ def test_invalid_dtype(self, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.square(dp_array, out=dp_out) @pytest.mark.parametrize( @@ -385,7 +385,7 @@ def test_invalid_dtype(self, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.arctan2(dp_array, dp_array, out=dp_out) @pytest.mark.parametrize( @@ -421,7 +421,7 @@ def test_invalid_dtype(self, dtype): dpnp_dtype = get_all_dtypes(no_complex=True, no_none=True)[-1] dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.copysign(dp_array, dp_array, out=dp_out) @pytest.mark.parametrize( @@ -457,7 +457,7 @@ def test_invalid_dtype(self, dtype): dpnp_dtype = get_all_dtypes(no_complex=True, no_none=True)[-1] dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(TypeError): + with pytest.raises(ValueError): dpnp.logaddexp(dp_array, dp_array, out=dp_out) @pytest.mark.parametrize( diff --git a/tests/third_party/cupy/core_tests/test_ndarray_unary_op.py b/tests/third_party/cupy/core_tests/test_ndarray_unary_op.py index 9622decd9813..105295fd1df9 100644 --- a/tests/third_party/cupy/core_tests/test_ndarray_unary_op.py +++ b/tests/third_party/cupy/core_tests/test_ndarray_unary_op.py @@ -124,7 +124,12 @@ def test_invert_array(self): @testing.numpy_cupy_allclose(accept_error=TypeError) def check_zerodim_op(self, op, xp, dtype): a = xp.array(-2).astype(dtype) - return op(a) + if op == operator.invert and numpy.issubdtype(dtype, numpy.inexact): + # NumPy returns TypeError + # DPNP returns ValueError + pytest.skip("NumPy and DPNP returns different types of error.") + else: + return op(a) def test_invert_zerodim(self): self.check_zerodim_op(operator.invert) diff --git a/tests/third_party/cupy/math_tests/test_rounding.py b/tests/third_party/cupy/math_tests/test_rounding.py index 5c9cbcd4aa68..443674cb9167 100644 --- a/tests/third_party/cupy/math_tests/test_rounding.py +++ b/tests/third_party/cupy/math_tests/test_rounding.py @@ -8,7 +8,6 @@ from tests.third_party.cupy import testing -@testing.gpu class TestRounding(unittest.TestCase): @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose(type_check=False, atol=1e-5) @@ -26,7 +25,11 @@ def check_unary_complex(self, name, xp, dtype): def check_unary_complex_unsupported(self, name, dtype): for xp in (numpy, cupy): a = testing.shaped_arange((2, 3), xp, dtype) - with pytest.raises(TypeError): + if xp == cupy and name in ["ceil", "floor", "trunc"]: + Exception = ValueError + else: + Exception = TypeError + with pytest.raises(Exception): getattr(xp, name)(a) @testing.for_dtypes(["?", "b", "h", "i", "q", "e", "f", "d"]) From cdecc06f74b20d3497bc00b56e4858e4ad75c9d0 Mon Sep 17 00:00:00 2001 From: Vahid Tavanashad Date: Fri, 19 Jan 2024 09:53:41 -0600 Subject: [PATCH 2/3] including both type of erros in tests --- tests/test_mathematical.py | 44 ++++++++++++++----- tests/test_umath.py | 28 +++++++++--- .../cupy/math_tests/test_rounding.py | 8 ++-- 3 files changed, 57 insertions(+), 23 deletions(-) diff --git a/tests/test_mathematical.py b/tests/test_mathematical.py index 879a2657c370..e6eef1646cd4 100644 --- a/tests/test_mathematical.py +++ b/tests/test_mathematical.py @@ -1160,7 +1160,9 @@ def test_invalid_dtype(self, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.ceil(dp_array, out=dp_out) @pytest.mark.parametrize("dtype", get_float_dtypes()) @@ -1200,7 +1202,9 @@ def test_invalid_dtype(self, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.floor(dp_array, out=dp_out) @pytest.mark.parametrize("dtype", get_float_dtypes()) @@ -1240,7 +1244,9 @@ def test_invalid_dtype(self, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.trunc(dp_array, out=dp_out) @pytest.mark.parametrize("dtype", get_float_dtypes()) @@ -1291,7 +1297,9 @@ def test_out_dtypes(self, dtype): dp_out = dpnp.empty(size, dtype=dpnp.complex64) if dtype != dpnp.complex64: # dtype of out mismatches types of input arrays - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.add(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type @@ -1388,7 +1396,9 @@ def test_out_dtypes(self, dtype): check_dtype = True if dtype != dpnp.complex64: # dtype of out mismatches types of input arrays - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.divide(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type @@ -1489,7 +1499,9 @@ def test_out_dtypes(self, dtype): dp_out = dpnp.empty(size, dtype=dpnp.complex64) if dtype != dpnp.complex64: # dtype of out mismatches types of input arrays - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.floor_divide(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type @@ -1749,7 +1761,9 @@ def test_out_dtypes(self, dtype): dp_out = dpnp.empty(size, dtype=dpnp.float32) if dtype != dpnp.float32: # dtype of out mismatches types of input arrays - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.hypot(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type @@ -1917,7 +1931,9 @@ def test_out_dtypes(self, dtype): dp_out = dpnp.empty(size, dtype=dpnp.complex64) if dtype != dpnp.complex64: # dtype of out mismatches types of input arrays - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.maximum(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type @@ -1998,7 +2014,9 @@ def test_out_dtypes(self, dtype): dp_out = dpnp.empty(size, dtype=dpnp.complex64) if dtype != dpnp.complex64: # dtype of out mismatches types of input arrays - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.minimum(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type @@ -2079,7 +2097,9 @@ def test_out_dtypes(self, dtype): dp_out = dpnp.empty(size, dtype=dpnp.complex64) if dtype != dpnp.complex64: # dtype of out mismatches types of input arrays - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.multiply(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type @@ -2174,7 +2194,9 @@ def test_out_dtypes(self, dtype): dp_out = dpnp.empty(size, dtype=dpnp.complex64) if dtype != dpnp.complex64: # dtype of out mismatches types of input arrays - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.power(dp_array1, dp_array2, out=dp_out) # allocate new out with expected type diff --git a/tests/test_umath.py b/tests/test_umath.py index 70c9b65e4986..ccfa35aca555 100644 --- a/tests/test_umath.py +++ b/tests/test_umath.py @@ -205,7 +205,9 @@ def test_invalid_dtype(self, func_params, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): getattr(dpnp, func_name)(dp_array, out=dp_out) @pytest.mark.parametrize( @@ -250,7 +252,9 @@ def test_invalid_dtype(self, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.cbrt(dp_array, out=dp_out) @pytest.mark.parametrize( @@ -296,7 +300,9 @@ def test_invalid_dtype(self, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.rsqrt(dp_array, out=dp_out) @pytest.mark.parametrize( @@ -337,7 +343,9 @@ def test_invalid_dtype(self, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.square(dp_array, out=dp_out) @pytest.mark.parametrize( @@ -385,7 +393,9 @@ def test_invalid_dtype(self, dtype): dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.arctan2(dp_array, dp_array, out=dp_out) @pytest.mark.parametrize( @@ -421,7 +431,9 @@ def test_invalid_dtype(self, dtype): dpnp_dtype = get_all_dtypes(no_complex=True, no_none=True)[-1] dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.copysign(dp_array, dp_array, out=dp_out) @pytest.mark.parametrize( @@ -457,7 +469,9 @@ def test_invalid_dtype(self, dtype): dpnp_dtype = get_all_dtypes(no_complex=True, no_none=True)[-1] dp_array = dpnp.arange(10, dtype=dpnp_dtype) dp_out = dpnp.empty(10, dtype=dtype) - with pytest.raises(ValueError): + # TODO: change it to ValueError, when dpctl + # is being used in internal CI + with pytest.raises((TypeError, ValueError)): dpnp.logaddexp(dp_array, dp_array, out=dp_out) @pytest.mark.parametrize( diff --git a/tests/third_party/cupy/math_tests/test_rounding.py b/tests/third_party/cupy/math_tests/test_rounding.py index 443674cb9167..7e451ae1e511 100644 --- a/tests/third_party/cupy/math_tests/test_rounding.py +++ b/tests/third_party/cupy/math_tests/test_rounding.py @@ -25,11 +25,9 @@ def check_unary_complex(self, name, xp, dtype): def check_unary_complex_unsupported(self, name, dtype): for xp in (numpy, cupy): a = testing.shaped_arange((2, 3), xp, dtype) - if xp == cupy and name in ["ceil", "floor", "trunc"]: - Exception = ValueError - else: - Exception = TypeError - with pytest.raises(Exception): + # NumPy returns TypeError while DPNP returns ValueError + # for these functions: "ceil", "floor", "trunc" + with pytest.raises((TypeError, ValueError)): getattr(xp, name)(a) @testing.for_dtypes(["?", "b", "h", "i", "q", "e", "f", "d"]) From cee0d989e9e14fa85bf1c5bd3c6ac26306ac118c Mon Sep 17 00:00:00 2001 From: Vahid Tavanashad Date: Fri, 19 Jan 2024 10:49:06 -0600 Subject: [PATCH 3/3] address comments --- .../cupy/core_tests/test_ndarray_unary_op.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/third_party/cupy/core_tests/test_ndarray_unary_op.py b/tests/third_party/cupy/core_tests/test_ndarray_unary_op.py index 105295fd1df9..86bf028aa019 100644 --- a/tests/third_party/cupy/core_tests/test_ndarray_unary_op.py +++ b/tests/third_party/cupy/core_tests/test_ndarray_unary_op.py @@ -124,12 +124,14 @@ def test_invert_array(self): @testing.numpy_cupy_allclose(accept_error=TypeError) def check_zerodim_op(self, op, xp, dtype): a = xp.array(-2).astype(dtype) - if op == operator.invert and numpy.issubdtype(dtype, numpy.inexact): - # NumPy returns TypeError - # DPNP returns ValueError - pytest.skip("NumPy and DPNP returns different types of error.") - else: + try: return op(a) + except ValueError: + # When op is operator.invert and dtype is inexact, + # NumPy raises TypeError while DPNP raises ValueError. + # With this logic, when ValueError is raised in DPNP, + # it is changed to TypeError to align with Numpy. + raise TypeError def test_invert_zerodim(self): self.check_zerodim_op(operator.invert)