Skip to content

Commit d7c9a38

Browse files
committed
tests
1 parent f07c9a1 commit d7c9a38

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

test/basic.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ K = 12
3333

3434
@test size(Id) == (N, N)
3535
@test Id' isa IdentityOperator{N}
36+
@test isconstant(Id)
3637

3738
for op in (
3839
*, \,
@@ -62,6 +63,7 @@ end
6263
Z = NullOperator{N}()
6364

6465
@test NullOperator(u) isa NullOperator{N}
66+
@test isconstant(Z)
6567
@test zero(A) isa NullOperator{N}
6668
@test convert(AbstractMatrix, Z) == zeros(size(Z))
6769

@@ -99,13 +101,15 @@ end
99101
op = ScaledOperator(α, MatrixOperator(A))
100102

101103
@test op isa ScaledOperator
104+
@test isconstant(op)
102105

103106
@test α * A * u op * u
104107
@test* op) * u β * α * A * u
105108

106109
opF = factorize(op)
107110

108111
@test opF isa ScaledOperator
112+
@test isconstant(opF)
109113

110114
@test α * A convert(AbstractMatrix, op) convert(AbstractMatrix, opF)
111115

@@ -138,6 +142,11 @@ end
138142
@test op3 isa AddedOperator
139143
@test op4 isa AddedOperator
140144

145+
@test isconstant(op1)
146+
@test isconstant(op2)
147+
@test isconstant(op3)
148+
@test isconstant(op4)
149+
141150
@test op1 * u op( A*u, B*u)
142151
@test op2 * u op*A*u, B*u)
143152
@test op3 * u op( A*u, β*B*u)
@@ -163,11 +172,14 @@ end
163172
op = (MatrixOperator.((A, B, C))...)
164173

165174
@test op isa ComposedOperator
175+
@test isconstant(op)
176+
166177
@test *(op.ops...) isa ComposedOperator
167178

168179
opF = factorize(op)
169180

170181
@test opF isa ComposedOperator
182+
@test isconstant(opF)
171183

172184
@test ABCmulu op * u
173185
@test ABCdivu op \ u opF \ u
@@ -223,6 +235,9 @@ end
223235
AAt = LType(AA)
224236
DDt = LType(DD)
225237

238+
@test isconstant(AAt)
239+
@test isconstant(DDt)
240+
226241
@test AAt.L === AA
227242
@test op(u) isa VType
228243

@@ -247,6 +262,8 @@ end
247262

248263
Di = cache_operator(Di, u)
249264

265+
@test isconstant(Di)
266+
250267
@test Di * u u ./ s
251268
v=rand(N); @test mul!(v, Di, u) u ./ s
252269
v=rand(N); w=copy(v); @test mul!(v, Di, u, α, β) α *(u ./ s) + β*w

test/matrix.jl

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ K = 19
2424
@test AA isa MatrixOperator
2525
@test AAt isa MatrixOperator
2626

27+
@test isconstant(AA)
28+
@test isconstant(AAt)
29+
2730
FF = factorize(AA)
2831
FFt = FF'
2932

3033
@test FF isa InvertibleOperator
3134
@test FFt isa InvertibleOperator
3235

36+
@test isconstant(FF)
37+
@test isconstant(FFt)
38+
3339
@test eachindex(A) === eachindex(AA)
3440
@test eachindex(A') === eachindex(AAt) === eachindex(MatrixOperator(At))
3541

@@ -55,9 +61,11 @@ end
5561
t = rand()
5662

5763
L = MatrixOperator(zeros(N,N);
58-
update_func= (A,u,p,t) -> (A .= p*p'; nothing)
64+
update_func = (A,u,p,t) -> (A .= p*p'; nothing)
5965
)
6066

67+
@test !isconstant(L)
68+
6169
A = p*p'
6270
ans = A * u
6371
@test L(u,p,t) ans
@@ -70,9 +78,11 @@ end
7078
t = rand()
7179

7280
D = DiagonalOperator(zeros(N);
73-
update_func= (diag,u,p,t) -> (diag .= p*t; nothing)
81+
update_func = (diag,u,p,t) -> (diag .= p*t; nothing)
7482
)
7583

84+
@test !isconstant(D)
85+
7686
ans = Diagonal(p*t) * u
7787
@test D(u,p,t) ans
7888
v=copy(u); @test D(v,u,p,t) ans
@@ -85,6 +95,7 @@ end
8595
β = rand()
8696

8797
L = DiagonalOperator(d)
98+
@test isconstant(L)
8899

89100
@test L * u d .* u
90101
v=rand(N,K); @test mul!(v, L, u) d .* u
@@ -105,6 +116,7 @@ end
105116
β = rand()
106117

107118
L = AffineOperator(MatrixOperator(A), MatrixOperator(B), b)
119+
@test isconstant(L)
108120

109121
@test L * u A * u + B*b
110122
v=rand(N,K); @test mul!(v, L, u) A*u + B*b
@@ -141,9 +153,11 @@ end
141153
t = rand()
142154

143155
L = AffineOperator(A, B, b;
144-
update_func= (b,u,p,t) -> (b .= Diagonal(p*t)*b; nothing)
156+
update_func = (b,u,p,t) -> (b .= Diagonal(p*t)*b; nothing)
145157
)
146158

159+
@test !isconstant(L)
160+
147161
b = Diagonal(p*t)*b
148162
ans = A * u + B * b
149163
@test L(u,p,t) ans
@@ -188,13 +202,19 @@ for square in [false, true] #for K in [1, K]
188202
@test opAB isa TensorProductOperator
189203
@test opABC isa TensorProductOperator
190204

205+
@test isconstant(opAB)
206+
@test isconstant(opABC)
207+
191208
@test AB convert(AbstractMatrix, opAB)
192209
@test ABC convert(AbstractMatrix, opABC)
193210

194211
# factorization tests
195212
opAB_F = factorize(opAB)
196213
opABC_F = factorize(opABC)
197214

215+
@test isconstant(opAB_F)
216+
@test isconstant(opABC_F)
217+
198218
@test opAB_F isa TensorProductOperator
199219
@test opABC_F isa TensorProductOperator
200220

test/scalar.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ K = 12
1818
@test convert(ScalarOperator, a) isa ScalarOperator
1919

2020
@test size(α) == ()
21+
@test isconstant(α)
2122

2223
v=copy(u); @test lmul!(α, u) v * x
2324
v=copy(u); @test rmul!(u, α) x * v
@@ -64,6 +65,9 @@ end
6465
α = ScalarOperator(0.0; update_func=(a,u,p,t) -> p)
6566
β = ScalarOperator(0.0; update_func=(a,u,p,t) -> t)
6667

68+
@test !isconstant(α)
69+
@test !isconstant(β)
70+
6771
@test α(u,p,t) p * u
6872
@test α(v,u,p,t) p * u
6973

0 commit comments

Comments
 (0)