Remove unnecessary array copies to reduce memory allocations#933
Merged
brendancol merged 2 commits intomasterfrom Mar 3, 2026
Merged
Remove unnecessary array copies to reduce memory allocations#933brendancol merged 2 commits intomasterfrom
brendancol merged 2 commits intomasterfrom
Conversation
- Replace zeros_like + fill NaN with empty + fill NaN in ngjit functions (aspect, slope, classify) to avoid a wasted zeroing pass - Drop redundant .copy() after cupy.asnumpy().astype() in erosion (asnumpy already produces a fresh numpy array) - Drop redundant .copy() after boolean fancy indexing in bump (fancy indexing always returns a copy) - Use .data instead of .values on numpy-backed DataArrays in viewshed and min_observable_height (.values forces numpy conversion) - Use np.asarray instead of np.array for barriers in pathfinding (avoids copying when input is already an ndarray) - Replace np.array(float64_slice, dtype=float64) with .copy() in viewshed (no dtype conversion needed) - Widen test_perlin_gpu tolerance to match fastmath precision (rtol 1e-4, atol 1e-6); consistent with test_perlin_dask_gpu
Six standalone examples demonstrating cost distance, erosion, fire propagation, flood simulation, landslide risk, and watershed delineation.
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.
Summary
np.zeros_like+[:] = np.nanwithnp.empty+[:] = np.nanin@ngjitfunctions (aspect, slope, classify) to skip a wasted zeroing pass.copy()aftercupy.asnumpy().astype()in erosion --asnumpyalready produces a fresh numpy array.copy()after boolean fancy indexing in bump -- fancy indexing always copies.datainstead of.valueson numpy-backed DataArrays in viewshed and min_observable_height to avoid unnecessary property dispatch and potential forced numpy conversionnp.asarrayinstead ofnp.arrayfor barriers in pathfinding to skip copying when the input is already an ndarraynp.array(float64_slice, dtype=float64)with.copy()in viewshed where no dtype conversion is neededtest_perlin_gputolerance tortol=1e-4, atol=1e-6to matchfastmath=Trueprecision, consistent withtest_perlin_dask_gpuTest plan