Skip to content

Commit 0026bc1

Browse files
Merge pull request #285 from avik-pal/ap/fix_jacvec
Use Function Wrappers from SciMLBase
2 parents cf8dd0c + af40e41 commit 0026bc1

File tree

4 files changed

+7
-18
lines changed

4 files changed

+7
-18
lines changed

Project.toml

+3-3
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.8.1"
4+
version = "2.8.2"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
@@ -56,11 +56,11 @@ NonlinearProblemLibrary = "0.1"
5656
PrecompileTools = "1"
5757
RecursiveArrayTools = "2"
5858
Reexport = "0.2, 1"
59-
SciMLBase = "2.4"
59+
SciMLBase = "2.8.2"
6060
SciMLOperators = "0.3"
6161
SimpleNonlinearSolve = "0.1.23"
6262
SparseArrays = "1.9"
63-
SparseDiffTools = "2.11"
63+
SparseDiffTools = "2.12"
6464
StaticArraysCore = "1.4"
6565
UnPack = "1.0"
6666
Zygote = "0.6"

docs/src/tutorials/getting_started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ There are multiple return codes which can mean the solve was successful, and thu
7777
general command `SciMLBase.successful_retcode` to check whether the solution process exited as
7878
intended:
7979

80-
```@example
80+
```@example 1
8181
SciMLBase.successful_retcode(sol)
8282
```
8383

src/jacobian.jl

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
@concrete struct JacobianWrapper{iip} <: Function
2-
f
3-
p
4-
end
5-
6-
# Previous Implementation did not hold onto `iip`, but this causes problems in packages
7-
# where we check for the presence of function signatures to check which dispatch to call
8-
(uf::JacobianWrapper{false})(u) = uf.f(u, uf.p)
9-
(uf::JacobianWrapper{false})(res, u) = (vec(res) .= vec(uf.f(u, uf.p)))
10-
(uf::JacobianWrapper{true})(res, u) = uf.f(res, u, uf.p)
11-
121
sparsity_detection_alg(_, _) = NoSparsityDetection()
132
function sparsity_detection_alg(f, ad::AbstractSparseADType)
143
if f.sparsity === nothing
@@ -52,7 +41,7 @@ jacobian!!(::Number, cache) = last(value_derivative(cache.uf, cache.u))
5241
function jacobian_caches(alg::AbstractNonlinearSolveAlgorithm, f::F, u, p, ::Val{iip};
5342
linsolve_kwargs = (;), lininit::Val{linsolve_init} = Val(true),
5443
linsolve_with_JᵀJ::Val{needsJᵀJ} = Val(false)) where {iip, needsJᵀJ, linsolve_init, F}
55-
uf = JacobianWrapper{iip}(f, p)
44+
uf = SciMLBase.JacobianWrapper{iip}(f, p)
5645

5746
haslinsolve = hasfield(typeof(alg), :linsolve)
5847

@@ -152,7 +141,7 @@ function jacobian_caches(alg::AbstractNonlinearSolveAlgorithm, f::F, u::Number,
152141
::Val{false}; linsolve_with_JᵀJ::Val{needsJᵀJ} = Val(false),
153142
kwargs...) where {needsJᵀJ, F}
154143
# NOTE: Scalar `u` assumes scalar output from `f`
155-
uf = JacobianWrapper{false}(f, p)
144+
uf = SciMLBase.JacobianWrapper{false}(f, p)
156145
needsJᵀJ && return uf, nothing, u, nothing, nothing, u, u, u
157146
return uf, nothing, u, nothing, nothing, u
158147
end

src/linesearch.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function LineSearchesJLCache(ls::LineSearch, f::F, u, p, fu1, IIP::Val{iip}) whe
122122
end
123123

124124
function g!(u, fu)
125-
op = VecJac(f, u, p; fu = fu1, autodiff)
125+
op = VecJac(SciMLBase.JacobianWrapper(f, p), u; fu = fu1, autodiff)
126126
if iip
127127
mul!(g₀, op, fu)
128128
return g₀

0 commit comments

Comments
 (0)