Skip to content

Keep template backend and variance name in kriging singular-matrix fallback#3294

Open
brendancol wants to merge 2 commits into
mainfrom
deep-sweep-metadata-interpolate-2026-06-12
Open

Keep template backend and variance name in kriging singular-matrix fallback#3294
brendancol wants to merge 2 commits into
mainfrom
deep-sweep-metadata-interpolate-2026-06-12

Conversation

@brendancol

Copy link
Copy Markdown
Contributor

Closes #3288

  • The K_inv is None fallback in kriging() now builds its all-NaN result on the template's backend: map_blocks + np.full_like for dask templates (stays lazy, keeps chunks and the cupy meta on dask+cupy) and np.full_like otherwise (dispatches to cupy for GPU templates). Previously the fallback always returned an eager numpy array, and for a large chunked dask template it materialised the whole grid in host memory.
  • With return_variance=True the fallback's variance raster is now named <name>_variance, matching the normal path. It used to inherit the prediction's name.

Backend coverage: numpy, cupy, dask+numpy, dask+cupy. All four verified locally on a GPU host.

Test plan:

  • 4 new tests in TestKriging force the fallback via monkeypatch and check name, backend type, chunks, dtype, attrs, and NaN content per backend
  • pytest xrspatial/tests/test_interpolation.py: 70 passed (GPU tests included)

@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Jun 12, 2026

@brendancol brendancol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PR Review: Keep template backend and variance name in kriging singular-matrix fallback

Blockers (must fix before merge)

None.

Suggestions (should fix, not blocking)

None.

Nits (optional improvements)

  • xrspatial/interpolate/_kriging.py (new map_blocks call in the K_inv is None branch): the lambda gives the dask task a lambda-<hash> name instead of an xrspatial.kriging-style name per the #3255 convention. Every other map_blocks call in this module has the same gap, and #3256 already tracks the module-wide naming sweep, so fixing only this one call here would leave the module inconsistent either way. Fine to leave for #3256.

What looks good

  • The fix dispatches on the actual backend: map_blocks + np.full_like keeps dask templates lazy with their original chunks, and np.full_like dispatches to cupy for GPU templates. Verified in the new tests, including the dask+cupy meta check (result.data._meta is cupy.ndarray).
  • The fallback was eager before this change even for chunked dask templates; now it never materialises the grid, which matches the memory-guard reasoning that skips the grid-sized term for dask (_check_kriging_memory(is_dask=True)).
  • variance now carries <name>_variance like the normal path (line 523), and the test asserts it on all four backends.
  • The monkeypatch in the tests targets the module global _build_kriging_matrix, which kriging() resolves at call time, so the forcing mechanism is sound.
  • Coords, dims, attrs, and dtype assertions are explicit in test_singular_fallback_metadata rather than inferred.

Checklist

  • Algorithm matches reference/paper (n/a, metadata-only fix)
  • All implemented backends produce consistent results
  • NaN handling is correct (all-NaN fallback by design)
  • Edge cases are covered by tests (fallback forced per backend)
  • Dask chunk boundaries handled correctly (no overlap needed; chunks preserved)
  • No premature materialization (fallback is now lazy on dask; was eager before)
  • Benchmark exists or is not needed (degenerate path, not performance-relevant)
  • README feature matrix updated (n/a, no API or backend-support change)
  • Docstrings present and accurate (no public signature change)

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.

kriging() singular-matrix fallback ignores template backend and misnames the variance raster

1 participant