From 3501ed556db34a213a212b022e89663d7c2acee4 Mon Sep 17 00:00:00 2001 From: Karthik Date: Thu, 5 Nov 2026 15:20:05 -0500 Subject: [PATCH 1/2] Migrate multidimensional motif test comparisons --- tests/test_mmotifs.py | 168 +++++++++++++++++++++--------------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index d70b476bb..1040d931e 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -52,128 +52,128 @@ @pytest.mark.parametrize("T", test_data) def test_mmotifs_with_default_parameters(T): - motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) - motif_indices_ref = np.array([[2, 9]]) - motif_subspaces_ref = [np.array([1])] - motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] + ref_motif_distances = np.array([[0.0000000e00, 1.1151008e-07]]) + ref_motif_indices = np.array([[2, 9]]) + ref_motif_subspaces = [np.array([1])] + ref_motif_mdls = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] m = 4 excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) ( - motif_distances_cmp, - motif_indices_cmp, - motif_subspaces_cmp, - motif_mdls_cmp, + cmp_motif_distances, + cmp_motif_indices, + cmp_motif_subspaces, + cmp_motif_mdls, ) = mmotifs(T, P, I) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) + npt.assert_allclose(cmp_motif_distances, ref_motif_distances, rtol=0, atol=1.5e-06) + npt.assert_array_equal(cmp_motif_indices, ref_motif_indices) + npt.assert_array_equal(cmp_motif_subspaces, ref_motif_subspaces) + npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, rtol=0, atol=1.5e-06) @pytest.mark.parametrize("T", test_data) def test_mmotifs_max_matches_none(T): - motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) - motif_indices_ref = np.array([[2, 9]]) - motif_subspaces_ref = [np.array([1])] - motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] + ref_motif_distances = np.array([[0.0000000e00, 1.1151008e-07]]) + ref_motif_indices = np.array([[2, 9]]) + ref_motif_subspaces = [np.array([1])] + ref_motif_mdls = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] m = 4 excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) ( - motif_distances_cmp, - motif_indices_cmp, - motif_subspaces_cmp, - motif_mdls_cmp, + cmp_motif_distances, + cmp_motif_indices, + cmp_motif_subspaces, + cmp_motif_mdls, ) = mmotifs(T, P, I, max_matches=None) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) + npt.assert_allclose(cmp_motif_distances, ref_motif_distances, rtol=0, atol=1.5e-06) + npt.assert_array_equal(cmp_motif_indices, ref_motif_indices) + npt.assert_array_equal(cmp_motif_subspaces, ref_motif_subspaces) + npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, rtol=0, atol=1.5e-06) @pytest.mark.parametrize("T", test_data) def test_mmotifs_more_motifs_when_cutoffs_3(T): - motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) - motif_indices_ref = np.array([[2, 9]]) - motif_subspaces_ref = [np.array([1])] - motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] + ref_motif_distances = np.array([[0.0000000e00, 1.1151008e-07]]) + ref_motif_indices = np.array([[2, 9]]) + ref_motif_subspaces = [np.array([1])] + ref_motif_mdls = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] m = 4 excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) ( - motif_distances_cmp, - motif_indices_cmp, - motif_subspaces_cmp, - motif_mdls_cmp, + cmp_motif_distances, + cmp_motif_indices, + cmp_motif_subspaces, + cmp_motif_mdls, ) = mmotifs(T, P, I, cutoffs=3, max_motifs=10) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) + npt.assert_allclose(cmp_motif_distances, ref_motif_distances, rtol=0, atol=1.5e-06) + npt.assert_array_equal(cmp_motif_indices, ref_motif_indices) + npt.assert_array_equal(cmp_motif_subspaces, ref_motif_subspaces) + npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, rtol=0, atol=1.5e-06) @pytest.mark.parametrize("T", test_data) def test_mmotifs_more_motifs_cutoffs_is_list(T): - motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) - motif_indices_ref = np.array([[2, 9]]) - motif_subspaces_ref = [np.array([1])] - motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] + ref_motif_distances = np.array([[0.0000000e00, 1.1151008e-07]]) + ref_motif_indices = np.array([[2, 9]]) + ref_motif_subspaces = [np.array([1])] + ref_motif_mdls = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] m = 4 cutoffs = [2, 3, 4, 5] excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) ( - motif_distances_cmp, - motif_indices_cmp, - motif_subspaces_cmp, - motif_mdls_cmp, + cmp_motif_distances, + cmp_motif_indices, + cmp_motif_subspaces, + cmp_motif_mdls, ) = mmotifs(T, P, I, cutoffs=cutoffs, max_motifs=10) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) + npt.assert_allclose(cmp_motif_distances, ref_motif_distances, rtol=0, atol=1.5e-06) + npt.assert_array_equal(cmp_motif_indices, ref_motif_indices) + npt.assert_array_equal(cmp_motif_subspaces, ref_motif_subspaces) + npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, rtol=0, atol=1.5e-06) @pytest.mark.parametrize("T", test_data) def test_mmotifs_max_matches_2_k_1(T): - motif_distances_ref = np.array([[0.0, 0.20948156]]) - motif_indices_ref = np.array([[2, 9]]) - motif_subspaces_ref = [np.array([1, 3])] - motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] + ref_motif_distances = np.array([[0.0, 0.20948156]]) + ref_motif_indices = np.array([[2, 9]]) + ref_motif_subspaces = [np.array([1, 3])] + ref_motif_mdls = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] m = 4 excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) ( - motif_distances_cmp, - motif_indices_cmp, - motif_subspaces_cmp, - motif_mdls_cmp, + cmp_motif_distances, + cmp_motif_indices, + cmp_motif_subspaces, + cmp_motif_mdls, ) = mmotifs(T, P, I, max_distance=np.inf, max_matches=2, k=1) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) + npt.assert_allclose(cmp_motif_distances, ref_motif_distances, rtol=0, atol=1.5e-06) + npt.assert_array_equal(cmp_motif_indices, ref_motif_indices) + npt.assert_array_equal(cmp_motif_subspaces, ref_motif_subspaces) + npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, rtol=0, atol=1.5e-06) @pytest.mark.parametrize("T", test_data) def test_mmotifs_two_motif_pairs_max_motifs_2(T): - motif_distances_ref = np.array( + ref_motif_distances = np.array( [[0.00000000e00, 1.11510080e-07], [1.68587394e-07, 2.58694429e-01]] ) - motif_indices_ref = np.array([[2, 9], [6, 1]]) - motif_subspaces_ref = [np.array([1]), np.array([2])] - motif_mdls_ref = [ + ref_motif_indices = np.array([[2, 9], [6, 1]]) + ref_motif_subspaces = [np.array([1]), np.array([2])] + ref_motif_mdls = [ np.array([232.0, 250.57542476, 260.0, 271.3509059]), np.array([264.0, 280.0, 299.01955001, 310.51024953]), ] @@ -182,26 +182,26 @@ def test_mmotifs_two_motif_pairs_max_motifs_2(T): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) ( - motif_distances_cmp, - motif_indices_cmp, - motif_subspaces_cmp, - motif_mdls_cmp, + cmp_motif_distances, + cmp_motif_indices, + cmp_motif_subspaces, + cmp_motif_mdls, ) = mmotifs( T, P, I, cutoffs=np.inf, max_motifs=2, max_distance=np.inf, max_matches=2 ) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) + npt.assert_allclose(cmp_motif_distances, ref_motif_distances, rtol=0, atol=1.5e-06) + npt.assert_array_equal(cmp_motif_indices, ref_motif_indices) + npt.assert_array_equal(cmp_motif_subspaces, ref_motif_subspaces) + npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, rtol=0, atol=1.5e-06) @pytest.mark.parametrize("T", test_data) def test_mmotifs_with_default_parameters_with_isconstant(T): - motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) - motif_indices_ref = np.array([[2, 9]]) - motif_subspaces_ref = [np.array([1])] - motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] + ref_motif_distances = np.array([[0.0000000e00, 1.1151008e-07]]) + ref_motif_indices = np.array([[2, 9]]) + ref_motif_subspaces = [np.array([1])] + ref_motif_mdls = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] m = 4 excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) @@ -218,13 +218,13 @@ def test_mmotifs_with_default_parameters_with_isconstant(T): P, I = naive.mstump(T, m, excl_zone, T_subseq_isconstant=T_subseq_isconstant) ( - motif_distances_cmp, - motif_indices_cmp, - motif_subspaces_cmp, - motif_mdls_cmp, + cmp_motif_distances, + cmp_motif_indices, + cmp_motif_subspaces, + cmp_motif_mdls, ) = mmotifs(T, P, I, T_subseq_isconstant=T_subseq_isconstant) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) + npt.assert_allclose(cmp_motif_distances, ref_motif_distances, rtol=0, atol=1.5e-06) + npt.assert_array_equal(cmp_motif_indices, ref_motif_indices) + npt.assert_array_equal(cmp_motif_subspaces, ref_motif_subspaces) + npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, rtol=0, atol=1.5e-06) From 9bbe330772e75394c381f5d15e2bdf892c5d5710 Mon Sep 17 00:00:00 2001 From: Karthik Date: Fri, 6 Nov 2026 15:42:43 -0500 Subject: [PATCH 2/2] Align mmotifs assertions with migration conventions --- tests/test_mmotifs.py | 58 +++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 1040d931e..20f378609 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -67,10 +67,10 @@ def test_mmotifs_with_default_parameters(T): cmp_motif_mdls, ) = mmotifs(T, P, I) - npt.assert_allclose(cmp_motif_distances, ref_motif_distances, rtol=0, atol=1.5e-06) - npt.assert_array_equal(cmp_motif_indices, ref_motif_indices) - npt.assert_array_equal(cmp_motif_subspaces, ref_motif_subspaces) - npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, rtol=0, atol=1.5e-06) + npt.assert_allclose(cmp_motif_distances, ref_motif_distances, atol=1.5e-07) + npt.assert_allclose(cmp_motif_indices, ref_motif_indices, atol=1.5e-07) + npt.assert_allclose(cmp_motif_subspaces, ref_motif_subspaces, atol=1.5e-07) + npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, atol=1.5e-07) @pytest.mark.parametrize("T", test_data) @@ -90,10 +90,10 @@ def test_mmotifs_max_matches_none(T): cmp_motif_mdls, ) = mmotifs(T, P, I, max_matches=None) - npt.assert_allclose(cmp_motif_distances, ref_motif_distances, rtol=0, atol=1.5e-06) - npt.assert_array_equal(cmp_motif_indices, ref_motif_indices) - npt.assert_array_equal(cmp_motif_subspaces, ref_motif_subspaces) - npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, rtol=0, atol=1.5e-06) + npt.assert_allclose(cmp_motif_distances, ref_motif_distances, atol=1.5e-07) + npt.assert_allclose(cmp_motif_indices, ref_motif_indices, atol=1.5e-07) + npt.assert_allclose(cmp_motif_subspaces, ref_motif_subspaces, atol=1.5e-07) + npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, atol=1.5e-07) @pytest.mark.parametrize("T", test_data) @@ -113,10 +113,10 @@ def test_mmotifs_more_motifs_when_cutoffs_3(T): cmp_motif_mdls, ) = mmotifs(T, P, I, cutoffs=3, max_motifs=10) - npt.assert_allclose(cmp_motif_distances, ref_motif_distances, rtol=0, atol=1.5e-06) - npt.assert_array_equal(cmp_motif_indices, ref_motif_indices) - npt.assert_array_equal(cmp_motif_subspaces, ref_motif_subspaces) - npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, rtol=0, atol=1.5e-06) + npt.assert_allclose(cmp_motif_distances, ref_motif_distances, atol=1.5e-07) + npt.assert_allclose(cmp_motif_indices, ref_motif_indices, atol=1.5e-07) + npt.assert_allclose(cmp_motif_subspaces, ref_motif_subspaces, atol=1.5e-07) + npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, atol=1.5e-07) @pytest.mark.parametrize("T", test_data) @@ -137,10 +137,10 @@ def test_mmotifs_more_motifs_cutoffs_is_list(T): cmp_motif_mdls, ) = mmotifs(T, P, I, cutoffs=cutoffs, max_motifs=10) - npt.assert_allclose(cmp_motif_distances, ref_motif_distances, rtol=0, atol=1.5e-06) - npt.assert_array_equal(cmp_motif_indices, ref_motif_indices) - npt.assert_array_equal(cmp_motif_subspaces, ref_motif_subspaces) - npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, rtol=0, atol=1.5e-06) + npt.assert_allclose(cmp_motif_distances, ref_motif_distances, atol=1.5e-07) + npt.assert_allclose(cmp_motif_indices, ref_motif_indices, atol=1.5e-07) + npt.assert_allclose(cmp_motif_subspaces, ref_motif_subspaces, atol=1.5e-07) + npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, atol=1.5e-07) @pytest.mark.parametrize("T", test_data) @@ -160,16 +160,16 @@ def test_mmotifs_max_matches_2_k_1(T): cmp_motif_mdls, ) = mmotifs(T, P, I, max_distance=np.inf, max_matches=2, k=1) - npt.assert_allclose(cmp_motif_distances, ref_motif_distances, rtol=0, atol=1.5e-06) - npt.assert_array_equal(cmp_motif_indices, ref_motif_indices) - npt.assert_array_equal(cmp_motif_subspaces, ref_motif_subspaces) - npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, rtol=0, atol=1.5e-06) + npt.assert_allclose(cmp_motif_distances, ref_motif_distances, atol=1.5e-07) + npt.assert_allclose(cmp_motif_indices, ref_motif_indices, atol=1.5e-07) + npt.assert_allclose(cmp_motif_subspaces, ref_motif_subspaces, atol=1.5e-07) + npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, atol=1.5e-07) @pytest.mark.parametrize("T", test_data) def test_mmotifs_two_motif_pairs_max_motifs_2(T): ref_motif_distances = np.array( - [[0.00000000e00, 1.11510080e-07], [1.68587394e-07, 2.58694429e-01]] + [[0.00000000e00, 1.11510080e-07], [0.00000000e00, 2.58694429e-01]] ) ref_motif_indices = np.array([[2, 9], [6, 1]]) ref_motif_subspaces = [np.array([1]), np.array([2])] @@ -190,10 +190,10 @@ def test_mmotifs_two_motif_pairs_max_motifs_2(T): T, P, I, cutoffs=np.inf, max_motifs=2, max_distance=np.inf, max_matches=2 ) - npt.assert_allclose(cmp_motif_distances, ref_motif_distances, rtol=0, atol=1.5e-06) - npt.assert_array_equal(cmp_motif_indices, ref_motif_indices) - npt.assert_array_equal(cmp_motif_subspaces, ref_motif_subspaces) - npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, rtol=0, atol=1.5e-06) + npt.assert_allclose(cmp_motif_distances, ref_motif_distances, atol=1.5e-07) + npt.assert_allclose(cmp_motif_indices, ref_motif_indices, atol=1.5e-07) + npt.assert_allclose(cmp_motif_subspaces, ref_motif_subspaces, atol=1.5e-07) + npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, atol=1.5e-07) @pytest.mark.parametrize("T", test_data) @@ -224,7 +224,7 @@ def test_mmotifs_with_default_parameters_with_isconstant(T): cmp_motif_mdls, ) = mmotifs(T, P, I, T_subseq_isconstant=T_subseq_isconstant) - npt.assert_allclose(cmp_motif_distances, ref_motif_distances, rtol=0, atol=1.5e-06) - npt.assert_array_equal(cmp_motif_indices, ref_motif_indices) - npt.assert_array_equal(cmp_motif_subspaces, ref_motif_subspaces) - npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, rtol=0, atol=1.5e-06) + npt.assert_allclose(cmp_motif_distances, ref_motif_distances, atol=1.5e-07) + npt.assert_allclose(cmp_motif_indices, ref_motif_indices, atol=1.5e-07) + npt.assert_allclose(cmp_motif_subspaces, ref_motif_subspaces, atol=1.5e-07) + npt.assert_allclose(cmp_motif_mdls, ref_motif_mdls, atol=1.5e-07)