Skip to content

Commit

Permalink
TST: cluster: turn off dtype checks where they are failing
Browse files Browse the repository at this point in the history
[skip cirrus] [skip circle]
  • Loading branch information
lucascolley committed Sep 21, 2023
1 parent 4bdec24 commit cb1364d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions scipy/cluster/tests/test_hierarchy.py
Expand Up @@ -193,7 +193,7 @@ def test_linkage_cophenet_tdist_Z(self, xp):
295, 138, 219, 295, 295])
Z = xp.asarray(hierarchy_test_data.linkage_ytdist_single)
M = cophenet(Z)
xp_assert_close(M, expectedM, atol=1e-10)
xp_assert_close(M, expectedM, atol=1e-10, check_dtype=False)

@skip_if_array_api_gpu
@array_api_compatible
Expand All @@ -204,8 +204,8 @@ def test_linkage_cophenet_tdist_Z_Y(self, xp):
expectedM = xp.asarray([268, 295, 255, 255, 295, 295, 268, 268, 295, 295,
295, 138, 219, 295, 295])
expectedc = xp.asarray(0.639931296433393415057366837573)[()]
xp_assert_close(c, expectedc, atol=1e-10)
xp_assert_close(M, expectedM, atol=1e-10)
xp_assert_close(c, expectedc, atol=1e-10, check_dtype=False)
xp_assert_close(M, expectedM, atol=1e-10, check_dtype=False)


class TestMLabLinkageConversion:
Expand All @@ -223,8 +223,8 @@ def test_mlab_linkage_conversion_single_row(self, xp):
# Tests from/to_mlab_linkage on linkage array with single row.
Z = xp.asarray([[0., 1., 3., 2.]])
Zm = xp.asarray([[1, 2, 3]])
xp_assert_close(from_mlab_linkage(Zm), Z, rtol=1e-15)
xp_assert_close(to_mlab_linkage(Z), Zm, rtol=1e-15)
xp_assert_close(from_mlab_linkage(Zm), Z, rtol=1e-15, check_dtype=False)
xp_assert_close(to_mlab_linkage(Z), Zm, rtol=1e-15, check_dtype=False)

@skip_if_array_api_gpu
@array_api_compatible
Expand All @@ -239,7 +239,7 @@ def test_mlab_linkage_conversion_multiple_rows(self, xp):
[6., 9., 295., 6.]],
dtype=xp.float64)
xp_assert_close(from_mlab_linkage(Zm), Z, rtol=1e-15)
xp_assert_close(to_mlab_linkage(Z), Zm, rtol=1e-15)
xp_assert_close(to_mlab_linkage(Z), Zm, rtol=1e-15, check_dtype=False)


class TestFcluster:
Expand Down Expand Up @@ -1274,7 +1274,7 @@ def test_cut_tree(xp):
cutree = cut_tree(Z)

xp_assert_close(cutree[:, 0], xp.arange(nobs), rtol=1e-15)
xp_assert_close(cutree[:, -1], xp.zeros(nobs), rtol=1e-15)
xp_assert_close(cutree[:, -1], xp.zeros(nobs), rtol=1e-15, check_dtype=False)
assert_equal(np.asarray(cutree).max(0), np.arange(nobs - 1, -1, -1))

xp_assert_close(cutree[:, [-5]], cut_tree(Z, n_clusters=5), rtol=1e-15)
Expand Down
20 changes: 10 additions & 10 deletions scipy/cluster/tests/test_vq.py
Expand Up @@ -154,7 +154,7 @@ def test_vq_1d(self, xp):
data = xp.asarray(data)
initc = xp.asarray(initc)
ta, tb = py_vq(data[:, np.newaxis], initc[:, np.newaxis])
xp_assert_equal(ta, xp.asarray(a))
xp_assert_equal(ta, xp.asarray(a), check_dtype=False)
xp_assert_equal(tb, xp.asarray(b))

@skip_if_array_api
Expand All @@ -179,7 +179,7 @@ def test_vq_large_nfeat(self, xp):
xp.asarray(X), xp.asarray(code_book)
)
xp_assert_close(dis1, xp.asarray(dis0), 1e-5)
xp_assert_equal(codes1, xp.asarray(codes0))
xp_assert_equal(codes1, xp.asarray(codes0), check_dtype=False)

X = X.astype(np.float32)
code_book = code_book.astype(np.float32)
Expand All @@ -188,8 +188,8 @@ def test_vq_large_nfeat(self, xp):
codes1, dis1 = py_vq(
xp.asarray(X), xp.asarray(code_book)
)
xp_assert_close(dis1, xp.asarray(dis0), 1e-5)
xp_assert_equal(codes1, xp.asarray(codes0))
xp_assert_close(dis1, xp.asarray(dis0), 1e-5, check_dtype=False)
xp_assert_equal(codes1, xp.asarray(codes0), check_dtype=False)

@skip_if_array_api_gpu
@array_api_compatible
Expand All @@ -202,7 +202,7 @@ def test_vq_large_features(self, xp):
xp.asarray(X), xp.asarray(code_book)
)
xp_assert_close(dis1, xp.asarray(dis0), 1e-5)
xp_assert_equal(codes1, xp.asarray(codes0))
xp_assert_equal(codes1, xp.asarray(codes0), check_dtype=False)


# Whole class skipped on GPU for now;
Expand Down Expand Up @@ -350,8 +350,8 @@ def test_kmeans_large_thres(self, xp):
# Regression test for gh-1774
x = xp.asarray([1, 2, 3, 4, 10], dtype=xp.float64)
res = kmeans(x, xp.asarray(1), thresh=1e16)
xp_assert_close(res[0], xp.asarray([4.]))
xp_assert_close(res[1], xp.asarray(2.3999999999999999)[()])
xp_assert_close(res[0], xp.asarray([4.]), check_dtype=False)
xp_assert_close(res[1], xp.asarray(2.3999999999999999)[()], check_dtype=False)

@skip_if_array_api_gpu
@array_api_compatible
Expand All @@ -361,7 +361,7 @@ def test_kmeans2_kpp_low_dim(self, xp):
[-3.153375, 3.3945]])
np.random.seed(42)
res, _ = kmeans2(xp.asarray(TESTDATA_2D), xp.asarray(2), minit='++')
xp_assert_close(res, prev_res)
xp_assert_close(res, prev_res, check_dtype=False)

@skip_if_array_api_gpu
@array_api_compatible
Expand All @@ -387,8 +387,8 @@ def test_kmeans_diff_convergence(self, xp):
# Regression test for gh-8727
obs = xp.asarray([-3, -1, 0, 1, 1, 8], dtype=xp.float64)
res = kmeans(obs, xp.asarray([-3., 0.99]))
xp_assert_close(res[0], xp.asarray([-0.4, 8.]))
xp_assert_close(res[1], xp.asarray(1.0666666666666667)[()])
xp_assert_close(res[0], xp.asarray([-0.4, 8.]), check_dtype=False)
xp_assert_close(res[1], xp.asarray(1.0666666666666667)[()], check_dtype=False)

@skip_if_array_api
def test_kmeans_and_kmeans2_random_seed(self):
Expand Down

0 comments on commit cb1364d

Please sign in to comment.