Skip to content

Guard owa() against unbounded criteria stack (#1370)#1375

Merged
brendancol merged 1 commit into
mainfrom
issue-1370
Apr 29, 2026
Merged

Guard owa() against unbounded criteria stack (#1370)#1375
brendancol merged 1 commit into
mainfrom
issue-1370

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

  • Adds a host-memory guard to owa() that estimates the float64 criteria stack size (n_criteria * H * W * 8) and raises MemoryError when it would exceed 50% of available RAM.
  • Dask-backed inputs skip the guard, since per-chunk allocations are bounded by the chunk size.
  • Three new tests in TestOWAMemoryGuard: oversize raises, normal succeeds, error message names the criterion count and grid shape.

Closes #1370.

Test plan

  • pytest xrspatial/tests/test_mcda.py passes (169 tests, including the 3 new ones).
  • Manual smoke check: owa() on a small Dataset returns the expected composite surface.

owa() concatenates every weighted criterion layer into a single
float64 stack via xr.concat, then sorts that stack descending
along the criterion axis.  Peak working memory scales as
n_criteria * H * W * 8, with the sort roughly doubling that.
A caller passing 100 criteria over a 10000x10000 raster needs
~80 GB just for the stack; the sort takes it to ~160 GB.

Add a host-memory guard on the eager numpy path that refuses
inputs whose stack would exceed 50% of available RAM.  Dask-backed
inputs skip the guard since per-chunk allocations are bounded.

Tests: oversize raises MemoryError; normal-size succeeds; error
message names the criterion count and grid shape.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Apr 29, 2026
@brendancol brendancol merged commit 2ee107d into main Apr 29, 2026
10 of 11 checks passed
@brendancol brendancol deleted the issue-1370 branch May 4, 2026 19:50
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.

owa() unbounded xr.concat allocation across criteria

1 participant