From db9daea2cfa85dfa2d481e5fbf7e7995d0a2e559 Mon Sep 17 00:00:00 2001 From: Akshat Sharma Date: Sun, 8 Mar 2026 18:05:09 +0530 Subject: [PATCH] Avoid repeated extinction law construction in redden!/deredden! 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. --- src/transforms/redden.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/transforms/redden.jl b/src/transforms/redden.jl index 7930d6a..6539a01 100644 --- a/src/transforms/redden.jl +++ b/src/transforms/redden.jl @@ -7,7 +7,8 @@ In-place version of [`redden`](@ref) """ function redden!(spec::T, Av; Rv = 3.1, law = DustExtinction.CCM89) where {T <: AbstractSpectrum} s, f = spectral_axis(spec), flux_axis(spec) - @. f = DustExtinction.redden(law, s, f; Rv, Av) + law_instance = law isa DustExtinction.ExtinctionLaw ? law : law(Rv=Rv) + @. f = DustExtinction.redden(law_instance, s, f; Av) return spec end @@ -32,7 +33,8 @@ In-place version of [`deredden`](@ref) """ function deredden!(spec::AbstractSpectrum, Av; Rv = 3.1, law = DustExtinction.CCM89) s, f = spectral_axis(spec), flux_axis(spec) - @. f = DustExtinction.deredden(law, s, f; Rv, Av) + law_instance = law isa DustExtinction.ExtinctionLaw ? law : law(Rv=Rv) + @. f = DustExtinction.deredden(law_instance, s, f; Av) return spec end