Repository navigation
perf: separable box dilation in blurring_mask_2d_from for large PSFs - #697
Merged
Merged
Conversation
The blurring mask dilated the unmasked region with a dense (ky, kx) box, and scipy's offsets table for it grows as (ky*kx)**2: a 499x499 PSF took 401 s and 462 GiB. A box is separable, so a (ky, 1) dilation followed by a (1, kx) dilation gives the identical mask. Adds a dense-reference test over odd, even and rectangular kernels. Proposed and diagnosed by George Vassilakis in PyAutoLabs/.github#45. Closes #696. Co-authored-by: George Vassilakis <90641828+GeorgeVassilakis@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #696. Community: PyAutoLabs/.github#45 (proposed and diagnosed by @GeorgeVassilakis, co-author on the commit).
Summary
blurring_mask_2d_fromdilated the unmasked region with a densenp.ones((ky, kx))structure. scipy builds an offsets table for it that grows as (ky·kx)², so large PSFs were slow and memory hungry: George measured 401 s and 462 GiB for a 499 × 499 kernel, which OOM-killed jobs on his cluster. A box is separable, so a(ky, 1)dilation followed by a(1, kx)dilation gives the identical mask.API Changes
None. Same signature and identical output.
Numbers (laptop, after the change; masks byte-identical to before)
The blurring mask is built once or twice per
apply_mask, never per likelihood call, so ordinary HST/JWST modelling saves milliseconds. Large PSFs (wide-field, oversampled, HWO/ELT-style simulations) go from minutes and tens of GB to seconds.Tests
test__blurring_mask_2d_from__matches_dense_box_dilation: compares against a dense 2-D box dilation for kernels (3,3), (5,3), (4,4), (6,2), (3,7), (8,5), (2,9).test_autoarray/: 2418 passed.🤖 Generated with Claude Code