Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions tests/test_aamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,17 @@ def test_aamp_identical_subsequence_self_join():
naive.replace_inf(ref_mp)
naive.replace_inf(comp_mp)
npt.assert_almost_equal(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is npt.assert_almost_equal still being used here instead of npt.assert_allclose?

ref_mp[:, 0], comp_mp[:, 0], decimal=config.STUMPY_TEST_PRECISION
ref_mp[:, 0],
comp_mp[:, 0],
decimal=config.STUMPY_TEST_PRECISION,
) # ignore indices

comp_mp = aamp(pd.Series(T_A), m, ignore_trivial=True)
naive.replace_inf(comp_mp)
npt.assert_almost_equal(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is npt.assert_almost_equal still being used here instead of npt.assert_allclose?

ref_mp[:, 0], comp_mp[:, 0], decimal=config.STUMPY_TEST_PRECISION
ref_mp[:, 0],
comp_mp[:, 0],
decimal=config.STUMPY_TEST_PRECISION,
) # ignore indices


Expand All @@ -154,13 +158,17 @@ def test_aamp_identical_subsequence_A_B_join():
naive.replace_inf(ref_mp)
naive.replace_inf(comp_mp)
npt.assert_almost_equal(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is npt.assert_almost_equal still being used here instead of npt.assert_allclose?

ref_mp[:, 0], comp_mp[:, 0], config.STUMPY_TEST_PRECISION
ref_mp[:, 0],
comp_mp[:, 0],
decimal=config.STUMPY_TEST_PRECISION,
) # ignore indices

comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False)
naive.replace_inf(comp_mp)
npt.assert_almost_equal(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is npt.assert_almost_equal still being used here instead of npt.assert_allclose?

ref_mp[:, 0], comp_mp[:, 0], config.STUMPY_TEST_PRECISION
ref_mp[:, 0],
comp_mp[:, 0],
decimal=config.STUMPY_TEST_PRECISION,
) # ignore indices

# Swap inputs
Expand All @@ -169,7 +177,9 @@ def test_aamp_identical_subsequence_A_B_join():
naive.replace_inf(ref_mp)
naive.replace_inf(comp_mp)
npt.assert_almost_equal(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is npt.assert_almost_equal still being used here instead of npt.assert_allclose?

ref_mp[:, 0], comp_mp[:, 0], config.STUMPY_TEST_PRECISION
ref_mp[:, 0],
comp_mp[:, 0],
decimal=config.STUMPY_TEST_PRECISION,
) # ignore indices


Expand Down
12 changes: 8 additions & 4 deletions tests/test_aamp_motifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def test_aamp_motifs_one_motif():
)

npt.assert_array_equal(left_indices, right_indices)
npt.assert_almost_equal(left_profile_values, right_distance_values, decimal=4)
npt.assert_allclose(
left_profile_values, right_distance_values, atol=1.5e-04, rtol=0
)


def test_aamp_motifs_two_motifs():
Expand Down Expand Up @@ -124,7 +126,9 @@ def test_aamp_motifs_two_motifs():

# We ignore indices because of sorting ambiguities for equal distances.
# As long as the distances are correct, the indices will be too.
npt.assert_almost_equal(left_profile_values, right_distance_values, decimal=6)
npt.assert_allclose(
left_profile_values, right_distance_values, atol=1.5e-06, rtol=0
)


def test_aamp_naive_match_exact():
Expand Down Expand Up @@ -248,12 +252,12 @@ def test_aamp_match_query_idx():

# `mass_absolute` zeroes the self-match distance when told where `Q` lives.
D = core.mass_absolute(Q, T, query_idx=query_idx)
npt.assert_almost_equal(D[query_idx], 0.0)
npt.assert_allclose(D[query_idx], 0.0, atol=1.5e-07, rtol=0)

# A `Q` that is not the subsequence at `query_idx` must still return the
# self-match first, and must warn, exactly as `stumpy.match` does.
with pytest.warns(UserWarning):
out = aamp_match(Q + 0.5, T, query_idx=query_idx, max_distance=1.0)

