Skip to content

Commit 30ffdd7

Browse files
committed
added tests to ensure no nesting is happening
1 parent f403820 commit 30ffdd7

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

test/basic.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ end
221221
v=rand(N,K); @test ldiv!(v, op, u) (A * B * C) \ u
222222
v=copy(u); @test ldiv!(op, u) (A * B * C) \ v
223223

224+
# ensure composedoperators don't nest
225+
A = MatrixOperator(rand(N, N))
226+
L = A * (A * A) * A
227+
@test L isa ComposedOperator
228+
for op in L.ops
229+
@test !isa(op, ComposedOperator)
230+
end
231+
224232
# Test caching of composed operator when inner ops do not support Base.:*
225233
# ComposedOperator caching was modified in PR # 174
226234
inner_op = qr(MatrixOperator(rand(N, N)))

test/scalar.jl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#
2-
using SciMLOperators, LinearAlgebra
3-
using Random
2+
using SciMLOperators
3+
using SciMLOperators: AbstractSciMLScalarOperator,
4+
ComposedScalarOperator,
5+
AddedScalarOperator,
6+
InvertedScalarOperator,
7+
IdentityOperator,
8+
AddedOperator,
9+
ScaledOperator
10+
11+
using LinearAlgebra, Random
412

513
Random.seed!(0)
614
N = 8
@@ -38,31 +46,31 @@ K = 12
3846

3947
# Test that ScalarOperator's remain AbstractSciMLScalarOperator's under common ops
4048
β = α + α
41-
@test β isa SciMLOperators.AddedScalarOperator
49+
@test β isa AddedScalarOperator
4250
@test β * u x * u + x * u
4351
@inferred convert(Float32, β)
4452
@test convert(Number, β) x + x
4553

4654
β = α * α
47-
@test β isa SciMLOperators.ComposedScalarOperator
55+
@test β isa ComposedScalarOperator
4856
@test β * u x * x * u
4957
@inferred convert(Float32, β)
5058
@test convert(Number, β) x * x
5159

5260
β = inv(α)
53-
@test β isa SciMLOperators.InvertedScalarOperator
61+
@test β isa InvertedScalarOperator
5462
@test β * u 1 / x * u
5563
@inferred convert(Float32, β)
5664
@test convert(Number, β) 1 / x
5765

5866
β = α * inv(α)
59-
@test β isa SciMLOperators.ComposedScalarOperator
67+
@test β isa ComposedScalarOperator
6068
@test β * u u
6169
@inferred convert(Float32, β)
6270
@test convert(Number, β) true
6371

6472
β = α / α
65-
@test β isa SciMLOperators.ComposedScalarOperator
73+
@test β isa ComposedScalarOperator
6674
@test β * u u
6775
@inferred convert(Float32, β)
6876
@test convert(Number, β) true
@@ -77,6 +85,14 @@ K = 12
7785
@test/ op) * u (op \ α) * u α * (op \ u)
7886
@test (op / α) * u \ op) * u 1/α * op * u
7987
end
88+
89+
# ensure composedscalaroperators doesn't nest
90+
α = ScalarOperator(rand())
91+
L = α ** α) * α
92+
@test L isa ComposedScalarOperator
93+
for op in L.ops
94+
@test !isa(op, ComposedScalarOperator)
95+
end
8096
end
8197

8298
@testset "ScalarOperator update test" begin

0 commit comments

Comments
 (0)