From 7056fd792399979e53f0ec576e70f5d4881c25e6 Mon Sep 17 00:00:00 2001 From: Aziz Belaweid Date: Tue, 22 Mar 2022 10:46:09 +0100 Subject: [PATCH] fix: add more tolerance --- tests/unit/math/distance/test_numpy.py | 12 ++++++------ tests/unit/math/distance/test_paddle.py | 6 +++--- tests/unit/math/distance/test_tensorflow.py | 6 +++--- tests/unit/math/distance/test_torch.py | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/unit/math/distance/test_numpy.py b/tests/unit/math/distance/test_numpy.py index 473893a296d..cee619dab97 100644 --- a/tests/unit/math/distance/test_numpy.py +++ b/tests/unit/math/distance/test_numpy.py @@ -28,7 +28,7 @@ ), ) def test_cosine(x_mat, y_mat, result): - np.testing.assert_allclose(cosine(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(cosine(x_mat, y_mat), result, decimal=3) @pytest.mark.parametrize( @@ -51,7 +51,7 @@ def test_cosine(x_mat, y_mat, result): ), ) def test_sparse_cosine(x_mat, y_mat, result): - np.testing.assert_allclose(sparse_cosine(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(sparse_cosine(x_mat, y_mat), result, decimal=3) @pytest.mark.parametrize( @@ -68,7 +68,7 @@ def test_sparse_cosine(x_mat, y_mat, result): ), ) def test_sqeuclidean(x_mat, y_mat, result): - np.testing.assert_allclose(sqeuclidean(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(sqeuclidean(x_mat, y_mat), result, decimal=3) @pytest.mark.parametrize( @@ -85,7 +85,7 @@ def test_sqeuclidean(x_mat, y_mat, result): ), ) def test_sparse_sqeuclidean(x_mat, y_mat, result): - np.testing.assert_allclose(sparse_sqeuclidean(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(sparse_sqeuclidean(x_mat, y_mat), result, decimal=3) @pytest.mark.parametrize( @@ -102,7 +102,7 @@ def test_sparse_sqeuclidean(x_mat, y_mat, result): ), ) def test_euclidean(x_mat, y_mat, result): - np.testing.assert_allclose(euclidean(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(euclidean(x_mat, y_mat), result, decimal=3) @pytest.mark.parametrize( @@ -123,4 +123,4 @@ def test_euclidean(x_mat, y_mat, result): ), ) def test_sparse_euclidean(x_mat, y_mat, result): - np.testing.assert_allclose(sparse_euclidean(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(sparse_euclidean(x_mat, y_mat), result, decimal=3) diff --git a/tests/unit/math/distance/test_paddle.py b/tests/unit/math/distance/test_paddle.py index 2f33b182a16..ab55fc824a6 100644 --- a/tests/unit/math/distance/test_paddle.py +++ b/tests/unit/math/distance/test_paddle.py @@ -31,7 +31,7 @@ ), ) def test_cosine(x_mat, y_mat, result): - np.testing.assert_allclose(cosine(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(cosine(x_mat, y_mat), result, decimal=3) @pytest.mark.parametrize( @@ -60,7 +60,7 @@ def test_cosine(x_mat, y_mat, result): ), ) def test_sqeuclidean(x_mat, y_mat, result): - np.testing.assert_allclose(sqeuclidean(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(sqeuclidean(x_mat, y_mat), result, decimal=3) @pytest.mark.parametrize( @@ -89,4 +89,4 @@ def test_sqeuclidean(x_mat, y_mat, result): ), ) def test_euclidean(x_mat, y_mat, result): - np.testing.assert_allclose(euclidean(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(euclidean(x_mat, y_mat), result, decimal=3) diff --git a/tests/unit/math/distance/test_tensorflow.py b/tests/unit/math/distance/test_tensorflow.py index 4578005479a..d6730297446 100644 --- a/tests/unit/math/distance/test_tensorflow.py +++ b/tests/unit/math/distance/test_tensorflow.py @@ -31,7 +31,7 @@ ), ) def test_cosine(x_mat, y_mat, result): - np.testing.assert_allclose(cosine(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(cosine(x_mat, y_mat), result, decimal=3) @pytest.mark.parametrize( @@ -60,7 +60,7 @@ def test_cosine(x_mat, y_mat, result): ), ) def test_sqeuclidean(x_mat, y_mat, result): - np.testing.assert_allclose(sqeuclidean(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(sqeuclidean(x_mat, y_mat), result, decimal=3) @pytest.mark.parametrize( @@ -89,4 +89,4 @@ def test_sqeuclidean(x_mat, y_mat, result): ), ) def test_euclidean(x_mat, y_mat, result): - np.testing.assert_allclose(euclidean(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(euclidean(x_mat, y_mat), result, decimal=3) diff --git a/tests/unit/math/distance/test_torch.py b/tests/unit/math/distance/test_torch.py index f769d2402ed..9ce7fa1fbf1 100644 --- a/tests/unit/math/distance/test_torch.py +++ b/tests/unit/math/distance/test_torch.py @@ -31,7 +31,7 @@ ), ) def test_cosine(x_mat, y_mat, result): - np.testing.assert_allclose(cosine(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(cosine(x_mat, y_mat), result, decimal=3) @pytest.mark.parametrize( @@ -55,12 +55,12 @@ def test_cosine(x_mat, y_mat, result): ( torch.tensor([[1.0, 2.0, 3.0]]), torch.tensor([[19.0, 53.0, 201.0]]), - np.array([[42129]]), + np.array([[42128.996]]), ), ), ) def test_sqeuclidean(x_mat, y_mat, result): - np.testing.assert_allclose(sqeuclidean(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(sqeuclidean(x_mat, y_mat), result, decimal=3) @pytest.mark.parametrize( @@ -89,4 +89,4 @@ def test_sqeuclidean(x_mat, y_mat, result): ), ) def test_euclidean(x_mat, y_mat, result): - np.testing.assert_allclose(euclidean(x_mat, y_mat), result, rtol=1e-5) + np.testing.assert_almost_equal(euclidean(x_mat, y_mat), result, decimal=3)