From 493f59765fe643324917ea7aaf137500536cb67c Mon Sep 17 00:00:00 2001 From: Karthik Date: Wed, 18 Nov 2026 15:03:06 -0500 Subject: [PATCH 1/3] Finish comparison names and argument order in remaining tests --- tests/test_cache.py | 4 ++-- tests/test_chains.py | 20 ++++++++++---------- tests/test_sdp.py | 36 ++++++++++++++++++------------------ 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/test_cache.py b/tests/test_cache.py index ffd4fe1ce..379d66292 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -32,8 +32,8 @@ def test_cache_save_after_clear(): # calls to `cache.save()` will automatically save both `.nbi` and `.nbc` cache files cache.save() # Save both `.nbi` and `.nbc` cache files - comp_cache = cache._get_cache(cache_dir) + cmp_cache = cache._get_cache(cache_dir) - assert sorted(ref_cache) == sorted(comp_cache) + assert sorted(cmp_cache) == sorted(ref_cache) cache.clear(cache_dir) diff --git a/tests/test_chains.py b/tests/test_chains.py index a2cb70aba..88fb21ca1 100644 --- a/tests/test_chains.py +++ b/tests/test_chains.py @@ -16,14 +16,14 @@ @pytest.mark.parametrize("Value, IR, IL", test_data) def test_atsc(Value, IR, IL): j = 2 - ref = np.array([2, 4, 6, 8, 10], np.int64) - comp = atsc(IL, IR, j) - npt.assert_equal(ref, comp) + ref_chain = np.array([2, 4, 6, 8, 10], np.int64) + cmp_chain = atsc(IL, IR, j) + npt.assert_array_equal(cmp_chain, ref_chain) @pytest.mark.parametrize("Value, IR, IL", test_data) def test_allc(Value, IR, IL): - S_ref = [ + ref_chains = [ np.array([1, 7, 11], dtype=np.int64), np.array([0], dtype=np.int64), np.array([3], dtype=np.int64), @@ -31,11 +31,11 @@ def test_allc(Value, IR, IL): np.array([2, 4, 6, 8, 10], dtype=np.int64), np.array([5], dtype=np.int64), ] - C_ref = np.array([2, 4, 6, 8, 10], dtype=np.int64) - S_comp, C_comp = allc(IL, IR) + ref_longest_chain = np.array([2, 4, 6, 8, 10], dtype=np.int64) + cmp_chains, cmp_longest_chain = allc(IL, IR) - S_ref = sorted(S_ref, key=lambda x: (len(x), list(x))) - S_comp = sorted(S_comp, key=lambda x: (len(x), list(x))) + ref_chains = sorted(ref_chains, key=lambda x: (len(x), list(x))) + cmp_chains = sorted(cmp_chains, key=lambda x: (len(x), list(x))) - npt.assert_equal(S_ref, S_comp) - npt.assert_equal(C_ref, C_comp) + npt.assert_equal(cmp_chains, ref_chains) + npt.assert_array_equal(cmp_longest_chain, ref_longest_chain) diff --git a/tests/test_sdp.py b/tests/test_sdp.py index ea04f3ea3..5b2ad64fd 100644 --- a/tests/test_sdp.py +++ b/tests/test_sdp.py @@ -117,12 +117,12 @@ def test_sdp(n_T, remainder, comparator): for n_Q in n_Q_values: Q = rng.RNG.rand(n_Q) T = rng.RNG.rand(n_T) - ref = naive.rolling_window_dot_product(Q, T) + ref_dot_product = naive.rolling_window_dot_product(Q, T) for func_name in get_sdp_function_names(): func = getattr(sdp, func_name) try: - comp = func(Q, T) - npt.assert_allclose(comp, ref) + cmp_dot_product = func(Q, T) + npt.assert_allclose(cmp_dot_product, ref_dot_product) except Exception as e: # pragma: no cover msg = f"Error in {func_name}, with n_Q={n_Q} and n_T={n_T}" warnings.warn(msg) @@ -144,9 +144,9 @@ def test_sdp_power2(): Q = rng.RNG.rand(n_Q) T = rng.RNG.rand(n_T) - ref = naive.rolling_window_dot_product(Q, T) - comp = func(Q, T) - npt.assert_allclose(comp, ref) + ref_dot_product = naive.rolling_window_dot_product(Q, T) + cmp_dot_product = func(Q, T) + npt.assert_allclose(cmp_dot_product, ref_dot_product) except Exception as e: # pragma: no cover msg = f"Error in {func_name}, with q={q} and p={p}" @@ -173,10 +173,10 @@ def test_pyfftw_sdp_init_len(): T = np.random.rand(init_len + 1) Q = np.random.rand(2**2) - comp = _pyfftw_sliding_dot_product(Q, T) - ref = naive.rolling_window_dot_product(Q, T) + cmp_dot_product = _pyfftw_sliding_dot_product(Q, T) + ref_dot_product = naive.rolling_window_dot_product(Q, T) - np.testing.assert_allclose(comp, ref) + np.testing.assert_allclose(cmp_dot_product, ref_dot_product) return @@ -196,10 +196,10 @@ def test_pyfftw_sdp_longdoube(): T = np.random.rand(init_len) Q = np.random.rand(2**8) - comp = sdp_func(Q, T) - ref = naive.rolling_window_dot_product(Q, T) + cmp_dot_product = sdp_func(Q, T) + ref_dot_product = naive.rolling_window_dot_product(Q, T) - np.testing.assert_allclose(comp, ref) + np.testing.assert_allclose(cmp_dot_product, ref_dot_product) return @@ -214,10 +214,10 @@ def test_pyfftw_sdp_multithreaded(): T = np.random.rand(2**5) Q = np.random.rand(2**4) - comp = sdp._pyfftw_sliding_dot_product(Q, T, n_threads=2) - ref = naive.rolling_window_dot_product(Q, T) + cmp_dot_product = sdp._pyfftw_sliding_dot_product(Q, T, n_threads=2) + ref_dot_product = naive.rolling_window_dot_product(Q, T) - np.testing.assert_allclose(comp, ref) + np.testing.assert_allclose(cmp_dot_product, ref_dot_product) return @@ -237,9 +237,9 @@ def test_pyfftw_sdp_multithreaded_longdouble(): T = np.random.rand(init_len) Q = np.random.rand(2**8) - comp = sdp_func(Q, T, n_threads=2) - ref = naive.rolling_window_dot_product(Q, T) + cmp_dot_product = sdp_func(Q, T, n_threads=2) + ref_dot_product = naive.rolling_window_dot_product(Q, T) - np.testing.assert_allclose(comp, ref) + np.testing.assert_allclose(cmp_dot_product, ref_dot_product) return From c207eb5a6d3c370712374ffa8c47f134765f64e7 Mon Sep 17 00:00:00 2001 From: Karthik Date: Wed, 18 Nov 2026 16:06:28 -0500 Subject: [PATCH 2/3] Use descriptive comparison prefixes in remaining tests --- tests/test_core.py | 316 ++++++++++++++++++++-------------------- tests/test_floss.py | 24 +-- tests/test_maamp.py | 20 ++- tests/test_precision.py | 16 +- 4 files changed, 193 insertions(+), 183 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 28589cfa3..df88d8a91 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -443,7 +443,7 @@ def test_compute_mean_std_multidimensional_chunked_many(Q, T): @pytest.mark.parametrize("Q, T", test_data) def test_calculate_squared_distance_profile(Q, T): m = Q.shape[0] - ref = ( + ref_distances = ( np.linalg.norm( core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1 ) @@ -457,7 +457,7 @@ def test_calculate_squared_distance_profile(Q, T): T_subseq_isconstant = core.rolling_isconstant(T, m) M_T, Σ_T = core.compute_mean_std(T, m) - cmp = core._calculate_squared_distance_profile( + cmp_distances = core._calculate_squared_distance_profile( m, QT, μ_Q, @@ -467,13 +467,13 @@ def test_calculate_squared_distance_profile(Q, T): Q_subseq_isconstant, T_subseq_isconstant, ) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) @pytest.mark.parametrize("Q, T", test_data) def test_calculate_distance_profile(Q, T): m = Q.shape[0] - ref = np.linalg.norm( + ref_distances = np.linalg.norm( core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1 ) @@ -484,7 +484,7 @@ def test_calculate_distance_profile(Q, T): T_subseq_isconstant = core.rolling_isconstant(T, m) M_T, Σ_T = core.compute_mean_std(T, m) - cmp = core.calculate_distance_profile( + cmp_distances = core.calculate_distance_profile( m, QT, μ_Q, @@ -494,17 +494,17 @@ def test_calculate_distance_profile(Q, T): Q_subseq_isconstant, T_subseq_isconstant, ) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) @pytest.mark.parametrize("Q, T", test_data) def test_mueen_calculate_distance_profile(Q, T): m = Q.shape[0] - ref = np.linalg.norm( + ref_distances = np.linalg.norm( core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1 ) - cmp = core.mueen_calculate_distance_profile(Q, T) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_distances = core.mueen_calculate_distance_profile(Q, T) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) @pytest.mark.parametrize("Q, T", test_data) @@ -512,11 +512,11 @@ def test_mass(Q, T): Q = Q.copy() T = T.copy() m = Q.shape[0] - ref = np.linalg.norm( + ref_distances = np.linalg.norm( core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1 ) - cmp = core.mass(Q, T) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_distances = core.mass(Q, T) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) @pytest.mark.parametrize("Q, T", test_data) @@ -526,13 +526,13 @@ def test_mass_Q_nan(Q, T): T = T.copy() m = Q.shape[0] - ref = np.linalg.norm( + ref_distances = np.linalg.norm( core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1 ) - ref[np.isnan(ref)] = np.inf + ref_distances[np.isnan(ref_distances)] = np.inf - cmp = core.mass(Q, T) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_distances = core.mass(Q, T) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) @pytest.mark.parametrize("Q, T", test_data) @@ -542,13 +542,13 @@ def test_mass_Q_inf(Q, T): T = T.copy() m = Q.shape[0] - ref = np.linalg.norm( + ref_distances = np.linalg.norm( core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1 ) - ref[np.isnan(ref)] = np.inf + ref_distances[np.isnan(ref_distances)] = np.inf - cmp = core.mass(Q, T) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_distances = core.mass(Q, T) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) T[1] = 1e10 @@ -559,13 +559,13 @@ def test_mass_T_nan(Q, T): T[1] = np.nan m = Q.shape[0] - ref = np.linalg.norm( + ref_distances = np.linalg.norm( core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1 ) - ref[np.isnan(ref)] = np.inf + ref_distances[np.isnan(ref_distances)] = np.inf - cmp = core.mass(Q, T) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_distances = core.mass(Q, T) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) @pytest.mark.parametrize("Q, T", test_data) @@ -575,13 +575,13 @@ def test_mass_T_inf(Q, T): T[1] = np.inf m = Q.shape[0] - ref = np.linalg.norm( + ref_distances = np.linalg.norm( core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1 ) - ref[np.isnan(ref)] = np.inf + ref_distances[np.isnan(ref_distances)] = np.inf - cmp = core.mass(Q, T) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_distances = core.mass(Q, T) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) T[1] = 1e10 @@ -591,15 +591,15 @@ def test_p_norm_distance_profile(Q, T): T = T.copy() m = Q.shape[0] for p in [1.0, 1.5, 2.0]: - ref = cdist( + ref_distances = cdist( core.rolling_window(Q, m), core.rolling_window(T, m), metric="minkowski", p=p, ).flatten() - ref = np.power(ref, p) - cmp = core._p_norm_distance_profile(Q, T, p) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + ref_distances = np.power(ref_distances, p) + cmp_distances = core._p_norm_distance_profile(Q, T, p) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) @pytest.mark.parametrize("Q, T", test_data) @@ -608,9 +608,9 @@ def test_mass_absolute(Q, T): T = T.copy() m = Q.shape[0] for p in [1.0, 2.0, 3.0]: - ref = np.linalg.norm(core.rolling_window(T, m) - Q, axis=1, ord=p) - cmp = core.mass_absolute(Q, T, p=p) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + ref_distances = np.linalg.norm(core.rolling_window(T, m) - Q, axis=1, ord=p) + cmp_distances = core.mass_absolute(Q, T, p=p) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) @pytest.mark.parametrize("Q, T", test_data) @@ -620,11 +620,11 @@ def test_mass_absolute_Q_nan(Q, T): T = T.copy() m = Q.shape[0] - ref = np.linalg.norm(core.rolling_window(T, m) - Q, axis=1) - ref[np.isnan(ref)] = np.inf + ref_distances = np.linalg.norm(core.rolling_window(T, m) - Q, axis=1) + ref_distances[np.isnan(ref_distances)] = np.inf - cmp = core.mass_absolute(Q, T) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_distances = core.mass_absolute(Q, T) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) @pytest.mark.parametrize("Q, T", test_data) @@ -634,11 +634,11 @@ def test_mass_absolute_Q_inf(Q, T): T = T.copy() m = Q.shape[0] - ref = np.linalg.norm(core.rolling_window(T, m) - Q, axis=1) - ref[np.isnan(ref)] = np.inf + ref_distances = np.linalg.norm(core.rolling_window(T, m) - Q, axis=1) + ref_distances[np.isnan(ref_distances)] = np.inf - cmp = core.mass_absolute(Q, T) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_distances = core.mass_absolute(Q, T) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) @pytest.mark.parametrize("Q, T", test_data) @@ -648,11 +648,11 @@ def test_mass_absolute_T_nan(Q, T): T[1] = np.nan m = Q.shape[0] - ref = np.linalg.norm(core.rolling_window(T, m) - Q, axis=1) - ref[np.isnan(ref)] = np.inf + ref_distances = np.linalg.norm(core.rolling_window(T, m) - Q, axis=1) + ref_distances[np.isnan(ref_distances)] = np.inf - cmp = core.mass_absolute(Q, T) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_distances = core.mass_absolute(Q, T) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) @pytest.mark.parametrize("Q, T", test_data) @@ -662,11 +662,11 @@ def test_mass_absolute_T_inf(Q, T): T[1] = np.inf m = Q.shape[0] - ref = np.linalg.norm(core.rolling_window(T, m) - Q, axis=1) - ref[np.isnan(ref)] = np.inf + ref_distances = np.linalg.norm(core.rolling_window(T, m) - Q, axis=1) + ref_distances[np.isnan(ref_distances)] = np.inf - cmp = core.mass_absolute(Q, T) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_distances = core.mass_absolute(Q, T) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) def test_mass_absolute_sqrt_input_negative(): @@ -724,9 +724,9 @@ def test_mass_absolute_sqrt_input_negative(): -9.71, ] ) - ref = 0.0 - cmp = core.mass_absolute(Q, Q) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + ref_distances = 0.0 + cmp_distances = core.mass_absolute(Q, Q) + npt.assert_allclose(cmp_distances, ref_distances, atol=1.5e-07) @pytest.mark.parametrize("T_A, T_B", test_data) @@ -759,56 +759,56 @@ def test_mass_absolute_distance_matrix(T_A, T_B): def test_apply_exclusion_zone(): T = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=np.float64) - ref = np.empty(T.shape, dtype=np.float64) - cmp = np.empty(T.shape, dtype=np.float64) + ref_values = np.empty(T.shape, dtype=np.float64) + cmp_values = np.empty(T.shape, dtype=np.float64) exclusion_zone = 2 for i in range(T.shape[0]): - ref[:] = T[:] - naive.apply_exclusion_zone(ref, i, exclusion_zone, np.inf) + ref_values[:] = T[:] + naive.apply_exclusion_zone(ref_values, i, exclusion_zone, np.inf) - cmp[:] = T[:] - core.apply_exclusion_zone(cmp, i, exclusion_zone, np.inf) + cmp_values[:] = T[:] + core.apply_exclusion_zone(cmp_values, i, exclusion_zone, np.inf) - naive.replace_inf(ref) - naive.replace_inf(cmp) - npt.assert_array_equal(cmp, ref) + naive.replace_inf(ref_values) + naive.replace_inf(cmp_values) + npt.assert_array_equal(cmp_values, ref_values) def test_apply_exclusion_zone_int(): T = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=np.int64) - ref = np.empty(T.shape, dtype=np.int64) - cmp = np.empty(T.shape, dtype=np.int64) + ref_values = np.empty(T.shape, dtype=np.int64) + cmp_values = np.empty(T.shape, dtype=np.int64) exclusion_zone = 2 for i in range(T.shape[0]): - ref[:] = T[:] - naive.apply_exclusion_zone(ref, i, exclusion_zone, -1) + ref_values[:] = T[:] + naive.apply_exclusion_zone(ref_values, i, exclusion_zone, -1) - cmp[:] = T[:] - core.apply_exclusion_zone(cmp, i, exclusion_zone, -1) + cmp_values[:] = T[:] + core.apply_exclusion_zone(cmp_values, i, exclusion_zone, -1) - naive.replace_inf(ref) - naive.replace_inf(cmp) - npt.assert_array_equal(cmp, ref) + naive.replace_inf(ref_values) + naive.replace_inf(cmp_values) + npt.assert_array_equal(cmp_values, ref_values) def test_apply_exclusion_zone_bool(): T = np.ones(10, dtype=bool) - ref = np.empty(T.shape, dtype=bool) - cmp = np.empty(T.shape, dtype=bool) + ref_values = np.empty(T.shape, dtype=bool) + cmp_values = np.empty(T.shape, dtype=bool) exclusion_zone = 2 for i in range(T.shape[0]): - ref[:] = T[:] - naive.apply_exclusion_zone(ref, i, exclusion_zone, False) + ref_values[:] = T[:] + naive.apply_exclusion_zone(ref_values, i, exclusion_zone, False) - cmp[:] = T[:] - core.apply_exclusion_zone(cmp, i, exclusion_zone, False) + cmp_values[:] = T[:] + core.apply_exclusion_zone(cmp_values, i, exclusion_zone, False) - naive.replace_inf(ref) - naive.replace_inf(cmp) - npt.assert_array_equal(cmp, ref) + naive.replace_inf(ref_values) + naive.replace_inf(cmp_values) + npt.assert_array_equal(cmp_values, ref_values) def test_apply_exclusion_zone_multidimensional(): @@ -816,20 +816,20 @@ def test_apply_exclusion_zone_multidimensional(): [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], dtype=np.float64, ) - ref = np.empty(T.shape, dtype=np.float64) - cmp = np.empty(T.shape, dtype=np.float64) + ref_values = np.empty(T.shape, dtype=np.float64) + cmp_values = np.empty(T.shape, dtype=np.float64) exclusion_zone = 2 for i in range(T.shape[1]): - ref[:, :] = T[:, :] - naive.apply_exclusion_zone(ref, i, exclusion_zone, np.inf) + ref_values[:, :] = T[:, :] + naive.apply_exclusion_zone(ref_values, i, exclusion_zone, np.inf) - cmp[:, :] = T[:, :] - core.apply_exclusion_zone(cmp, i, exclusion_zone, np.inf) + cmp_values[:, :] = T[:, :] + core.apply_exclusion_zone(cmp_values, i, exclusion_zone, np.inf) - naive.replace_inf(ref) - naive.replace_inf(cmp) - npt.assert_array_equal(cmp, ref) + naive.replace_inf(ref_values) + naive.replace_inf(cmp_values) + npt.assert_array_equal(cmp_values, ref_values) def test_preprocess(): @@ -955,72 +955,74 @@ def test_count_diagonal_ndist(): def test_get_array_ranges(): x = np.array([3, 9, 2, 1, 5, 4, 7, 7, 8, 6], dtype=np.int64) for n_chunks in range(2, 5): - ref = naive.get_array_ranges(x, n_chunks, False) + ref_ranges = naive.get_array_ranges(x, n_chunks, False) - cmp = core._get_array_ranges(x, n_chunks, False) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_ranges = core._get_array_ranges(x, n_chunks, False) + npt.assert_allclose(cmp_ranges, ref_ranges, atol=1.5e-07) def test_get_array_ranges_exhausted(): x = np.array([3, 3, 3, 11, 11, 11], dtype=np.int64) n_chunks = 6 - ref = naive.get_array_ranges(x, n_chunks, False) + ref_ranges = naive.get_array_ranges(x, n_chunks, False) - cmp = core._get_array_ranges(x, n_chunks, False) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_ranges = core._get_array_ranges(x, n_chunks, False) + npt.assert_allclose(cmp_ranges, ref_ranges, atol=1.5e-07) def test_get_array_ranges_exhausted_truncated(): x = np.array([3, 3, 3, 11, 11, 11], dtype=np.int64) n_chunks = 6 - ref = naive.get_array_ranges(x, n_chunks, True) + ref_ranges = naive.get_array_ranges(x, n_chunks, True) - cmp = core._get_array_ranges(x, n_chunks, True) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_ranges = core._get_array_ranges(x, n_chunks, True) + npt.assert_allclose(cmp_ranges, ref_ranges, atol=1.5e-07) def test_get_array_ranges_empty_array(): x = np.array([], dtype=np.int64) n_chunks = 6 - ref = naive.get_array_ranges(x, n_chunks, False) + ref_ranges = naive.get_array_ranges(x, n_chunks, False) - cmp = core._get_array_ranges(x, n_chunks, False) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_ranges = core._get_array_ranges(x, n_chunks, False) + npt.assert_allclose(cmp_ranges, ref_ranges, atol=1.5e-07) def test_get_ranges(): - ref = np.array([[0, 3], [3, 6]]) + ref_ranges = np.array([[0, 3], [3, 6]]) size = 6 n_chunks = 2 - cmp = core._get_ranges(size, n_chunks, False) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_ranges = core._get_ranges(size, n_chunks, False) + npt.assert_allclose(cmp_ranges, ref_ranges, atol=1.5e-07) def test_get_ranges_exhausted(): - ref = np.array([[0, 1], [1, 2], [2, 3], [3, 3], [3, 4], [4, 5], [5, 6], [6, 6]]) + ref_ranges = np.array( + [[0, 1], [1, 2], [2, 3], [3, 3], [3, 4], [4, 5], [5, 6], [6, 6]] + ) size = 6 n_chunks = 8 - cmp = core._get_ranges(size, n_chunks, False) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_ranges = core._get_ranges(size, n_chunks, False) + npt.assert_allclose(cmp_ranges, ref_ranges, atol=1.5e-07) def test_get_ranges_exhausted_truncated(): - ref = np.array([[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) + ref_ranges = np.array([[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) size = 6 n_chunks = 8 - cmp = core._get_ranges(size, n_chunks, True) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_ranges = core._get_ranges(size, n_chunks, True) + npt.assert_allclose(cmp_ranges, ref_ranges, atol=1.5e-07) def test_get_ranges_zero_size(): - ref = np.empty((0, 2)) + ref_ranges = np.empty((0, 2)) size = 0 n_chunks = 8 - cmp = core._get_ranges(size, n_chunks, True) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_ranges = core._get_ranges(size, n_chunks, True) + npt.assert_allclose(cmp_ranges, ref_ranges, atol=1.5e-07) def test_rolling_isfinite(): @@ -1031,14 +1033,14 @@ def test_rolling_isfinite(): a[5] = np.nan a[9] = np.nan - ref = np.all(core.rolling_window(np.isfinite(a), w), axis=1) - cmp = core.rolling_isfinite(a, w) + ref_isfinite = np.all(core.rolling_window(np.isfinite(a), w), axis=1) + cmp_isfinite = core.rolling_isfinite(a, w) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + npt.assert_allclose(cmp_isfinite, ref_isfinite, atol=1.5e-07) # test `a` as all boolean isfinite array - cmp = core.rolling_isfinite(np.isfinite(a), w) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_isfinite = core.rolling_isfinite(np.isfinite(a), w) + npt.assert_allclose(cmp_isfinite, ref_isfinite, atol=1.5e-07) def test_rolling_isconstant(): @@ -1050,10 +1052,10 @@ def test_rolling_isconstant(): a[4:7] = 77.0 a[9:12] = [77.0, np.nan, 77.0] - ref = naive.rolling_isconstant(a, w) - cmp = core.rolling_isconstant(a, w) + ref_isconstant = naive.rolling_isconstant(a, w) + cmp_isconstant = core.rolling_isconstant(a, w) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + npt.assert_allclose(cmp_isconstant, ref_isconstant, atol=1.5e-07) def test_compare_parameters(): @@ -1065,28 +1067,28 @@ def test_compare_parameters(): def test_jagged_list_to_array(): arr = [np.array([0, 1]), np.array([0]), np.array([0, 1, 2, 3])] - ref = np.array([[0, 1, -1, -1], [0, -1, -1, -1], [0, 1, 2, 3]], dtype="int64") - cmp = core._jagged_list_to_array(arr, fill_value=-1, dtype="int64") - npt.assert_array_equal(cmp, ref) + ref_array = np.array([[0, 1, -1, -1], [0, -1, -1, -1], [0, 1, 2, 3]], dtype="int64") + cmp_array = core._jagged_list_to_array(arr, fill_value=-1, dtype="int64") + npt.assert_array_equal(cmp_array, ref_array) - ref = np.array( + ref_array = np.array( [[0, 1, np.nan, np.nan], [0, np.nan, np.nan, np.nan], [0, 1, 2, 3]], dtype="float64", ) - cmp = core._jagged_list_to_array(arr, fill_value=np.nan, dtype="float64") - npt.assert_array_equal(cmp, ref) + cmp_array = core._jagged_list_to_array(arr, fill_value=np.nan, dtype="float64") + npt.assert_array_equal(cmp_array, ref_array) def test_jagged_list_to_array_empty(): arr = [] - ref = np.array([[]], dtype="int64") - cmp = core._jagged_list_to_array(arr, fill_value=-1, dtype="int64") - npt.assert_array_equal(cmp, ref) + ref_array = np.array([[]], dtype="int64") + cmp_array = core._jagged_list_to_array(arr, fill_value=-1, dtype="int64") + npt.assert_array_equal(cmp_array, ref_array) - ref = np.array([[]], dtype="float64") - cmp = core._jagged_list_to_array(arr, fill_value=np.nan, dtype="float64") - npt.assert_array_equal(cmp, ref) + ref_array = np.array([[]], dtype="float64") + cmp_array = core._jagged_list_to_array(arr, fill_value=np.nan, dtype="float64") + npt.assert_array_equal(cmp_array, ref_array) def test_get_mask_slices(): @@ -1177,10 +1179,10 @@ def test_select_P_ABBA_val_inf(): P_ABBA[k:] = np.inf p_abba = P_ABBA.copy() - cmp = core._select_P_ABBA_value(P_ABBA, k=k) + cmp_value = core._select_P_ABBA_value(P_ABBA, k=k) p_abba.sort() - ref = p_abba[k - 1] - npt.assert_allclose(cmp, ref, atol=1.5e-07) + ref_value = p_abba[k - 1] + npt.assert_allclose(cmp_value, ref_value, atol=1.5e-07) def test_merge_topk_PI_without_overlap(): @@ -1436,35 +1438,35 @@ def test_merge_topk_ρI_with_1D_input_hardcoded(): def test_shift_insert_at_index(): for k in range(1, 6): a = rng.RNG.rand(k) - ref = np.empty(k, dtype=np.float64) - cmp = np.empty(k, dtype=np.float64) + ref_values = np.empty(k, dtype=np.float64) + cmp_values = np.empty(k, dtype=np.float64) indices = np.arange(k + 1) values = rng.RNG.rand(k + 1) # test shift = "right" for idx, v in zip(indices, values): - ref[:] = a - cmp[:] = a + ref_values[:] = a + cmp_values[:] = a - ref = np.insert(ref, idx, v)[:-1] + ref_values = np.insert(ref_values, idx, v)[:-1] core._shift_insert_at_index( - cmp, idx, v, shift="right" - ) # update cmp in place + cmp_values, idx, v, shift="right" + ) # update cmp_values in place - npt.assert_allclose(cmp, ref, atol=1.5e-07) + npt.assert_allclose(cmp_values, ref_values, atol=1.5e-07) # test shift = "left" for idx, v in zip(indices, values): - ref[:] = a - cmp[:] = a + ref_values[:] = a + cmp_values[:] = a - ref = np.insert(ref, idx, v)[1:] + ref_values = np.insert(ref_values, idx, v)[1:] core._shift_insert_at_index( - cmp, idx, v, shift="left" - ) # update cmp in place + cmp_values, idx, v, shift="left" + ) # update cmp_values in place - npt.assert_allclose(cmp, ref, atol=1.5e-07) + npt.assert_allclose(cmp_values, ref_values, atol=1.5e-07) def test_check_P(): @@ -1477,11 +1479,11 @@ def test_find_matches_all(): max_distance = np.inf D = rng.RNG.rand(64) for excl_zone in range(3): - ref = naive.find_matches(D, excl_zone, max_distance, max_matches=None) - cmp = core._find_matches(D, excl_zone, max_distance, max_matches=None) + ref_matches = naive.find_matches(D, excl_zone, max_distance, max_matches=None) + cmp_matches = core._find_matches(D, excl_zone, max_distance, max_matches=None) npt.assert_allclose( - cmp.astype(np.float64), ref.astype(np.float64), atol=1.5e-07 + cmp_matches.astype(np.float64), ref_matches.astype(np.float64), atol=1.5e-07 ) @@ -1490,11 +1492,11 @@ def test_find_matches_maxmatch(): D = rng.RNG.rand(64) for excl_zone in range(3): max_matches = rng.RNG.randint(0, 100) - ref = naive.find_matches(D, excl_zone, max_distance, max_matches) - cmp = core._find_matches(D, excl_zone, max_distance, max_matches) + ref_matches = naive.find_matches(D, excl_zone, max_distance, max_matches) + cmp_matches = core._find_matches(D, excl_zone, max_distance, max_matches) npt.assert_allclose( - cmp.astype(np.float64), ref.astype(np.float64), atol=1.5e-07 + cmp_matches.astype(np.float64), ref_matches.astype(np.float64), atol=1.5e-07 ) diff --git a/tests/test_floss.py b/tests/test_floss.py index 7ff58a32e..689974266 100644 --- a/tests/test_floss.py +++ b/tests/test_floss.py @@ -102,9 +102,9 @@ def naive_rea(cac, n_regimes, L, excl_factor): @pytest.mark.parametrize("I", test_data) def test_nnmark(I): - ref = naive_nnmark(I) - cmp = _nnmark(I) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + ref_marks = naive_nnmark(I) + cmp_marks = _nnmark(I) + npt.assert_allclose(cmp_marks, ref_marks, atol=1.5e-07) @pytest.mark.parametrize("I", test_data) @@ -112,21 +112,21 @@ def test_cac(I): L = 5 excl_factor = 1 custom_iac = _iac(I.shape[0]) - ref = naive_cac(I, L, excl_factor, custom_iac) + ref_cac = naive_cac(I, L, excl_factor, custom_iac) bidirectional = True - cmp = _cac(I, L, bidirectional, excl_factor) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_cac = _cac(I, L, bidirectional, excl_factor) + npt.assert_allclose(cmp_cac, ref_cac, atol=1.5e-07) @pytest.mark.parametrize("I", test_data) def test_cac_custom_iac(I): L = 5 excl_factor = 1 - ref = naive_cac(I, L, excl_factor) + ref_cac = naive_cac(I, L, excl_factor) custom_iac = naive_iac(I.shape[0]) bidirectional = True - cmp = _cac(I, L, bidirectional, excl_factor, custom_iac) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + cmp_cac = _cac(I, L, bidirectional, excl_factor, custom_iac) + npt.assert_allclose(cmp_cac, ref_cac, atol=1.5e-07) @pytest.mark.parametrize("I", test_data) @@ -135,9 +135,9 @@ def test_rea(I): excl_factor = 1 cac = naive_cac(I, L, excl_factor) n_regimes = 3 - ref = naive_rea(cac, n_regimes, L, excl_factor) - cmp = _rea(cac, n_regimes, L, excl_factor) - npt.assert_allclose(cmp, ref, atol=1.5e-07) + ref_regimes = naive_rea(cac, n_regimes, L, excl_factor) + cmp_regimes = _rea(cac, n_regimes, L, excl_factor) + npt.assert_allclose(cmp_regimes, ref_regimes, atol=1.5e-07) @pytest.mark.parametrize("I", test_data) diff --git a/tests/test_maamp.py b/tests/test_maamp.py index c91589266..c48657b88 100644 --- a/tests/test_maamp.py +++ b/tests/test_maamp.py @@ -34,14 +34,16 @@ def test_multi_mass_absolute_seeded(): Q = T[:, trivial_idx : trivial_idx + m] - ref = naive.multi_mass_absolute(Q, T, m) + ref_distances = naive.multi_mass_absolute(Q, T, m) T, T_subseq_isfinite = core.preprocess_non_normalized(T, m) - cmp = _multi_mass_absolute( + cmp_distances = _multi_mass_absolute( Q, T, m, T_subseq_isfinite[:, trivial_idx], T_subseq_isfinite ) - npt.assert_allclose(cmp, ref, atol=1.5 * 10**-config.STUMPY_TEST_PRECISION) + npt.assert_allclose( + cmp_distances, ref_distances, atol=1.5 * 10**-config.STUMPY_TEST_PRECISION + ) @pytest.mark.parametrize("T, m", test_data) @@ -51,14 +53,16 @@ def test_multi_mass_absolute(T, m): Q = T[:, trivial_idx : trivial_idx + m] for p in [1.0, 2.0, 3.0]: - ref = naive.multi_mass_absolute(Q, T, m, p=p) + ref_distances = naive.multi_mass_absolute(Q, T, m, p=p) _T, T_subseq_isfinite = core.preprocess_non_normalized(T, m) - cmp = _multi_mass_absolute( + cmp_distances = _multi_mass_absolute( Q, _T, m, T_subseq_isfinite[:, trivial_idx], T_subseq_isfinite, p=p ) - npt.assert_allclose(cmp, ref, atol=1.5 * 10**-config.STUMPY_TEST_PRECISION) + npt.assert_allclose( + cmp_distances, ref_distances, atol=1.5 * 10**-config.STUMPY_TEST_PRECISION + ) @pytest.mark.parametrize("T, m", test_data) @@ -157,8 +161,8 @@ def test_maamp_mdl(T, m): cmp_MDL, cmp_S = maamp_mdl(T, m, subseq_idx, nn_idx, p=p) npt.assert_allclose(cmp_MDL, ref_MDL, atol=1.5e-07) - for ref, cmp in zip(ref_S, cmp_S): - npt.assert_allclose(cmp, ref, atol=1.5e-07) + for ref_subspace, cmp_subspace in zip(ref_S, cmp_S): + npt.assert_allclose(cmp_subspace, ref_subspace, atol=1.5e-07) def test_naive_maamp(): diff --git a/tests/test_precision.py b/tests/test_precision.py index 4a973b263..a7c58c99b 100644 --- a/tests/test_precision.py +++ b/tests/test_precision.py @@ -115,10 +115,12 @@ def test_calculate_squared_distance(): T_subseq_isconstant[i], ) - cmp = dist_ij - dist_ji - ref = 0.0 + cmp_distance_difference = dist_ij - dist_ji + ref_distance_difference = 0.0 - npt.assert_allclose(cmp, ref, atol=1.5e-14) + npt.assert_allclose( + cmp_distance_difference, ref_distance_difference, atol=1.5e-14 + ) @pytest.mark.parametrize( @@ -213,7 +215,9 @@ def test_distance_symmetry_property_in_gpu(): d_ij = mp_AB[0, 0] d_ji = mp_BA[0, 0] - cmp = d_ij - d_ji - ref = 0.0 + cmp_distance_difference = d_ij - d_ji + ref_distance_difference = 0.0 - npt.assert_allclose(cmp, ref, atol=1.5e-15) + npt.assert_allclose( + cmp_distance_difference, ref_distance_difference, atol=1.5e-15 + ) From 7a80a3adb1c5a8a9dd232cfebe469f5e7ab48ce7 Mon Sep 17 00:00:00 2001 From: Karthik Date: Fri, 20 Nov 2026 15:40:57 -0500 Subject: [PATCH 3/3] Add explicit absolute tolerance to SDP comparisons --- tests/test_sdp.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_sdp.py b/tests/test_sdp.py index 5b2ad64fd..ecebc99d5 100644 --- a/tests/test_sdp.py +++ b/tests/test_sdp.py @@ -122,7 +122,7 @@ def test_sdp(n_T, remainder, comparator): func = getattr(sdp, func_name) try: cmp_dot_product = func(Q, T) - npt.assert_allclose(cmp_dot_product, ref_dot_product) + npt.assert_allclose(cmp_dot_product, ref_dot_product, atol=1.5e-07) except Exception as e: # pragma: no cover msg = f"Error in {func_name}, with n_Q={n_Q} and n_T={n_T}" warnings.warn(msg) @@ -146,7 +146,7 @@ def test_sdp_power2(): ref_dot_product = naive.rolling_window_dot_product(Q, T) cmp_dot_product = func(Q, T) - npt.assert_allclose(cmp_dot_product, ref_dot_product) + npt.assert_allclose(cmp_dot_product, ref_dot_product, atol=1.5e-07) except Exception as e: # pragma: no cover msg = f"Error in {func_name}, with q={q} and p={p}" @@ -176,7 +176,7 @@ def test_pyfftw_sdp_init_len(): cmp_dot_product = _pyfftw_sliding_dot_product(Q, T) ref_dot_product = naive.rolling_window_dot_product(Q, T) - np.testing.assert_allclose(cmp_dot_product, ref_dot_product) + np.testing.assert_allclose(cmp_dot_product, ref_dot_product, atol=1.5e-07) return @@ -199,7 +199,7 @@ def test_pyfftw_sdp_longdoube(): cmp_dot_product = sdp_func(Q, T) ref_dot_product = naive.rolling_window_dot_product(Q, T) - np.testing.assert_allclose(cmp_dot_product, ref_dot_product) + np.testing.assert_allclose(cmp_dot_product, ref_dot_product, atol=1.5e-07) return @@ -217,7 +217,7 @@ def test_pyfftw_sdp_multithreaded(): cmp_dot_product = sdp._pyfftw_sliding_dot_product(Q, T, n_threads=2) ref_dot_product = naive.rolling_window_dot_product(Q, T) - np.testing.assert_allclose(cmp_dot_product, ref_dot_product) + np.testing.assert_allclose(cmp_dot_product, ref_dot_product, atol=1.5e-07) return @@ -240,6 +240,6 @@ def test_pyfftw_sdp_multithreaded_longdouble(): cmp_dot_product = sdp_func(Q, T, n_threads=2) ref_dot_product = naive.rolling_window_dot_product(Q, T) - np.testing.assert_allclose(cmp_dot_product, ref_dot_product) + np.testing.assert_allclose(cmp_dot_product, ref_dot_product, atol=1.5e-07) return