Avoid modifying the input pixel array in place in wcs_pix2world#19859
Open
astrofrog wants to merge 3 commits into
Open
Avoid modifying the input pixel array in place in wcs_pix2world#19859astrofrog wants to merge 3 commits into
astrofrog wants to merge 3 commits into
Conversation
…fsetting a bounded scratch buffer instead
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.
|
Member
Author
|
I wonder if maybe it's best to not backport and to just say that we are going to focus on thread-safety issues for 8.1.0 |
mhvk
approved these changes
Jun 4, 2026
Contributor
mhvk
left a comment
There was a problem hiding this comment.
This looks good! Two totally nitpicky comments, which can definitely be ignored.
| npy_intp block = ncoord; | ||
| double* pixscratch = NULL; | ||
| if (delta != 0.0 && ncoord > 0) { | ||
| block = (ncoord < 1024) ? ncoord : 1024; |
Contributor
There was a problem hiding this comment.
Since you have access to numpy headers, you could use NPY_BUFSIZE here -- which ends up being the same (it is 8192 bytes).
| double* pixscratch = NULL; | ||
| if (delta != 0.0 && ncoord > 0) { | ||
| block = (ncoord < 1024) ? ncoord : 1024; | ||
| pixscratch = (double*)malloc((size_t)block * nelem * sizeof(double)); |
Contributor
There was a problem hiding this comment.
Is nelem typically 2? I'd tend to make the scratch size independent of its value.
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.
This is a fix for #16244 and an alternative to #16459
The basic idea here is that instead of modifying the input array in-place (which is very thread-unsafe), we iterate over the coordinates in blocks of 1024 elements. This size was chosen as it results in essentially no measurable overhead - it's an optimal value that is not too small yet fits in a typical L1 cache.
When origin=1, the block size is just the number of coordinates and there is no chunking necessary.
Fixes #16244