Skip to content

Commit 6041da8

Browse files
committed
ensure addedoperator doesn't nest
1 parent 30ffdd7 commit 6041da8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/basic.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,9 @@ AddedOperator(L::AbstractSciMLOperator) = L
330330
# constructors
331331
Base.:+(A::AbstractSciMLOperator, B::AbstractMatrix) = A + MatrixOperator(B)
332332
Base.:+(A::AbstractMatrix, B::AbstractSciMLOperator) = MatrixOperator(A) + B
333-
Base.:+(ops::AbstractSciMLOperator...) = AddedOperator(ops...)
334333

334+
Base.:+(ops::AbstractSciMLOperator...) = reduce(+, ops)
335+
Base.:+(A::AbstractSciMLOperator, B::AbstractSciMLOperator) = AddedOperator(A, B)
335336
Base.:+(A::AbstractSciMLOperator, B::AddedOperator) = AddedOperator(A, B.ops...)
336337
Base.:+(A::AddedOperator, B::AbstractSciMLOperator) = AddedOperator(A.ops..., B)
337338
Base.:+(A::AddedOperator, B::AddedOperator) = AddedOperator(A.ops..., B.ops...)

test/basic.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ end
171171

172172
v=rand(N,K); @test mul!(v, op, u) (A+B) * u
173173
v=rand(N,K); w=copy(v); @test mul!(v, op, u, α, β) α*(A+B)*u + β*w
174+
175+
# ensure AddedOperator doesn't nest
176+
A = MatrixOperator(rand(N, N))
177+
L = A + (A + A) + A
178+
@test L isa AddedOperator
179+
for op in L.ops
180+
@test !isa(op, AddedOperator)
181+
end
182+
174183
end
175184

176185
@testset "ComposedOperator" begin
@@ -221,7 +230,7 @@ end
221230
v=rand(N,K); @test ldiv!(v, op, u) (A * B * C) \ u
222231
v=copy(u); @test ldiv!(op, u) (A * B * C) \ v
223232

224-
# ensure composedoperators don't nest
233+
# ensure composedoperators doesn't nest
225234
A = MatrixOperator(rand(N, N))
226235
L = A * (A * A) * A
227236
@test L isa ComposedOperator

0 commit comments

Comments
 (0)