Avoid repeated extinction law construction in redden!/deredden!#48
Open
Akshat1000Sharma wants to merge 1 commit into
Open
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.85% +0.11%
==========================================
Files 8 8
Lines 162 164 +2
==========================================
+ Hits 147 149 +2
Misses 15 15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.