Skip to content

Commit bdf34f3

Browse files
authored
test: add more tolerance (#218)
1 parent bbbf881 commit bdf34f3

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

tests/unit/math/distance/test_numpy.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
),
2929
)
3030
def test_cosine(x_mat, y_mat, result):
31-
np.testing.assert_allclose(cosine(x_mat, y_mat), result, rtol=1e-5)
31+
np.testing.assert_almost_equal(cosine(x_mat, y_mat), result, decimal=3)
3232

3333

3434
@pytest.mark.parametrize(
@@ -51,7 +51,7 @@ def test_cosine(x_mat, y_mat, result):
5151
),
5252
)
5353
def test_sparse_cosine(x_mat, y_mat, result):
54-
np.testing.assert_allclose(sparse_cosine(x_mat, y_mat), result, rtol=1e-5)
54+
np.testing.assert_almost_equal(sparse_cosine(x_mat, y_mat), result, decimal=3)
5555

5656

5757
@pytest.mark.parametrize(
@@ -68,7 +68,7 @@ def test_sparse_cosine(x_mat, y_mat, result):
6868
),
6969
)
7070
def test_sqeuclidean(x_mat, y_mat, result):
71-
np.testing.assert_allclose(sqeuclidean(x_mat, y_mat), result, rtol=1e-5)
71+
np.testing.assert_almost_equal(sqeuclidean(x_mat, y_mat), result, decimal=3)
7272

7373

7474
@pytest.mark.parametrize(
@@ -85,7 +85,7 @@ def test_sqeuclidean(x_mat, y_mat, result):
8585
),
8686
)
8787
def test_sparse_sqeuclidean(x_mat, y_mat, result):
88-
np.testing.assert_allclose(sparse_sqeuclidean(x_mat, y_mat), result, rtol=1e-5)
88+
np.testing.assert_almost_equal(sparse_sqeuclidean(x_mat, y_mat), result, decimal=3)
8989

9090

9191
@pytest.mark.parametrize(
@@ -102,7 +102,7 @@ def test_sparse_sqeuclidean(x_mat, y_mat, result):
102102
),
103103
)
104104
def test_euclidean(x_mat, y_mat, result):
105-
np.testing.assert_allclose(euclidean(x_mat, y_mat), result, rtol=1e-5)
105+
np.testing.assert_almost_equal(euclidean(x_mat, y_mat), result, decimal=3)
106106

107107

108108
@pytest.mark.parametrize(
@@ -123,4 +123,4 @@ def test_euclidean(x_mat, y_mat, result):
123123
),
124124
)
125125
def test_sparse_euclidean(x_mat, y_mat, result):
126-
np.testing.assert_allclose(sparse_euclidean(x_mat, y_mat), result, rtol=1e-5)
126+
np.testing.assert_almost_equal(sparse_euclidean(x_mat, y_mat), result, decimal=3)

tests/unit/math/distance/test_paddle.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
),
3232
)
3333
def test_cosine(x_mat, y_mat, result):
34-
np.testing.assert_allclose(cosine(x_mat, y_mat), result, rtol=1e-5)
34+
np.testing.assert_almost_equal(cosine(x_mat, y_mat), result, decimal=3)
3535

3636

3737
@pytest.mark.parametrize(
@@ -60,7 +60,7 @@ def test_cosine(x_mat, y_mat, result):
6060
),
6161
)
6262
def test_sqeuclidean(x_mat, y_mat, result):
63-
np.testing.assert_allclose(sqeuclidean(x_mat, y_mat), result, rtol=1e-5)
63+
np.testing.assert_almost_equal(sqeuclidean(x_mat, y_mat), result, decimal=3)
6464

6565

6666
@pytest.mark.parametrize(
@@ -89,4 +89,4 @@ def test_sqeuclidean(x_mat, y_mat, result):
8989
),
9090
)
9191
def test_euclidean(x_mat, y_mat, result):
92-
np.testing.assert_allclose(euclidean(x_mat, y_mat), result, rtol=1e-5)
92+
np.testing.assert_almost_equal(euclidean(x_mat, y_mat), result, decimal=3)

tests/unit/math/distance/test_tensorflow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
),
3232
)
3333
def test_cosine(x_mat, y_mat, result):
34-
np.testing.assert_allclose(cosine(x_mat, y_mat), result, rtol=1e-5)
34+
np.testing.assert_almost_equal(cosine(x_mat, y_mat), result, decimal=3)
3535

3636

3737
@pytest.mark.parametrize(
@@ -60,7 +60,7 @@ def test_cosine(x_mat, y_mat, result):
6060
),
6161
)
6262
def test_sqeuclidean(x_mat, y_mat, result):
63-
np.testing.assert_allclose(sqeuclidean(x_mat, y_mat), result, rtol=1e-5)
63+
np.testing.assert_almost_equal(sqeuclidean(x_mat, y_mat), result, decimal=3)
6464

6565

6666
@pytest.mark.parametrize(
@@ -89,4 +89,4 @@ def test_sqeuclidean(x_mat, y_mat, result):
8989
),
9090
)
9191
def test_euclidean(x_mat, y_mat, result):
92-
np.testing.assert_allclose(euclidean(x_mat, y_mat), result, rtol=1e-5)
92+
np.testing.assert_almost_equal(euclidean(x_mat, y_mat), result, decimal=3)

tests/unit/math/distance/test_torch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
),
3232
)
3333
def test_cosine(x_mat, y_mat, result):
34-
np.testing.assert_allclose(cosine(x_mat, y_mat), result, rtol=1e-5)
34+
np.testing.assert_almost_equal(cosine(x_mat, y_mat), result, decimal=3)
3535

3636

3737
@pytest.mark.parametrize(
@@ -55,12 +55,12 @@ def test_cosine(x_mat, y_mat, result):
5555
(
5656
torch.tensor([[1.0, 2.0, 3.0]]),
5757
torch.tensor([[19.0, 53.0, 201.0]]),
58-
np.array([[42129]]),
58+
np.array([[42128.996]]),
5959
),
6060
),
6161
)
6262
def test_sqeuclidean(x_mat, y_mat, result):
63-
np.testing.assert_allclose(sqeuclidean(x_mat, y_mat), result, rtol=1e-5)
63+
np.testing.assert_almost_equal(sqeuclidean(x_mat, y_mat), result, decimal=3)
6464

6565

6666
@pytest.mark.parametrize(
@@ -89,4 +89,4 @@ def test_sqeuclidean(x_mat, y_mat, result):
8989
),
9090
)
9191
def test_euclidean(x_mat, y_mat, result):
92-
np.testing.assert_allclose(euclidean(x_mat, y_mat), result, rtol=1e-5)
92+
np.testing.assert_almost_equal(euclidean(x_mat, y_mat), result, decimal=3)

0 commit comments

Comments
 (0)