|
31 | 31 | @test one(A) isa IdentityOperator{N} |
32 | 32 | @test convert(AbstractMatrix, Id) == Matrix(I, N, N) |
33 | 33 |
|
| 34 | + @test iscached(Id) |
34 | 35 | @test size(Id) == (N, N) |
35 | 36 | @test Id' isa IdentityOperator{N} |
36 | 37 |
|
|
65 | 66 | @test zero(A) isa NullOperator{N} |
66 | 67 | @test convert(AbstractMatrix, Z) == zeros(size(Z)) |
67 | 68 |
|
| 69 | + @test iscached(Z) |
68 | 70 | @test size(Z) == (N, N) |
69 | 71 | @test Z' isa NullOperator{N} |
70 | 72 |
|
|
99 | 101 | op = ScaledOperator(α, MatrixOperator(A)) |
100 | 102 |
|
101 | 103 | @test op isa ScaledOperator |
| 104 | + @test iscached(op) |
102 | 105 |
|
103 | 106 | @test α * A * u ≈ op * u |
104 | 107 | @test (β * op) * u ≈ β * α * A * u |
105 | 108 |
|
106 | 109 | opF = factorize(op) |
107 | 110 |
|
108 | 111 | @test opF isa ScaledOperator |
| 112 | + @test iscached(opF) |
109 | 113 |
|
110 | 114 | @test α * A ≈ convert(AbstractMatrix, op) ≈ convert(AbstractMatrix, opF) |
111 | 115 |
|
|
145 | 149 | end |
146 | 150 |
|
147 | 151 | op = AddedOperator(A, B) |
| 152 | + @test iscached(op) |
| 153 | + |
148 | 154 | v=rand(N,K); @test mul!(v, op, u) ≈ (A+B) * u |
149 | 155 | v=rand(N,K); w=copy(v); @test mul!(v, op, u, α, β) ≈ α*(A+B)*u + β*w |
150 | 156 | end |
|
172 | 178 | @test ABCmulu ≈ op * u |
173 | 179 | @test ABCdivu ≈ op \ u ≈ opF \ u |
174 | 180 |
|
| 181 | + @test !iscached(op) |
175 | 182 | op = cache_operator(op, u) |
| 183 | + @test iscached(op) |
| 184 | + |
176 | 185 | v=rand(N,K); @test mul!(v, op, u) ≈ ABCmulu |
177 | 186 | v=rand(N,K); w=copy(v); @test mul!(v, op, u, α, β) ≈ α*ABCmulu + β*w |
178 | 187 |
|
|
181 | 190 | C = rand(N) |> Diagonal |
182 | 191 |
|
183 | 192 | op = ∘(MatrixOperator.((A, B, C))...) |
| 193 | + @test !iscached(op) |
184 | 194 | op = cache_operator(op, u) |
| 195 | + @test iscached(op) |
185 | 196 | v=rand(N,K); @test ldiv!(v, op, u) ≈ (A * B * C) \ u |
186 | 197 | v=copy(u); @test ldiv!(op, u) ≈ (A * B * C) \ v |
187 | 198 |
|
|
195 | 206 | @test_throws MethodError inner_op * u |
196 | 207 | # We can now test that caching does not rely on matmul |
197 | 208 | op = inner_op * factorize(MatrixOperator(rand(N, N))) |
| 209 | + @test !iscached(op) |
198 | 210 | @test_nowarn op = cache_operator(op, rand(N)) |
| 211 | + @test iscached(op) |
199 | 212 | u = rand(N) |
200 | 213 | @test ldiv!(rand(N), op, u) ≈ op \ u |
201 | 214 | end |
|
245 | 258 | α = rand() |
246 | 259 | β = rand() |
247 | 260 |
|
| 261 | + @test !iscached(Di) |
248 | 262 | Di = cache_operator(Di, u) |
| 263 | + @test iscached(Di) |
249 | 264 |
|
250 | 265 | @test Di * u ≈ u ./ s |
251 | 266 | v=rand(N); @test mul!(v, Di, u) ≈ u ./ s |
|
0 commit comments