Skip to content

Commit

Permalink
Fix Jacobian Construction for concrete_jac
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 6, 2023
1 parent 9d98446 commit a1877cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NonlinearSolve"
uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
authors = ["SciML"]
version = "2.0.2"
version = "2.0.3"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
11 changes: 8 additions & 3 deletions src/jacobian.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@concrete struct JacobianWrapper{iip}
@concrete struct JacobianWrapper{iip} <: Function
f
p
end
Expand Down Expand Up @@ -73,9 +73,9 @@ function jacobian_caches(alg::AbstractNonlinearSolveAlgorithm, f, u, p, ::Val{ii
jac_cache = nothing
end

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

__get_nonsparse_ad(::AutoSparseForwardDiff) = AutoForwardDiff()
__get_nonsparse_ad(::AutoSparseFiniteDiff) = AutoFiniteDiff()
__get_nonsparse_ad(::AutoSparseZygote) = AutoZygote()

Check warning on line 103 in src/jacobian.jl

View check run for this annotation

Codecov / codecov/patch

src/jacobian.jl#L101-L103

Added lines #L101 - L103 were not covered by tests
__get_nonsparse_ad(ad) = ad

## Special Handling for Scalars
function jacobian_caches(alg::AbstractNonlinearSolveAlgorithm, f, u::Number, p,
::Val{false}; kwargs...)
Expand Down

0 comments on commit a1877cd

Please sign in to comment.