Skip to content

Commit e1f4ced

Browse files
committed
tests
1 parent 0f11885 commit e1f4ced

File tree

5 files changed

+70
-5
lines changed

5 files changed

+70
-5
lines changed

test/basic.jl

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ K = 12
2727
β = rand()
2828
Id = IdentityOperator{N}()
2929

30+
@test issquare(Id)
31+
@test islinear(Id)
3032
@test IdentityOperator(u) isa IdentityOperator{N}
3133
@test one(A) isa IdentityOperator{N}
3234
@test convert(AbstractMatrix, Id) == Matrix(I, N, N)
@@ -61,6 +63,8 @@ end
6163
β = rand()
6264
Z = NullOperator{N}()
6365

66+
@test issquare(Z)
67+
@test islinear(Z)
6468
@test NullOperator(u) isa NullOperator{N}
6569
@test zero(A) isa NullOperator{N}
6670
@test convert(AbstractMatrix, Z) == zeros(size(Z))
@@ -99,6 +103,8 @@ end
99103
op = ScaledOperator(α, MatrixOperator(A))
100104

101105
@test op isa ScaledOperator
106+
@test issquare(op)
107+
@test islinear(op)
102108

103109
@test α * A * u op * u
104110
@test* op) * u β * α * A * u
@@ -164,10 +170,14 @@ end
164170

165171
@test op isa ComposedOperator
166172
@test *(op.ops...) isa ComposedOperator
173+
@test issquare(op)
174+
@test islinear(op)
167175

168176
opF = factorize(op)
169177

170178
@test opF isa ComposedOperator
179+
@test issquare(opF)
180+
@test islinear(opF)
171181

172182
@test ABCmulu op * u
173183
@test ABCdivu op \ u opF \ u
@@ -202,10 +212,14 @@ end
202212

203213
@testset "Adjoint, Transpose" begin
204214

205-
for (op, LType, VType) in (
206-
(adjoint, AdjointOperator, AbstractAdjointVecOrMat ),
207-
(transpose, TransposedOperator, AbstractTransposedVecOrMat),
208-
)
215+
for (op,
216+
LType,
217+
VType
218+
) in (
219+
(adjoint, AdjointOperator, AbstractAdjointVecOrMat ),
220+
(transpose, TransposedOperator, AbstractTransposedVecOrMat),
221+
)
222+
209223
A = rand(N,N)
210224
D = Bidiagonal(rand(N,N), :L)
211225
u = rand(N,K)
@@ -215,7 +229,13 @@ end
215229
b = rand()
216230

217231
At = op(A)
218-
Dt = op(A)
232+
Dt = op(D)
233+
234+
@test issquare(At)
235+
@test issquare(Dt)
236+
237+
@test islinear(At)
238+
@test islinear(Dt)
219239

220240
AA = MatrixOperator(A)
221241
DD = MatrixOperator(D)
@@ -247,6 +267,9 @@ end
247267

248268
Di = cache_operator(Di, u)
249269

270+
@test issquare(Di)
271+
@test islinear(Di)
272+
250273
@test Di * u u ./ s
251274
v=rand(N); @test mul!(v, Di, u) u ./ s
252275
v=rand(N); w=copy(v); @test mul!(v, Di, u, α, β) α *(u ./ s) + β*w

test/func.jl

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

3030
op_inverse=f1i,
3131

32+
islinear=true,
3233
opnorm=true,
3334
issymmetric=true,
3435
ishermitian=true,
@@ -40,11 +41,17 @@ K = 12
4041

4142
op_inverse=f2i,
4243

44+
islinear=true,
4345
opnorm=true,
4446
issymmetric=true,
4547
ishermitian=true,
4648
isposdef=true,
4749
)
50+
@test issquare(op1)
51+
@test issquare(op2)
52+
53+
@test islinear(op1)
54+
@test islinear(op2)
4855

4956
@test op1' === op1
5057

test/matrix.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ K = 19
2424
@test AA isa MatrixOperator
2525
@test AAt isa MatrixOperator
2626

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

@@ -73,6 +76,9 @@ end
7376
update_func= (diag,u,p,t) -> (diag .= p*t; nothing)
7477
)
7578

79+
@test issquare(D)
80+
@test islinear(D)
81+
7682
ans = Diagonal(p*t) * u
7783
@test D(u,p,t) ans
7884
v=copy(u); @test D(v,u,p,t) ans
@@ -86,6 +92,9 @@ end
8692

8793
L = DiagonalOperator(d)
8894

95+
@test issquare(L)
96+
@test islinear(L)
97+
8998
@test L * u d .* u
9099
v=rand(N,K); @test mul!(v, L, u) d .* u
91100
v=rand(N,K); w=copy(v); @test mul!(v, L, u, α, β) α*(d .* u) + β*w
@@ -105,17 +114,25 @@ end
105114
β = rand()
106115

107116
L = AffineOperator(MatrixOperator(A), MatrixOperator(B), b)
117+
@test issquare(L)
118+
@test !islinear(L)
108119

109120
@test L * u A * u + B*b
110121
v=rand(N,K); @test mul!(v, L, u) A*u + B*b
111122
v=rand(N,K); w=copy(v); @test mul!(v, L, u, α, β) α*(A*u + B*b) + β*w
112123

113124
L = AffineOperator(MatrixOperator(D), MatrixOperator(B), b)
125+
@test issquare(L)
126+
@test !islinear(L)
127+
114128
@test L \ u D \ (u - B * b)
115129
v=rand(N,K); @test ldiv!(v, L, u) D \ (u-B*b)
116130
v=copy(u); @test ldiv!(L, u) D \ (v-B*b)
117131

118132
L = AddVector(b)
133+
@test issquare(L)
134+
@test !islinear(L)
135+
119136
@test L * u u + b
120137
@test L \ u u - b
121138
v=rand(N,K); @test mul!(v, L, u) u + b
@@ -124,6 +141,9 @@ end
124141
v=copy(u); @test ldiv!(L, u) v - b
125142

126143
L = AddVector(MatrixOperator(B), b)
144+
@test issquare(L)
145+
@test !islinear(L)
146+
127147
@test L * u u + B * b
128148
@test L \ u u - B * b
129149
v=rand(N,K); @test mul!(v, L, u) u + B * b
@@ -188,6 +208,17 @@ for square in [false, true] #for K in [1, K]
188208
@test opAB isa TensorProductOperator
189209
@test opABC isa TensorProductOperator
190210

211+
if square
212+
@test issquare(opAB)
213+
@test issquare(opABC)
214+
else
215+
@test !issquare(opAB)
216+
@test !issquare(opABC)
217+
end
218+
219+
@test islinear(opAB)
220+
@test islinear(opABC)
221+
191222
@test AB convert(AbstractMatrix, opAB)
192223
@test ABC convert(AbstractMatrix, opABC)
193224

test/scalar.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ K = 12
1414
u = rand(N,K)
1515

1616
@test α isa ScalarOperator
17+
@test issquare(α)
18+
@test islinear(α)
1719
@test convert(Number, α) isa Number
1820
@test convert(ScalarOperator, a) isa ScalarOperator
1921

test/total.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ K = 12
2727
op_adjoint = (du,u,p,t) -> ldiv!(du, tr, u),
2828
op_inverse = (du,u,p,t) -> ldiv!(du, tr, u),
2929
op_adjoint_inverse = (du,u,p,t) -> ldiv!(du, tr, u),
30+
31+
islinear=true,
3032
)
3133

3234
# derivative test

0 commit comments

Comments
 (0)