Skip to content

Commit beba3b7

Browse files
jClugstorChrisRackauckas
authored andcommitted
account for both derivative and gradient
1 parent 4fc5b98 commit beba3b7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/BracketingNonlinearSolve/ext/BracketingNonlinearSolveChainRulesCoreExt.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ function ChainRulesCore.rrule(
1818
function ∇bracketingnonlinear_solve_up(Δ)
1919
# Δ = dg/du
2020
λ = only(ForwardDiff.derivative(u -> f(u, p), only(u)) \ Δ.u)
21-
dgdp = -λ * ForwardDiff.gradient(p -> f(u, p), p)
21+
if p isa Number
22+
dgdp = -λ * ForwardDiff.derivative(p -> f(u, p), p)
23+
else
24+
dgdp = -λ * ForwardDiff.gradient(p -> f(u, p), p)
25+
end
2226
return (NoTangent(), NoTangent(), NoTangent(),
2327
dgdp, NoTangent(),
2428
ntuple(_ -> NoTangent(), length(args))...)

0 commit comments

Comments
 (0)