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.
PR summary
Agg already has RGB resampling with output to RGBA builtin, so we just need to correctly wire up the corresponding templates. With this RGB resampling mode, we save the extra copy from RGB to RGBA in NumPy land that was required for the previous always-RGBA resampling.
With the example from #29434, this saves 800MB of peak memory usage, which actually works out to two copies of 10000x10000x4 bytes; I'm not sure where the second copy comes from.
While this does pass tests, I think there may be some room for further improvement, as the input to the C++ code is
A[..., :3]
, which should be a discontiguous view, but then the pybind11 code forces it to be contiguous, which would make another copy. There are some offset and step settings in Agg that I think we can use to avoid this copy as well, but it might require extra template expansions.PR checklist