|
97 | 97 | v=rand(N2,K); @test mul!(v, op, u) ≈ op * u |
98 | 98 | v=rand(N2,K); w=copy(v); @test mul!(v, op, u, α, β) ≈ α*(op * u) + β * w |
99 | 99 | end |
| 100 | + |
| 101 | +@testset "Resize! test" begin |
| 102 | + M1 = 4 |
| 103 | + M2 = 12 |
| 104 | + |
| 105 | + u = rand(N) |
| 106 | + u1 = rand(M1) |
| 107 | + u2 = rand(M2) |
| 108 | + |
| 109 | + f(u, p, t) = 2 * u |
| 110 | + f(v, u, p, t) = (copy!(v, u); lmul!(2, v)) |
| 111 | + |
| 112 | + fi(u, p, t) = 0.5 * u |
| 113 | + fi(v, u, p, t) = (copy!(v, u); lmul!(0.5, v)) |
| 114 | + |
| 115 | + F = FunctionOperator(f, u, u; islinear = true, op_inverse = fi, issymmetric = true) |
| 116 | + |
| 117 | + multest(L, u) = @test mul!(zero(u), L, u) ≈ L * u |
| 118 | + |
| 119 | + function multest(L::SciMLOperators.AdjointOperator, u) |
| 120 | + @test mul!(adjoint(zero(u)), adjoint(u), L) ≈ adjoint(u) * L |
| 121 | + end |
| 122 | + |
| 123 | + function multest(L::SciMLOperators.TransposedOperator, u) |
| 124 | + @test mul!(transpose(zero(u)), transpose(u), L) ≈ transpose(u) * L |
| 125 | + end |
| 126 | + |
| 127 | + function multest(L::SciMLOperators.InvertedOperator, u) |
| 128 | + @test ldiv!(zero(u), L, u) ≈ L \ u |
| 129 | + end |
| 130 | + |
| 131 | + for (L, LT) in ( |
| 132 | + (F, FunctionOperator), |
| 133 | + (F + F, SciMLOperators.AddedOperator), |
| 134 | + (F * 2, SciMLOperators.ScaledOperator), |
| 135 | + (F ∘ F, SciMLOperators.ComposedOperator), |
| 136 | + (AffineOperator(F, F, u), AffineOperator), |
| 137 | + (SciMLOperators.AdjointOperator(F), SciMLOperators.AdjointOperator), |
| 138 | + (SciMLOperators.TransposedOperator(F), SciMLOperators.TransposedOperator), |
| 139 | + (SciMLOperators.InvertedOperator(F), SciMLOperators.InvertedOperator), |
| 140 | + (SciMLOperators.InvertibleOperator(F), SciMLOperators.InvertibleOperator), |
| 141 | + ) |
| 142 | + |
| 143 | + @info "$LT" |
| 144 | + |
| 145 | + L = deepcopy(L) |
| 146 | + L = cache_operator(L, u) |
| 147 | + |
| 148 | + @test L isa LT |
| 149 | + @test size(L) == (N, N) |
| 150 | + multest(L, u) |
| 151 | + |
| 152 | + resize!(L, M1); @test size(L) == (M1, M1) |
| 153 | + multest(L, u1) |
| 154 | + |
| 155 | + resize!(L, M2); @test size(L) == (M2, M2) |
| 156 | + multest(L, u2) |
| 157 | + |
| 158 | + end |
| 159 | + |
| 160 | + # InvertedOperator |
| 161 | + # AffineOperator |
| 162 | + # FunctionOperator |
| 163 | +end |
100 | 164 | # |
0 commit comments