assert out[0, 1] == query_idx
npt.assert_almost_equal(out[0, 0], 0.0)
npt.assert_allclose(out[0, 0], 0.0, atol=1.5e-07, rtol=0)
48 changes: 30 additions & 18 deletions tests/test_aamp_ostinato.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def test_random_ostinato(runs):
ref_radius, ref_Ts_idx, ref_subseq_idx = naive.aamp_ostinato(Ts, m)
comp_radius, comp_Ts_idx, comp_subseq_idx = aamp_ostinato(Ts, m)

npt.assert_almost_equal(ref_radius, comp_radius)
npt.assert_almost_equal(ref_Ts_idx, comp_Ts_idx)
npt.assert_almost_equal(ref_subseq_idx, comp_subseq_idx)
npt.assert_allclose(ref_radius, comp_radius, atol=1.5e-07, rtol=0)
npt.assert_allclose(ref_Ts_idx, comp_Ts_idx, atol=1.5e-07, rtol=0)
npt.assert_allclose(ref_subseq_idx, comp_subseq_idx, atol=1.5e-07, rtol=0)


@pytest.mark.parametrize("seed", [41, 88, 290, 292, 310, 328, 538, 556, 563, 570])
Expand All @@ -49,9 +49,9 @@ def test_deterministic_ostinato(seed):
ref_radius, ref_Ts_idx, ref_subseq_idx = naive.aamp_ostinato(Ts, m, p=p)
comp_radius, comp_Ts_idx, comp_subseq_idx = aamp_ostinato(Ts, m, p=p)

npt.assert_almost_equal(ref_radius, comp_radius)
npt.assert_almost_equal(ref_Ts_idx, comp_Ts_idx)
npt.assert_almost_equal(ref_subseq_idx, comp_subseq_idx)
npt.assert_allclose(ref_radius, comp_radius, atol=1.5e-07, rtol=0)
npt.assert_allclose(ref_Ts_idx, comp_Ts_idx, atol=1.5e-07, rtol=0)
npt.assert_allclose(ref_subseq_idx, comp_subseq_idx, atol=1.5e-07, rtol=0)


@pytest.mark.parametrize("runs", range(25))
Expand All @@ -63,9 +63,9 @@ def test_random_ostinatoed(runs, dask_cluster):
ref_radius, ref_Ts_idx, ref_subseq_idx = naive.aamp_ostinato(Ts, m)
comp_radius, comp_Ts_idx, comp_subseq_idx = aamp_ostinatoed(dask_client, Ts, m)

npt.assert_almost_equal(ref_radius, comp_radius)
npt.assert_almost_equal(ref_Ts_idx, comp_Ts_idx)
npt.assert_almost_equal(ref_subseq_idx, comp_subseq_idx)
npt.assert_allclose(ref_radius, comp_radius, atol=1.5e-07, rtol=0)
npt.assert_allclose(ref_Ts_idx, comp_Ts_idx, atol=1.5e-07, rtol=0)
npt.assert_allclose(ref_subseq_idx, comp_subseq_idx, atol=1.5e-07, rtol=0)


@pytest.mark.parametrize("seed", [41, 88, 290, 292, 310, 328, 538, 556, 563, 570])
Expand All @@ -82,9 +82,11 @@ def test_deterministic_ostinatoed(seed, dask_cluster):
dask_client, Ts, m, p=p
)

npt.assert_almost_equal(ref_radius, comp_radius)
npt.assert_almost_equal(ref_Ts_idx, comp_Ts_idx)
npt.assert_almost_equal(ref_subseq_idx, comp_subseq_idx)
npt.assert_allclose(ref_radius, comp_radius, atol=1.5e-07, rtol=0)
npt.assert_allclose(ref_Ts_idx, comp_Ts_idx, atol=1.5e-07, rtol=0)
npt.assert_allclose(
ref_subseq_idx, comp_subseq_idx, atol=1.5e-07, rtol=0
)


def test_input_not_overwritten_ostinato():
Expand All @@ -102,7 +104,9 @@ def test_input_not_overwritten_ostinato():
for i in range(len(Ts)):
T_ref = Ts[i]
T_comp = Ts_input[i]
npt.assert_almost_equal(T_ref[np.isfinite(T_ref)], T_comp[np.isfinite(T_comp)])
npt.assert_allclose(
T_ref[np.isfinite(T_ref)], T_comp[np.isfinite(T_comp)], atol=1.5e-07, rtol=0
)


