Skip to content

Commit 85f2cc7

Browse files
authored
test JacobianOperator (#9)
1 parent 30e0c2a commit 85f2cc7

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

test/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
[deps]
22
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3+
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
4+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

test/runtests.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,35 @@ function F!(res, x)
66
return res[2] = exp(x[1] - 1) + x[2]^2 - 2
77
end
88

9+
function F(x)
10+
res = similar(x)
11+
F!(res, x)
12+
return res
13+
end
14+
915
let x₀ = [2.0, 0.5]
1016
x, stats = newton_krylov!(F!, x₀)
1117
@test stats.solved
1218
end
1319

1420
let x₀ = [3.0, 5.0]
15-
x, stats = newton_krylov!(F!, x₀)
21+
x, stats = newton_krylov(F, x₀)
1622
@test stats.solved
1723
end
24+
25+
import NewtonKrylov: JacobianOperator
26+
using Enzyme, LinearAlgebra
27+
28+
@testset "Jacobian" begin
29+
J_Enz = jacobian(Forward, F, [3.0, 5.0]) |> only
30+
J = JacobianOperator(F!, zeros(2), [3.0, 5.0])
31+
J_NK = collect(J)
32+
33+
@test J_NK == J_Enz
34+
35+
v = rand(2)
36+
out = similar(v)
37+
mul!(out, J, v)
38+
39+
@test out J_Enz * v
40+
end

0 commit comments

Comments
 (0)