focal: speed up test_focal.py + test_proximity.py (#1931)#1939
Merged
Conversation
- Mock _available_memory_bytes in the three #1284 oversize-kernel tests so they trip the guard with a tiny kernel instead of allocating 10 GB of np.ones. Saves ~14 s on the suite. - Drop unused data_random_sparse / data_gaussian module-level globals and the helpers that built them; shrink data_random from 100x100 to 40x40 since the mean-transfer-function tests don't need that scale. - Use chunks=(20, 20) instead of chunks=(3, 3) for the dask mean tests so the dask graph has a handful of chunks instead of 1156. - Trim the (size, chunks) matrix in the four boundary parity tests (convolution_2d / mean / apply / hotspots) from 4-5 cases to 3, keeping small / medium / chunk-equals-array coverage. Local wall-clock for test_focal.py + test_proximity.py drops from 67 s to 32 s on the same hardware (~53%).
Contributor
There was a problem hiding this comment.
Pull request overview
Test-only speedup for xrspatial/tests/test_focal.py. Reduces wall-clock by patching the memory probe instead of allocating a real 10 GB kernel in the oversize-kernel regression tests, removes unused fixtures, shrinks data_random, uses larger dask chunks, and trims redundant (size, chunks) parametrize combinations.
Changes:
- Patch
_available_memory_bytesin three*_rejects_oversize_kernel_1284tests so a small (101, 101) kernel still trips the guard. - Drop unused
data_random_sparse/data_gaussianhelpers; shrinkdata_randomto 40x40; bump dask chunks from (3, 3) to (20, 20). - Trim
(size, chunks)matrix in 4 boundary parity tests from 4-5 cases to 3.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Fixes #1931. Local wall-clock for
test_focal.py+test_proximity.pydrops from ~67 s to ~32 s on the same hardware, roughly 53% faster, with no loss of functional coverage.Changes, all in
xrspatial/tests/test_focal.py:#1284oversize-kernel tests (apply,focal_stats,hotspots) used to allocate a(50001, 50001)float32kernel just to trip the memory guard. Thenp.onescall alone takes ~5 s and pins 10 GB of RAM. They now patchxrspatial.focal._available_memory_bytesto return 1 and use a small(101, 101)kernel. The guard still fires and the error message still gets matched.data_random_sparseanddata_gaussianand the helpers that built them. Nothing in the suite referenced either.data_randomfrom100x100to40x40, and switch the dask mean-transfer tests fromchunks=(3, 3)tochunks=(20, 20)so the graphs have a handful of chunks instead of 1156.(size, chunks)parametrize matrix in the four boundary parity tests (convolution_2d,mean,apply,hotspots) from 4-5 cases to 3, keeping small, medium, and chunk-equals-array coverage.The 20 fewer collected test items all came from redundant
(size, chunks)combinations that asserted the same numpy-vs-dask parity at different mid-range shapes.Test plan
pytest xrspatial/tests/test_focal.py xrspatial/tests/test_proximity.pypasses locally (183 passed, was 203)*_rejects_oversize_kernel_1284tests still raiseMemoryErrorwith the right message*_boundary_numpy_equals_dasktests still pass for the remaining(size, chunks)combinations across all 4 boundary modes