Skip to content

Commit e93fc58

Browse files
Merge pull request #200 from avik-pal/ap/jac_prototype
Newton Raphson used to ignore jac-prototype
2 parents cb80ed2 + 503d579 commit e93fc58

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ docs/site/
2323
# environment.
2424
Manifest.toml
2525
docs/src/assets/Project.toml
26+
27+
.vscode

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "NonlinearSolve"
22
uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
33
authors = ["SciML"]
4-
version = "1.9.0"
4+
version = "1.10.0"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/raphson.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ end
106106

107107
function jacobian_caches(alg::NewtonRaphson, f, u, p, ::Val{true})
108108
uf = JacobianWrapper(f, p)
109-
J = ArrayInterface.undefmatrix(u)
109+
J = if f.jac_prototype === nothing
110+
ArrayInterface.undefmatrix(u)
111+
else
112+
f.jac_prototype
113+
end
110114

111115
linprob = LinearProblem(J, _vec(zero(u)); u0 = _vec(zero(u)))
112116
weight = similar(u)

test/sparse.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ sol = solve(prob_brusselator_2d, NewtonRaphson())
4141
du0 = copy(u0)
4242
jac_sparsity = Symbolics.jacobian_sparsity((du, u) -> brusselator_2d_loop(du, u, p), du0,
4343
u0)
44+
jac_prototype = float.(jac_sparsity)
45+
fill!(jac_prototype, 0)
46+
@test all(iszero, jac_prototype)
4447

45-
ff = NonlinearFunction(brusselator_2d_loop; jac_prototype = float.(jac_sparsity))
48+
ff = NonlinearFunction(brusselator_2d_loop; jac_prototype)
4649
prob_brusselator_2d = NonlinearProblem(ff, u0, p)
4750
sol = solve(prob_brusselator_2d, NewtonRaphson())
4851
@test norm(sol.resid) < 1e-8
52+
@test !all(iszero, jac_prototype)
4953

5054
sol = solve(prob_brusselator_2d, NewtonRaphson(autodiff = false))
5155
@test norm(sol.resid) < 1e-6

0 commit comments

Comments
 (0)