Skip to content

Commit c8d19ee

Browse files
Merge pull request #264 from albertomercurio/master
Add special methods for multiplication of constant scalars
2 parents 29ea228 + 0e16e3f commit c8d19ee

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/basic.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,26 @@ for T in SCALINGNUMBERTYPES
218218
end
219219
end
220220

221+
# Special cases for constant scalars. These simplify the structure when applicable
222+
for T in SCALINGNUMBERTYPES[2:end]
223+
@eval function Base.:*::$T, L::ScaledOperator)
224+
isconstant(L.λ) && return ScaledOperator* L.λ, L.L)
225+
return ScaledOperator(L.λ, α * L.L) # Try to propagate the rule
226+
end
227+
@eval function Base.:*(L::ScaledOperator, α::$T)
228+
isconstant(L.λ) && return ScaledOperator* L.λ, L.L)
229+
return ScaledOperator(L.λ, α * L.L) # Try to propagate the rule
230+
end
231+
@eval function Base.:*::$T, L::MatrixOperator)
232+
isconstant(L) && return MatrixOperator* L.A)
233+
return ScaledOperator(α, L) # Going back to the generic case
234+
end
235+
@eval function Base.:*(L::MatrixOperator, α::$T)
236+
isconstant(L) && return MatrixOperator* L.A)
237+
return ScaledOperator(α, L) # Going back to the generic case
238+
end
239+
end
240+
221241
Base.:-(L::AbstractSciMLOperator) = ScaledOperator(-true, L)
222242
Base.:+(L::AbstractSciMLOperator) = L
223243

0 commit comments

Comments
 (0)