Skip to content

Add focal variety statistic (#1040)#1043

Merged
brendancol merged 4 commits intomasterfrom
issue-1040
Mar 21, 2026
Merged

Add focal variety statistic (#1040)#1043
brendancol merged 4 commits intomasterfrom
issue-1040

Conversation

@brendancol
Copy link
Contributor

Summary

  • Add variety to focal_stats -- counts distinct non-NaN values in a kernel neighbourhood
  • Works on all four backends: numpy, cupy, dask+numpy, dask+cupy
  • CPU path: @ngjit with a compact unique-values buffer
  • GPU path: @cuda.jit with a 25-slot cuda.local.array for tracking distinct values
  • variety is now in the default stats_funcs list
  • range (max - min) was mentioned in the original request as missing but already existed

Test plan

  • Correctness on a categorical 6x6 grid with known variety counts
  • Dask+numpy parity with numpy reference
  • NaN cells excluded from distinct count
  • All-NaN window produces NaN output
  • Single-cell raster edge case
  • Existing data_focal_stats fixture updated with variety expected values
  • Full focal test suite passes (116 tests)

Closes #1040

Add _calc_variety (CPU/numba) and _focal_variety_cuda (GPU) that count
distinct non-NaN values in a kernel neighbourhood.  Wire into all three
dispatch dicts so variety works across numpy, cupy, dask+numpy, and
dask+cupy backends.
Cover correctness on categorical data, NaN handling, all-NaN windows,
single-cell rasters, and dask+numpy backend parity.  Update the
data_focal_stats fixture to include variety expected values.
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Mar 20, 2026
@brendancol
Copy link
Contributor Author

rtd:rebuild

@brendancol brendancol merged commit 819ee71 into master Mar 21, 2026
11 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.

Add focal variety statistic (count of distinct values in window)

1 participant