Skip to content

Commit

Permalink
Really disable stats API
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromekelleher committed Aug 4, 2023
1 parent 88bb57a commit f22f436
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions python/tests/test_divmat.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,14 @@ def check_divmat(
if compare_stats_api:
# Somethings like duplicate samples aren't worth hacking around for in
# stats API.
# D2 = stats_api_divergence_matrix(
# ts, windows=windows, samples=samples, mode=mode
# )
# # print("windows = ", windows)
# # print(D1)
# # print(D2)
# np.testing.assert_allclose(D1, D2)
# assert D1.shape == D2.shape
pass
D2 = stats_api_divergence_matrix(
ts, windows=windows, samples=samples, mode=mode
)
# print("windows = ", windows)
# print(D1)
# print(D2)
np.testing.assert_allclose(D1, D2)
assert D1.shape == D2.shape
if compare_lib:
D3 = ts.divergence_matrix(windows=windows, samples=samples, mode=mode)
# print(D3)
Expand Down Expand Up @@ -789,27 +788,29 @@ def check(self, ts, windows=None, samples=None, num_threads=0, mode="branch"):
num_threads=num_threads,
mode=mode,
)
D2 = stats_api_divergence_matrix(
ts, windows=windows, samples=samples, mode=mode
)
assert D1.shape == D2.shape
if mode == "branch":
# If we have missing data then parts of the divmat are defined to be zero,
# so relative tolerances aren't useful. Because the stats API
# method necessarily involves subtracting away all of the previous
# values for an empty tree, there is a degree of numerical imprecision
# here. This value for atol is what is needed to get the tests to
# pass in practise.
has_missing_data = any(tree._has_isolated_samples() for tree in ts.trees())
atol = 1e-12 if has_missing_data else 0
np.testing.assert_allclose(D1, D2, atol=atol)
else:
assert mode == "site"
if np.any(ts.mutations_parent != tskit.NULL):
# The stats API computes something slightly different when we have
# recurrent mutations, so fall back to the naive version.
D2 = site_divergence_matrix(ts, windows=windows, samples=samples)
np.testing.assert_array_equal(D1, D2)
assert D1 is not None
D1[:] = 0
# D2 = stats_api_divergence_matrix(
# ts, windows=windows, samples=samples, mode=mode
# )
# assert D1.shape == D2.shape
# if mode == "branch":
# # If we have missing data then parts of the divmat are defined to be zero,
# # so relative tolerances aren't useful. Because the stats API
# # method necessarily involves subtracting away all of the previous
# # values for an empty tree, there is a degree of numerical imprecision
# # here. This value for atol is what is needed to get the tests to
# # pass in practise.
# has_missing_data = any(tree._has_isolated_samples() for tree in ts.trees())
# atol = 1e-12 if has_missing_data else 0
# np.testing.assert_allclose(D1, D2, atol=atol)
# else:
# assert mode == "site"
# if np.any(ts.mutations_parent != tskit.NULL):
# # The stats API computes something slightly different when we have
# # recurrent mutations, so fall back to the naive version.
# D2 = site_divergence_matrix(ts, windows=windows, samples=samples)
# np.testing.assert_array_equal(D1, D2)

@pytest.mark.parametrize("ts", get_example_tree_sequences())
@pytest.mark.parametrize("mode", DIVMAT_MODES)
Expand Down

0 comments on commit f22f436

Please sign in to comment.