Repository navigation
Fix block_replicate promoting float16/float32/complex64 inputs to float64 - #20364
Merged
larrybradley merged 2 commits intoSep 11, 2026
Merged
Conversation
Contributor
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
larrybradley
approved these changes
Sep 11, 2026
Member
|
@meeseeksdev backport to v7.2.x @meeseeksdev backport to v8.0.x |
pllim
added a commit
that referenced
this pull request
Sep 11, 2026
…364-on-v7.2.x Backport PR #20364 on branch v7.2.x (Fix block_replicate promoting float16/float32/complex64 inputs to float64)
pllim
added a commit
that referenced
this pull request
Sep 11, 2026
…364-on-v8.0.x Backport PR #20364 on branch v8.0.x (Fix block_replicate promoting float16/float32/complex64 inputs to float64)
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.
Description
Fixes #20360.
Under NumPy NEP 50, dividing a
float32orfloat16array by anint64scalar (whichnp.prod(block_size)produces becauseblock_sizeis anintndarray) promotes the array tofloat64(andcomplex64promotes tocomplex128). Consequently,block_replicate(..., conserve_sum=True)unexpectedly promoted these dtypes to 64-bit precision, doubling the memory footprint forfloat32astronomical imagery.By converting
np.prod(block_size)to a Pythonint(int(np.prod(block_size))), NumPy retains the floating point / complex precision of the input array under NEP 50 rules, while integer arrays continue to convert tofloat64under Python true division as expected.Checklist for package maintainer(s)
np.float16,np.float32,np.float64,np.complex64,np.complex128, andnp.int32inputs.astropy.nddatatest suite passed (1324/1324 tests passed).docs/changes/nddata/20360.bugfix.rst.