Skip to content

Commit 2c6d862

Browse files
Add a test for the tutorial issue
1 parent 2d6e744 commit 2c6d862

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/matrix.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,42 @@ end
160160
orig_w = copy(w)
161161
L(w, v, u, p, t, α, β)
162162
@test w α * (A * v) + β * orig_w
163+
164+
A = [-2.0 1 0 0 0
165+
1 -2 1 0 0
166+
0 1 -2 1 0
167+
0 0 1 -2 1
168+
0 0 0 1 -2]
169+
v = [3.0,2.0,1.0,2.0,3.0]
170+
opA = MatrixOperator(A)
171+
172+
function update_function!(B, u, p, t)
173+
dt = p
174+
B .= A .* u + dt*I
175+
end
176+
177+
u = Array(1:1.0:5); p = 0.1; t = 0.0
178+
opB = MatrixOperator(copy(A); update_func! = update_function!)
179+
180+
function Bfunc!(w,v,u,p,t)
181+
dt = p
182+
w[1] = -(2*u[1]-dt)*v[1] + v[2]*u[1]
183+
for i in 2:4
184+
w[i] = v[i-1]*u[i] - (2*u[i]-dt)*v[i] + v[i+1]*u[i]
185+
end
186+
w[5] = v[4]*u[5] - (2*u[5]-dt)*v[5]
187+
nothing
188+
end
189+
190+
function Bfunc!(v,u,p,t)
191+
w = zeros(5)
192+
Bfunc!(w,v,u,p,t)
193+
w
194+
end
195+
196+
mfopB = FunctionOperator(Bfunc!, zeros(5), zeros(5); u, p, t, isconstant=false)
197+
198+
@test iszero(opB(v, Array(2:1.0:6), 0.5, nothing) - mfopB(v, Array(2:1.0:6), 0.5, nothing))
163199
end
164200

165201
@testset "DiagonalOperator update test" begin

0 commit comments

Comments
 (0)