Skip to content

focal: speed up test_focal.py + test_proximity.py (#1931)#1939

Merged
brendancol merged 1 commit into
mainfrom
issue-1931
May 15, 2026
Merged

focal: speed up test_focal.py + test_proximity.py (#1931)#1939
brendancol merged 1 commit into
mainfrom
issue-1931

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

Fixes #1931. Local wall-clock for test_focal.py + test_proximity.py drops 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:

  • The three #1284 oversize-kernel tests (apply, focal_stats, hotspots) used to allocate a (50001, 50001) float32 kernel just to trip the memory guard. The np.ones call alone takes ~5 s and pins 10 GB of RAM. They now patch xrspatial.focal._available_memory_bytes to return 1 and use a small (101, 101) kernel. The guard still fires and the error message still gets matched.
  • Drop unused module-level data_random_sparse and data_gaussian and the helpers that built them. Nothing in the suite referenced either.
  • Shrink the module-level data_random from 100x100 to 40x40, and switch the dask mean-transfer tests from chunks=(3, 3) to chunks=(20, 20) so the graphs have a handful of chunks instead of 1156.
  • Trim the (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.py passes locally (183 passed, was 203)
  • All three *_rejects_oversize_kernel_1284 tests still raise MemoryError with the right message
  • All four *_boundary_numpy_equals_dask tests still pass for the remaining (size, chunks) combinations across all 4 boundary modes

- 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%).
Copilot AI review requested due to automatic review settings May 15, 2026 14:37
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 15, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_bytes in three *_rejects_oversize_kernel_1284 tests so a small (101, 101) kernel still trips the guard.
  • Drop unused data_random_sparse/data_gaussian helpers; shrink data_random to 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.

@brendancol brendancol merged commit d44c7a7 into main May 15, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Speed up focal and proximity test suites

2 participants