|
243 | 243 |
|
244 | 244 | # constructors |
245 | 245 | for T in SCALINGNUMBERTYPES[2:end] |
246 | | - @eval ScaledOperator(λ::$T, L::AbstractSciMLOperator) = ScaledOperator( |
247 | | - ScalarOperator(λ), |
248 | | - L) |
| 246 | + @eval function ScaledOperator(λ::$T, L::AbstractSciMLOperator) |
| 247 | + T2 = Base.promote_eltype(λ, L) |
| 248 | + Λ = λ isa UniformScaling ? UniformScaling(T2(λ.λ)) : T2(λ) |
| 249 | + ScaledOperator(ScalarOperator(Λ), L) |
| 250 | + end |
249 | 251 | end |
250 | 252 |
|
251 | 253 | for T in SCALINGNUMBERTYPES |
@@ -276,28 +278,16 @@ for T in SCALINGNUMBERTYPES[2:end] |
276 | 278 | isconstant(L.λ) && return ScaledOperator(α * L.λ, L.L) |
277 | 279 | return ScaledOperator(L.λ, α * L.L) # Try to propagate the rule |
278 | 280 | end |
279 | | - @eval function Base.:*(α::$T, L::MatrixOperator) |
280 | | - isconstant(L) && return MatrixOperator(α * L.A) |
281 | | - return ScaledOperator(α, L) # Going back to the generic case |
282 | | - end |
283 | | - @eval function Base.:*(L::MatrixOperator, α::$T) |
284 | | - isconstant(L) && return MatrixOperator(α * L.A) |
285 | | - return ScaledOperator(α, L) # Going back to the generic case |
286 | | - end |
287 | 281 | end |
288 | 282 |
|
289 | 283 | Base.:+(L::AbstractSciMLOperator) = L |
290 | | -Base.:-(L::AbstractSciMLOperator) = ScaledOperator(-true, L) |
| 284 | +Base.:-(L::AbstractSciMLOperator{T}) where T = ScaledOperator(-one(T), L) |
291 | 285 |
|
292 | 286 | # Special cases for constant scalars. These simplify the structure when applicable |
293 | 287 | function Base.:-(L::ScaledOperator) |
294 | 288 | isconstant(L.λ) && return ScaledOperator(-L.λ, L.L) |
295 | 289 | return ScaledOperator(L.λ, -L.L) # Try to propagate the rule |
296 | 290 | end |
297 | | -function Base.:-(L::MatrixOperator) |
298 | | - isconstant(L) && return MatrixOperator(-L.A) |
299 | | - return ScaledOperator(-true, L) # Going back to the generic case |
300 | | -end |
301 | 291 |
|
302 | 292 | function Base.convert(::Type{AbstractMatrix}, L::ScaledOperator) |
303 | 293 | convert(Number, L.λ) * convert(AbstractMatrix, L.L) |
|
0 commit comments