Inline dask aggregate kernel in resample (#1463)#1468
Merged
brendancol merged 1 commit intomainfrom May 4, 2026
Merged
Conversation
Replace the per-output-pixel `func(sub, 1, 1)[0, 0]` loop in `_agg_block_np` with a single `@ngjit` call per chunk. Each method gets a `_agg_block_*_nb` kernel that takes the global geometry and the chunk's `in_y0 / in_x0 / go_y0 / go_x0` offsets and walks the entire output region in one numba dispatch, writing into a pre-allocated output buffer. The eager `_run_numpy` aggregate path is unchanged. `_agg_block_cupy` already round-trips to CPU through `_agg_block_np`, so it picks up the speedup without code changes. Adds parity tests against `_run_numpy` for all 5 aggregate methods on a 60x60 raster with 20x20 chunks (output chunks straddle input chunk boundaries via `_add_overlap`), plus a 200x200 smoke test guarding against accidental quadratic regressions in the chunk loop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1463.
Summary
func(sub, 1, 1)[0, 0]loop in_agg_block_npwith a single@ngjitcall per chunk._agg_block_mean_nb,_min_nb,_max_nb,_median_nb,_mode_nb) that take the global input/output geometry plus the chunk'sin_y0 / in_x0 / go_y0 / go_x0offsets, derive per-pixel windows fromint(go * global_in_h / global_out_h) - in_y0, and write into a pre-allocated(target_h, target_w)buffer._run_numpyaggregate path is untouched._agg_block_cupyround-trips through_agg_block_np, so it picks up the speedup unchanged.Test plan
_add_overlap, so the chunk-offset math is exercised. Compared element-wise (assert_array_equal) against_run_numpy.