def test_extract_several_consensus_ostinato():
Expand Down Expand Up @@ -135,8 +139,11 @@ def test_extract_several_consensus_ostinato():
Ts_comp[i][idx : idx + m] = np.nan
Ts_ref[i][idx : idx + m] = np.nan

npt.assert_almost_equal(
Ts_ref[i][np.isfinite(Ts_ref[i])], Ts_comp[i][np.isfinite(Ts_comp[i])]
npt.assert_allclose(
Ts_ref[i][np.isfinite(Ts_ref[i])],
Ts_comp[i][np.isfinite(Ts_comp[i])],
atol=1.5e-07,
rtol=0,
)


Expand All @@ -156,8 +163,11 @@ def test_input_not_overwritten_ostinatoed(dask_cluster):
for i in range(len(Ts)):
T_ref = Ts[i]
T_comp = Ts_input[i]
npt.assert_almost_equal(
T_ref[np.isfinite(T_ref)], T_comp[np.isfinite(T_comp)]
npt.assert_allclose(
T_ref[np.isfinite(T_ref)],
T_comp[np.isfinite(T_comp)],
atol=1.5e-07,
rtol=0,
)


Expand Down Expand Up @@ -195,7 +205,9 @@ def test_extract_several_consensus_ostinatoed(dask_cluster):
Ts_comp[i][idx : idx + m] = np.nan
Ts_ref[i][idx : idx + m] = np.nan

npt.assert_almost_equal(
npt.assert_allclose(
Ts_ref[i][np.isfinite(Ts_ref[i])],
Ts_comp[i][np.isfinite(Ts_comp[i])],
atol=1.5e-07,
rtol=0,
)
16 changes: 8 additions & 8 deletions tests/test_aamp_stimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_aamp_stimp_1_percent(T):
naive.replace_inf(ref_PAN)
naive.replace_inf(cmp_PAN)

npt.assert_almost_equal(ref_PAN, cmp_PAN)
npt.assert_allclose(ref_PAN, cmp_PAN, atol=1.5e-07, rtol=0)

# Compare transformed pan
cmp_pan = pan.PAN_
Expand All @@ -85,7 +85,7 @@ def test_aamp_stimp_1_percent(T):
naive.replace_inf(ref_pan)
naive.replace_inf(cmp_pan)

npt.assert_almost_equal(ref_pan, cmp_pan)
npt.assert_allclose(ref_pan, cmp_pan, atol=1.5e-07, rtol=0)


@pytest.mark.parametrize("T", T)
Expand Down Expand Up @@ -126,7 +126,7 @@ def test_aamp_stimp_max_m(T):
naive.replace_inf(ref_PAN)
naive.replace_inf(cmp_PAN)

npt.assert_almost_equal(ref_PAN, cmp_PAN)
npt.assert_allclose(ref_PAN, cmp_PAN, atol=1.5e-07, rtol=0)

# Compare transformed pan
cmp_pan = pan.PAN_
Expand All @@ -143,7 +143,7 @@ def test_aamp_stimp_max_m(T):
naive.replace_inf(ref_pan)
naive.replace_inf(cmp_pan)

npt.assert_almost_equal(ref_pan, cmp_pan)
npt.assert_allclose(ref_pan, cmp_pan, atol=1.5e-07, rtol=0)


@pytest.mark.parametrize("T", T)
Expand Down Expand Up @@ -178,7 +178,7 @@ def test_aamp_stimp_100_percent(T):
naive.replace_inf(ref_PAN)
naive.replace_inf(cmp_PAN)

npt.assert_almost_equal(ref_PAN, cmp_PAN)
npt.assert_allclose(ref_PAN, cmp_PAN, atol=1.5e-07, rtol=0)

# Compare transformed pan
cmp_pan = pan.PAN_
Expand All @@ -195,7 +195,7 @@ def test_aamp_stimp_100_percent(T):
naive.replace_inf(ref_pan)
naive.replace_inf(cmp_pan)

npt.assert_almost_equal(ref_pan, cmp_pan)
npt.assert_allclose(ref_pan, cmp_pan, atol=1.5e-07, rtol=0)


@pytest.mark.parametrize("T", T)
Expand Down Expand Up @@ -264,7 +264,7 @@ def test_aamp_stimped(T, dask_cluster):
naive.replace_inf(ref_PAN)
naive.replace_inf(cmp_PAN)

npt.assert_almost_equal(ref_PAN, cmp_PAN)
npt.assert_allclose(ref_PAN, cmp_PAN, atol=1.5e-07, rtol=0)

# Compare transformed pan
cmp_pan = pan.PAN_
Expand All @@ -281,4 +281,4 @@ def test_aamp_stimped(T, dask_cluster):
naive.replace_inf(ref_pan)
naive.replace_inf(cmp_pan)

npt.assert_almost_equal(ref_pan, cmp_pan)
npt.assert_allclose(ref_pan, cmp_pan, atol=1.5e-07, rtol=0)
14 changes: 7 additions & 7 deletions tests/test_aampdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_aampdist_vect(T_A, T_B):
ref_aampdist_vect = naive.aampdist_vect(T_A, T_B, m, p=p)
comp_aampdist_vect = _aampdist_vect(T_A, T_B, m, p=p)

npt.assert_almost_equal(ref_aampdist_vect, comp_aampdist_vect)
npt.assert_allclose(ref_aampdist_vect, comp_aampdist_vect, atol=1.5e-07, rtol=0)


@pytest.mark.parametrize("T_A, T_B", test_data)
Expand All @@ -56,7 +56,7 @@ def test_aampdist_vect_percentage(T_A, T_B, percentage):
ref_aampdist_vect = naive.aampdist_vect(T_A, T_B, m, percentage=percentage)
comp_aampdist_vect = _aampdist_vect(T_A, T_B, m, percentage=percentage)

npt.assert_almost_equal(ref_aampdist_vect, comp_aampdist_vect)
npt.assert_allclose(ref_aampdist_vect, comp_aampdist_vect, atol=1.5e-07, rtol=0)


@pytest.mark.parametrize("T_A, T_B", test_data)
Expand All @@ -66,7 +66,7 @@ def test_aampdist_vect_k(T_A, T_B, k):
ref_aampdist_vect = naive.aampdist_vect(T_A, T_B, m, k=k)
comp_aampdist_vect = _aampdist_vect(T_A, T_B, m, k=k)

npt.assert_almost_equal(ref_aampdist_vect, comp_aampdist_vect)
npt.assert_allclose(ref_aampdist_vect, comp_aampdist_vect, atol=1.5e-07, rtol=0)


@pytest.mark.parametrize("T_A, T_B", test_data)
Expand All @@ -76,7 +76,7 @@ def test_aampdist(T_A, T_B):
ref_mpdist = naive.aampdist(T_A, T_B, m, p=p)
comp_mpdist = aampdist(T_A, T_B, m, p=p)

npt.assert_almost_equal(ref_mpdist, comp_mpdist)
npt.assert_allclose(ref_mpdist, comp_mpdist, atol=1.5e-07, rtol=0)


@pytest.mark.parametrize("T_A, T_B", test_data)
Expand All @@ -86,7 +86,7 @@ def test_aampdist_percentage(T_A, T_B, percentage):
ref_mpdist = naive.aampdist(T_A, T_B, m, percentage=percentage)
comp_mpdist = aampdist(T_A, T_B, m, percentage=percentage)

npt.assert_almost_equal(ref_mpdist, comp_mpdist)
npt.assert_allclose(ref_mpdist, comp_mpdist, atol=1.5e-07, rtol=0)


@pytest.mark.parametrize("T_A, T_B", test_data)
Expand All @@ -96,7 +96,7 @@ def test_aampdist_k(T_A, T_B, k):
ref_mpdist = naive.aampdist(T_A, T_B, m, k=k)
comp_mpdist = aampdist(T_A, T_B, m, k=k)

npt.assert_almost_equal(ref_mpdist, comp_mpdist)
npt.assert_allclose(ref_mpdist, comp_mpdist, atol=1.5e-07, rtol=0)


@pytest.mark.filterwarnings("ignore:numpy.dtype size changed")
Expand All @@ -111,4 +111,4 @@ def test_aampdisted(T_A, T_B, dask_cluster):
ref_mpdist = naive.aampdist(T_A, T_B, m, p=p)
comp_mpdist = aampdisted(dask_client, T_A, T_B, m, p=p)

npt.assert_almost_equal(ref_mpdist, comp_mpdist)
npt.assert_allclose(ref_mpdist, comp_mpdist, atol=1.5e-07, rtol=0)
Loading
Loading