Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit a52c1b9

Browse files
SebastianM-CChrisRackauckas
authored andcommitted
Move out DiffEqScaledOperator
This moves out the following to SciMLBase - `DiffEqScaledOperator` and its methods - `AbstractDiffEqCompositeOperator` - `getops` The `SciMLBase` package is also added as a dependency. The compat entry for `SciMLBase` should be added after the required version is registered.
1 parent 32c6d37 commit a52c1b9

3 files changed

Lines changed: 4 additions & 48 deletions

File tree

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1414
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
1515
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
1616
RuntimeGeneratedFunctions = "7e49a35a-f44a-4d26-94aa-eba1b4ca6b47"
17+
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
1718
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1819
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1920
SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"

src/DiffEqOperators.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ module DiffEqOperators
33
import Base: +, -, *, /, \, size, getindex, setindex!, Matrix, convert, ==
44
using DiffEqBase, StaticArrays, LinearAlgebra
55
import LinearAlgebra: mul!, ldiv!, lmul!, rmul!, axpy!, opnorm, factorize, I
6-
import DiffEqBase: AbstractDiffEqLinearOperator, update_coefficients!, isconstant
6+
import DiffEqBase: update_coefficients!, isconstant
7+
using SciMLBase: AbstractDiffEqLinearOperator, AbstractDiffEqCompositeOperator, DiffEqScaledOperator
8+
import SciMLBase: getops
79
using SparseArrays, ForwardDiff, BandedMatrices, NNlib, LazyArrays, BlockBandedMatrices
810
using LazyBandedMatrices, ModelingToolkit
911
using RuntimeGeneratedFunctions
1012
RuntimeGeneratedFunctions.init(@__MODULE__)
1113

1214
abstract type AbstractDiffEqAffineOperator{T} end
1315
abstract type AbstractDerivativeOperator{T} <: AbstractDiffEqLinearOperator{T} end
14-
abstract type AbstractDiffEqCompositeOperator{T} <: AbstractDiffEqLinearOperator{T} end
1516
abstract type AbstractMatrixFreeOperator{T} <: AbstractDiffEqLinearOperator{T} end
1617

1718
### Matrix-free Operators

src/composite_operators.jl

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,6 @@
22
# derivative) using arithmetic or other operator compositions. The composite
33
# operator types are lazy and maintain the structure used to build them.
44

5-
# Recursive routines that use `getops`
6-
function update_coefficients!(L::AbstractDiffEqCompositeOperator,u,p,t)
7-
for op in getops(L)
8-
update_coefficients!(op,u,p,t)
9-
end
10-
L
11-
end
12-
isconstant(L::AbstractDiffEqCompositeOperator) = all(isconstant, getops(L))
13-
14-
# Scaled operator (α * A)
15-
struct DiffEqScaledOperator{T,F,OpType<:AbstractDiffEqLinearOperator{T}} <: AbstractDiffEqCompositeOperator{T}
16-
coeff::DiffEqScalar{T,F}
17-
op::OpType
18-
end
19-
*::DiffEqScalar{T,F}, L::AbstractDiffEqLinearOperator{T}) where {T,F} = DiffEqScaledOperator(α, L)
20-
*::Number, L::AbstractDiffEqLinearOperator{T}) where T = DiffEqScaledOperator(DiffEqScalar(convert(T,α)), L)
21-
-(L::AbstractDiffEqLinearOperator{T}) where {T} = DiffEqScalar(-one(T)) * L
22-
getops(L::DiffEqScaledOperator) = (L.coeff, L.op)
23-
Matrix(L::DiffEqScaledOperator) = L.coeff * Matrix(L.op)
24-
convert(::Type{AbstractMatrix}, L::DiffEqScaledOperator) = L.coeff * convert(AbstractMatrix, L.op)
25-
26-
size(L::DiffEqScaledOperator, args...) = size(L.op, args...)
27-
opnorm(L::DiffEqScaledOperator, p::Real=2) = abs(L.coeff) * opnorm(L.op, p)
28-
getindex(L::DiffEqScaledOperator, i::Int) = L.coeff * L.op[i]
29-
getindex(L::DiffEqScaledOperator, I::Vararg{Int, N}) where {N} =
30-
L.coeff * L.op[I...]
31-
*(L::DiffEqScaledOperator, x::AbstractArray) = L.coeff * (L.op * x)
32-
*(x::AbstractArray, L::DiffEqScaledOperator) = (L.op * x) * L.coeff
33-
/(L::DiffEqScaledOperator, x::AbstractArray) = L.coeff * (L.op / x)
34-
/(x::AbstractArray, L::DiffEqScaledOperator) = 1/L.coeff * (x / L.op)
35-
\(L::DiffEqScaledOperator, x::AbstractArray) = 1/L.coeff * (L.op \ x)
36-
\(x::AbstractArray, L::DiffEqScaledOperator) = L.coeff * (x \ L)
37-
for N in (2,3)
38-
@eval begin
39-
mul!(Y::AbstractArray{T,$N}, L::DiffEqScaledOperator{T}, B::AbstractArray{T,$N}) where {T} =
40-
lmul!(Y, L.coeff, mul!(Y, L.op, B))
41-
end
42-
end
43-
ldiv!(Y::AbstractArray, L::DiffEqScaledOperator, B::AbstractArray) =
44-
lmul!(1/L.coeff, ldiv!(Y, L.op, B))
45-
factorize(L::DiffEqScaledOperator) = L.coeff * factorize(L.op)
46-
for fact in (:lu, :lu!, :qr, :qr!, :cholesky, :cholesky!, :ldlt, :ldlt!,
47-
:bunchkaufman, :bunchkaufman!, :lq, :lq!, :svd, :svd!)
48-
@eval LinearAlgebra.$fact(L::DiffEqScaledOperator, args...) =
49-
L.coeff * fact(L.op, args...)
50-
end
515

526
# Linear Combination
537
struct DiffEqOperatorCombination{T,O<:Tuple{Vararg{AbstractDiffEqLinearOperator{T}}},

0 commit comments

Comments
 (0)