fix: Avoid repeated extinction law construction in redden!/deredden! - #48
Merged
icweaver merged 3 commits intoJun 27, 2026
Conversation
Instantiate the DustExtinction law once before broadcasting instead of passing the law type directly to `DustExtinction.redden` /`DustExtinction.deredden`. This avoids repeated construction of the extinction law when broadcasting over spectral elements while keeping the public API unchanged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #48 +/- ##
==========================================
- Coverage 90.74% 90.38% -0.36%
==========================================
Files 8 8
Lines 162 156 -6
==========================================
- Hits 147 141 -6
Misses 15 15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
icweaver
added a commit
to JuliaAstro/DustExtinction.jl
that referenced
this pull request
Jun 27, 2026
Member
|
Thanks for the contribution! I've upstreamed the instance logic to DustExtinction.jl to make the changes here a bit more general. Should be good to go after the next version there is registered JuliaRegistries/General#159484 |
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 PR improves the implementation of
redden!andderedden!insrc/transforms/redden.jl.Previously the implementation broadcasted directly over the extinction law type:
When
lawis provided as aType(e.g. the defaultDustExtinction.CCM89), the broadcast dispatch calls the type-based method ofDustExtinction.reddenfor every wavelength element. This leads to constructing the extinction law instance (e.g.CCM89(Rv=3.1)) repeatedly.This PR instead constructs the extinction law instance once and then applies the broadcast using that instance:
The same change is applied to
deredden!.Benefits
DustExtinction.jlFuture work
There is ongoing upstream work adding in-place versions of these functions in DustExtinction.jl:
JuliaAstro/DustExtinction.jl#84
Once those functions (
redden!/deredden!) are available in a released version, Spectra.jl could simplify this further by delegating directly to those implementations. (Once that happens, it will also fix #45 )Testing
All existing tests (224/224) pass successfully.