Skip to content

Commit

Permalink
Fix JacVec for not inplace problems
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Sep 15, 2023
1 parent 5b46c2d commit a5ae510
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/jacobian.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
@concrete struct JacobianWrapper
@concrete struct JacobianWrapper{iip}
f
p
end

(uf::JacobianWrapper)(u) = uf.f(u, uf.p)
(uf::JacobianWrapper)(res, u) = uf.f(res, u, uf.p)
# Previous Implementation did not hold onto `iip`, but this causes problems in packages
# where we check for the presence of function signatures to check which dispatch to call
(uf::JacobianWrapper{false})(u) = uf.f(u, uf.p)
(uf::JacobianWrapper{false})(res, u) = (vec(res) .= vec(uf.f(u, uf.p)))
(uf::JacobianWrapper{true})(res, u) = uf.f(res, u, uf.p)

Check warning on line 10 in src/jacobian.jl

View check run for this annotation

Codecov / codecov/patch

src/jacobian.jl#L8-L10

Added lines #L8 - L10 were not covered by tests

sparsity_detection_alg(f, ad) = NoSparsityDetection()
function sparsity_detection_alg(f, ad::AbstractSparseADType)
Expand Down Expand Up @@ -48,7 +51,7 @@ jacobian!!(::Number, cache) = last(value_derivative(cache.uf, cache.u))
# Build Jacobian Caches
function jacobian_caches(alg::AbstractNonlinearSolveAlgorithm, f, u, p,

Check warning on line 52 in src/jacobian.jl

View check run for this annotation

Codecov / codecov/patch

src/jacobian.jl#L52

Added line #L52 was not covered by tests
::Val{iip}) where {iip}
uf = JacobianWrapper(f, p)
uf = JacobianWrapper{iip}(f, p)

Check warning on line 54 in src/jacobian.jl

View check run for this annotation

Codecov / codecov/patch

src/jacobian.jl#L54

Added line #L54 was not covered by tests

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

Expand Down

0 comments on commit a5ae510

Please sign in to comment.