@@ -74,3 +74,52 @@ function update_coefficients!(L::AffineDiffEqOperator,u,p,t)
7474end
7575
7676@deprecate is_constant (L:: AbstractDiffEqOperator ) isconstant (L)
77+
78+ # Scaled operator (α * A)
79+ struct DiffEqScaledOperator{T,F,OpType<: AbstractDiffEqLinearOperator{T} } <: AbstractDiffEqCompositeOperator{T}
80+ coeff:: DiffEqScalar{T,F}
81+ op:: OpType
82+ end
83+
84+ # Recursive routines that use `getops`
85+ function update_coefficients! (L:: AbstractDiffEqCompositeOperator ,u,p,t)
86+ for op in getops (L)
87+ update_coefficients! (op,u,p,t)
88+ end
89+ L
90+ end
91+
92+ Base.:* (α:: DiffEqScalar{T,F} , L:: AbstractDiffEqLinearOperator{T} ) where {T,F} = DiffEqScaledOperator (α, L)
93+ Base.:* (α:: Number , L:: AbstractDiffEqLinearOperator{T} ) where T = DiffEqScaledOperator (DiffEqScalar (convert (T,α)), L)
94+ Base.:- (L:: AbstractDiffEqLinearOperator{T} ) where {T} = DiffEqScalar (- one (T)) * L
95+ getops (L:: DiffEqScaledOperator ) = (L. coeff, L. op)
96+ Base. Matrix (L:: DiffEqScaledOperator ) = L. coeff * Matrix (L. op)
97+ Base. convert (:: Type{AbstractMatrix} , L:: DiffEqScaledOperator ) = L. coeff * convert (AbstractMatrix, L. op)
98+
99+ Base. size (L:: DiffEqScaledOperator , args... ) = size (L. op, args... )
100+ LinearAlgebra. opnorm (L:: DiffEqScaledOperator , p:: Real = 2 ) = abs (L. coeff) * opnorm (L. op, p)
101+ Base. getindex (L:: DiffEqScaledOperator , i:: Int ) = L. coeff * L. op[i]
102+ Base. getindex (L:: DiffEqScaledOperator , I:: Vararg{Int, N} ) where {N} =
103+ L. coeff * L. op[I... ]
104+ Base.:* (L:: DiffEqScaledOperator , x:: AbstractArray ) = L. coeff * (L. op * x)
105+ Base.:* (x:: AbstractArray , L:: DiffEqScaledOperator ) = (L. op * x) * L. coeff
106+ Base.:/ (L:: DiffEqScaledOperator , x:: AbstractArray ) = L. coeff * (L. op / x)
107+ Base.:/ (x:: AbstractArray , L:: DiffEqScaledOperator ) = 1 / L. coeff * (x / L. op)
108+ Base.:\ (L:: DiffEqScaledOperator , x:: AbstractArray ) = 1 / L. coeff * (L. op \ x)
109+ Base.:\ (x:: AbstractArray , L:: DiffEqScaledOperator ) = L. coeff * (x \ L)
110+ for N in (2 ,3 )
111+ @eval begin
112+ LinearAlgebra. mul! (Y:: AbstractArray{T,$N} , L:: DiffEqScaledOperator{T} , B:: AbstractArray{T,$N} ) where {T} =
113+ LinearAlgebra. lmul! (Y, L. coeff, mul! (Y, L. op, B))
114+ end
115+ end
116+ LinearAlgebra. ldiv! (Y:: AbstractArray , L:: DiffEqScaledOperator , B:: AbstractArray ) =
117+ lmul! (1 / L. coeff, ldiv! (Y, L. op, B))
118+ LinearAlgebra. factorize (L:: DiffEqScaledOperator ) = L. coeff * factorize (L. op)
119+ for fact in (:lu , :lu! , :qr , :qr! , :cholesky , :cholesky! , :ldlt , :ldlt! ,
120+ :bunchkaufman , :bunchkaufman! , :lq , :lq! , :svd , :svd! )
121+ @eval LinearAlgebra.$ fact (L:: DiffEqScaledOperator , args... ) =
122+ L. coeff * fact (L. op, args... )
123+ end
124+
125+ isconstant (L:: AbstractDiffEqCompositeOperator ) = all (isconstant, getops (L))
0 commit comments