Skip to content

interpolate: align IDW all-points and k-nearest on coincident inputs#1

Open
jam-lock wants to merge 1 commit into
mainfrom
deep-sweep-accuracy-interpolate-2026-05-21
Open

interpolate: align IDW all-points and k-nearest on coincident inputs#1
jam-lock wants to merge 1 commit into
mainfrom
deep-sweep-accuracy-interpolate-2026-05-21

Conversation

@jam-lock
Copy link
Copy Markdown
Owner

Summary

Accuracy sweep for the interpolate module surfaced a Cat 5 backend
divergence in idw(): the numba/CUDA all-points kernels broke on the
first input point with d2 == 0 and returned that point's z, while
the scipy.cKDTree k-nearest path averaged all coincident matches.
Same input, different numerical results.

  • All-points kernels (CPU + CUDA) now accumulate the sum and count of
    coincident input points and return the mean, matching the
    k-nearest path.
  • This is also the mathematically correct IDW limit at a coincident
    grid cell (the 1/d^p weights diverge equally for each coincident
    point).
  • Backend coverage: numpy / cupy / dask+numpy / dask+cupy all flow
    through the same updated kernels.

The state CSV update for the 2026-05-21 deep-sweep accuracy run is
included in the same commit.

Test plan

  • pytest xrspatial/tests/test_interpolation.py (37 passed, 5 skipped on CPU host)
  • New TestIDW.test_duplicate_points_average_across_backends
    regression test exercises the bug and passes both paths
  • cupy / dask+cupy paths validated on a GPU host (this host has
    no CUDA; the change is a direct port of the CPU fix into the
    @cuda.jit kernel)

…nputs

The numba/CUDA all-points kernels used to `break` on the first input
point with d2==0 and return that point's z, while the scipy.cKDTree
k-nearest path averaged the z values of all coincident matches.  The
two backends thus produced numerically different results on the same
input -- a Cat 5 (backend inconsistency) accuracy bug.

Both all-points kernels now accumulate the sum and count of coincident
points and return the mean, matching the k-nearest path.  This is also
the mathematically correct IDW limit at a coincident grid cell.

Adds TestIDW.test_duplicate_points_average_across_backends as the
regression test.

Updates .claude/sweep-accuracy-state.csv with the interpolate row for
the deep-sweep accuracy run on 2026-05-21.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant