Skip to content

Commit a1877cd

Browse files
committed
Fix Jacobian Construction for concrete_jac
1 parent 9d98446 commit a1877cd

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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 = "2.0.2"
4+
version = "2.0.3"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

src/jacobian.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@concrete struct JacobianWrapper{iip}
1+
@concrete struct JacobianWrapper{iip} <: Function
22
f
33
p
44
end
@@ -73,9 +73,9 @@ function jacobian_caches(alg::AbstractNonlinearSolveAlgorithm, f, u, p, ::Val{ii
7373
jac_cache = nothing
7474
end
7575

76-
J = if !linsolve_needs_jac
76+
J = if !(linsolve_needs_jac || alg_wants_jac)
7777
# We don't need to construct the Jacobian
78-
JacVec(uf, u; autodiff = alg.ad)
78+
JacVec(uf, u; autodiff = __get_nonsparse_ad(alg.ad))
7979
else
8080
if has_analytic_jac
8181
f.jac_prototype === nothing ? undefmatrix(u) : f.jac_prototype
@@ -98,6 +98,11 @@ function jacobian_caches(alg::AbstractNonlinearSolveAlgorithm, f, u, p, ::Val{ii
9898
return uf, linsolve, J, fu, jac_cache, du
9999
end
100100

101+
__get_nonsparse_ad(::AutoSparseForwardDiff) = AutoForwardDiff()
102+
__get_nonsparse_ad(::AutoSparseFiniteDiff) = AutoFiniteDiff()
103+
__get_nonsparse_ad(::AutoSparseZygote) = AutoZygote()
104+
__get_nonsparse_ad(ad) = ad
105+
101106
## Special Handling for Scalars
102107
function jacobian_caches(alg::AbstractNonlinearSolveAlgorithm, f, u::Number, p,
103108
::Val{false}; kwargs...)

0 commit comments

Comments
 (0)