Migrate tests/test_core.py to npt.assert_allclose - #1188
Open
viknesh-ai wants to merge 1 commit into
Open
Conversation
|
Review these changes at https://app.gitnotebooks.com/stumpy-dev/stumpy/pull/1188 |
Contributor
Author
|
@seanlaw next file in the split — same conventions as the previous PRs. Ready for review whenever you have time. |
seanlaw
requested changes
Aug 17, 2026
seanlaw
left a comment
Contributor
There was a problem hiding this comment.
For assert_array_equal, please also ensure that switch cmp is first and ref is second
| cmp_T_subseq_isconstant = core.process_isconstant(T, m, T_subseq_isconstant=None) | ||
|
|
||
| npt.assert_array_equal(T_subseq_isconstant_ref, T_subseq_isconstant_comp) | ||
| npt.assert_array_equal(ref_T_subseq_isconstant, cmp_T_subseq_isconstant) |
Contributor
There was a problem hiding this comment.
npt.assert_allclose and switch ref/cmp order
| naive.replace_inf(comp) | ||
| npt.assert_array_equal(ref, comp) | ||
| naive.replace_inf(cmp) | ||
| npt.assert_array_equal(ref, cmp) |
| naive.replace_inf(comp) | ||
| npt.assert_array_equal(ref, comp) | ||
| naive.replace_inf(cmp) | ||
| npt.assert_array_equal(ref, cmp) |
| naive.replace_inf(comp) | ||
| npt.assert_array_equal(ref, comp) | ||
| naive.replace_inf(cmp) | ||
| npt.assert_array_equal(ref, cmp) |
| naive.replace_inf(comp) | ||
| npt.assert_array_equal(ref, comp) | ||
| naive.replace_inf(cmp) | ||
| npt.assert_array_equal(ref, cmp) |
| comp_slices = core._get_mask_slices(mask) | ||
| npt.assert_array_equal(ref_slices, comp_slices) | ||
| cmp_slices = core._get_mask_slices(mask) | ||
| npt.assert_array_equal(ref_slices, cmp_slices) |
| comp_IDX = device_comp_IDX.copy_to_host() | ||
| npt.assert_array_equal(ref_IDX, comp_IDX) | ||
| cmp_IDX = device_cmp_IDX.copy_to_host() | ||
| npt.assert_array_equal(ref_IDX, cmp_IDX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #1175
Continuing the file-by-file split — this one covers
tests/test_core.py. Largest and messiest file in the split so far: 131 call sites, and unlike the other files, the naming here was inconsistent throughout (some pairsref/comp, someref/cmp, someref_X/comp_X, and a few reversed as suffix forms likeP_ref/P_comp,I_ref/I_comp).assert_almost_equalonly checks a fixed absolute tolerance and NumPy's docs recommendassert_allcloseinstead. What changed:ref_X/cmp_Xprefix convention, including the reversed suffix forms (P_ref/P_comp->ref_P/cmp_P,I_ref/I_comp->ref_I/cmp_I,mp_ref->ref_mp, etc.) and a couple ofcomp-not-cmpstragglers. Did a token-level rename (not a blind substring replace) to avoid clobbering unrelated words likecompare/compute/comparisonin comments.(ref, comp)order, so every one needed flipping to(cmp_side, ref_side).decimal=or referencedconfig.STUMPY_TEST_PRECISION— all used numpy's implicitdecimal=7default, so all 131 use the literalatol=1.5e-07.naive.*source feeding aref_side before touching anything. Onlynaive.find_matches/core._find_matches(2 call sites, intest_find_matches_all/test_find_matches_maxmatch) come backdtype=object(a[distance, index]pair array, same root cause as the earlier files) — cast both sides tofloat64there. Everywhere else the naive source (compute_mean_std,rolling_nanstd,distance_matrix,rolling_isconstant,get_array_ranges,rolling_window_dot_product,merge_topk_PI/merge_topk_ρI, and this file's own localnaive_idx_to_mp/naive_bfs_indiceshelpers) is already cleanfloat64/int64, so no unnecessary casting was added.ref_/cmp_naming fix to a handful ofnpt.assert_array_equalcalls that shared the same inconsistent naming (test_apply_exclusion_zone*,test_get_mask_slices,test_gpu_searchsorted,test_process_isconstant_*), per the standing rule that this convention applies toassert_array_equaltoo, not justassert_allclose.naive.*pair (test_array_to_temp_file, a value round-tripped throughcore.array_to_temp_file+np.load) got the same treatment: the original value isref_val, the round-tripped value iscmp_val. Left the unrelatedleft/rightpairs intest_jagged_list_to_array*/test_replace_distanceuntouched since those aren't naive-vs-stumpy comparisons and are out of scope for this migration.# npt.assert_almost_equal(...)lines got their syntax updated too for consistency, staying commented.Ran the full file twice locally (normal mode and JIT-disabled/CUDA-simulated, matching
test.sh coverage) — 244 passed + 1 skipped (GPU test, no CUDA available locally) in normal mode, 245 passed in CI-equivalent mode (the GPU test runs under the CUDA simulator there).To Do List
Standing checklist from @seanlaw for this migration, applies to every file in the split - status below is for
test_core.py:npt.assert_almost_equalwith its equivalentnpt.assert_allclosertol=0fornpt.assert_allclose, simply omit this parameter and value since this is the defaultnpt.assert_allclose(actual, desired)always has the stumpy computed value asactualand the naive computation asdesiredatol=1.5e-07rather thanatol=1.5*10**-07- applies to all 131 sites here (none referencedconfig.STUMPY_TEST_PRECISION)1.5*10**-config.STUMPY_TEST_PRECISIONwithconfig.STUMPY_TEST_PRECISION = 1.5e-07(inconfig.py) - tracked as a follow-up, not part of this per-file migration (n/a for this specific file, but keeping the item open since it's still pending overall)cmpinstead ofcomp- this file had severalcomp/comp_Xstragglers, all renamedref_and stumpy-computed outputs tocmp_(applies tonpt.assert_array_equaltoo) - this file had the most inconsistent naming of the series (including reversed suffix forms likeP_ref/P_comp), fully normalizedPull Request Checklist
Below is a simple checklist but please do not hesitate to ask for assistance!
black(i.e.,python -m pip install blackorconda install -c conda-forge black)flake8(i.e.,python -m pip install flake8orconda install -c conda-forge flake8)pytest-cov(i.e.,python -m pip install pytest-covorconda install -c conda-forge pytest-cov)black --exclude=".*\.ipynb" --extend-exclude=".venv" --diff ./in the root stumpy directoryflake8 --extend-exclude=.venv ./in the root stumpy directory./setup.sh dev && ./test.shin the root stumpy directory and ensured that all tests are passing locallyPlease do not commit any code to avoid/circumvent a failing test and, instead, engage in a discussion (below) to determine the best course of action.
Only request a review after the checklist above is fully completed!