From 94eaac249677bc364e4351bc79b5d11bfba78152 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 8 Jan 2025 05:57:29 -0800 Subject: [PATCH 1/3] Update TestSpacing::test_zeros using assert_dtype_allclose --- dpnp/tests/test_mathematical.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpnp/tests/test_mathematical.py b/dpnp/tests/test_mathematical.py index 756367c4bcb4..08db8597cad1 100644 --- a/dpnp/tests/test_mathematical.py +++ b/dpnp/tests/test_mathematical.py @@ -2112,13 +2112,13 @@ def test_zeros(self, dt): result = dpnp.spacing(ia) expected = numpy.spacing(a) if numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0": - assert_equal(result, expected) + assert_dtype_allclose(result, expected) else: # numpy.spacing(-0.0) == numpy.spacing(0.0), i.e. NumPy returns # positive value (looks as a bug in NumPy), because for any other # negative input the NumPy result will be also a negative value. expected[1] *= -1 - assert_equal(result, expected) + assert_dtype_allclose(result, expected) @pytest.mark.parametrize("dt", get_float_dtypes(no_float16=False)) @pytest.mark.parametrize("val", [1, 1e-5, 1000]) From 0d9ed4ac89ea5523013623d62837fcbe6e34894b Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Thu, 9 Jan 2025 04:24:19 -0800 Subject: [PATCH 2/3] Use assert_allclose and pass tol --- dpnp/tests/test_mathematical.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dpnp/tests/test_mathematical.py b/dpnp/tests/test_mathematical.py index 08db8597cad1..c19b3a8714ff 100644 --- a/dpnp/tests/test_mathematical.py +++ b/dpnp/tests/test_mathematical.py @@ -2111,14 +2111,15 @@ def test_zeros(self, dt): result = dpnp.spacing(ia) expected = numpy.spacing(a) + tol = numpy.finfo(expected.dtype).resolution if numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0": - assert_dtype_allclose(result, expected) + assert_allclose(result, expected, rtol=tol, atol=tol) else: # numpy.spacing(-0.0) == numpy.spacing(0.0), i.e. NumPy returns # positive value (looks as a bug in NumPy), because for any other # negative input the NumPy result will be also a negative value. expected[1] *= -1 - assert_dtype_allclose(result, expected) + assert_allclose(result, expected, rtol=tol, atol=tol) @pytest.mark.parametrize("dt", get_float_dtypes(no_float16=False)) @pytest.mark.parametrize("val", [1, 1e-5, 1000]) From b0f471a31dc2accbfc3508d0be983f623e2b7aff Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Thu, 9 Jan 2025 06:20:58 -0800 Subject: [PATCH 3/3] Update TestTensordot by adding factor to scale tolerance in assert_dtype_allclose --- dpnp/tests/test_product.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpnp/tests/test_product.py b/dpnp/tests/test_product.py index 95c643a6494c..eab4fe9f53ec 100644 --- a/dpnp/tests/test_product.py +++ b/dpnp/tests/test_product.py @@ -799,7 +799,7 @@ def test_axes(self, dtype, axes): result = dpnp.tensordot(ia, ib, axes=axes) expected = numpy.tensordot(a, b, axes=axes) - assert_dtype_allclose(result, expected) + assert_dtype_allclose(result, expected, factor=9) @pytest.mark.parametrize("dtype1", get_all_dtypes()) @pytest.mark.parametrize("dtype2", get_all_dtypes()) @@ -844,7 +844,7 @@ def test_linalg(self, axes): result = dpnp.linalg.tensordot(ia, ib, axes=axes) expected = numpy.linalg.tensordot(a, b, axes=axes) - assert_dtype_allclose(result, expected) + assert_dtype_allclose(result, expected, factor=9) def test_error(self): a = 5