|
29 | 29 |
|
30 | 30 | op_inverse=f1i, |
31 | 31 |
|
| 32 | + ifcache = false, |
| 33 | + |
32 | 34 | islinear=true, |
33 | 35 | opnorm=true, |
34 | 36 | issymmetric=true, |
|
41 | 43 |
|
42 | 44 | op_inverse=f2i, |
43 | 45 |
|
| 46 | + ifcache = false, |
| 47 | + |
44 | 48 | islinear=true, |
45 | 49 | opnorm=true, |
46 | 50 | issymmetric=true, |
@@ -69,6 +73,12 @@ K = 12 |
69 | 73 | @test has_ldiv(op2) |
70 | 74 | @test has_ldiv!(op2) |
71 | 75 |
|
| 76 | + @test !iscached(op1) |
| 77 | + @test !iscached(op2) |
| 78 | + |
| 79 | + op1 = cache_operator(op1, u, A * u) |
| 80 | + op2 = cache_operator(op2, u, A * u) |
| 81 | + |
72 | 82 | @test iscached(op1) |
73 | 83 | @test iscached(op2) |
74 | 84 |
|
|
87 | 97 |
|
88 | 98 | f(du,u,p,t) = mul!(du, Diagonal(p*t), u) |
89 | 99 |
|
90 | | - op = FunctionOperator(f, u, u; p=zero(p), t=zero(t)) |
| 100 | + L = FunctionOperator(f, u, u; p=zero(p), t=zero(t)) |
91 | 101 |
|
92 | 102 | ans = @. u * p * t |
93 | | - @test op(u,p,t) ≈ ans |
94 | | - v=copy(u); @test op(v,u,p,t) ≈ ans |
| 103 | + @test L(u,p,t) ≈ ans |
| 104 | + v=copy(u); @test L(v,u,p,t) ≈ ans |
| 105 | + |
| 106 | + # test that output isn't accidentally mutated by passing an internal cache. |
| 107 | + |
| 108 | + A = Diagonal(p * t) |
| 109 | + u1 = rand(N, K) |
| 110 | + u2 = rand(N, K) |
| 111 | + |
| 112 | + v1 = L * u1; @test v1 ≈ A * u1 |
| 113 | + v2 = L * u2; @test v2 ≈ A * u2; @test v1 ≈ A * u1 |
| 114 | + @test v1 + v2 ≈ A * (u1 + u2) |
| 115 | + |
| 116 | + v1 .= 0.0 |
| 117 | + v2 .= 0.0 |
| 118 | + |
| 119 | + mul!(v1, L, u1); @test v1 ≈ A * u1 |
| 120 | + mul!(v2, L, u2); @test v2 ≈ A * u2; @test v1 ≈ A * u1 |
| 121 | + @test v1 + v2 ≈ A * (u1 + u2) |
| 122 | + |
| 123 | + v1 = rand(N, K); w1 = copy(v1) |
| 124 | + v2 = rand(N, K); w2 = copy(v2) |
| 125 | + a1, a2, b1, b2 = rand(4) |
| 126 | + |
| 127 | + mul!(v1, L, u1, a1, b1); @test v1 ≈ a1*A*u1 + b1*w1 |
| 128 | + mul!(v2, L, u2, a2, b2); @test v2 ≈ a2*A*u2 + b2*w2; @test v1 ≈ a1*A*u1 + b1*w1 |
| 129 | + @test v1 + v2 ≈ (a1*A*u1 + b1*w1) + (a2*A*u2 + b2*w2) |
95 | 130 | end |
96 | 131 | # |
0 commit comments