Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Make Aqua happy #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module BracketingNonlinearSolveChainRulesCoreExt

using BracketingNonlinearSolve: bracketingnonlinear_solve_up, CommonSolve, SciMLBase
using CommonSolve: solve
using SciMLBase: IntervalNonlinearProblem
using ForwardDiff
using SciMLBase: IntervalNonlinearProblem, unwrapped_f
using ForwardDiff: derivative, gradient
using ChainRulesCore: ChainRulesCore, AbstractThunk, NoTangent, Tangent, unthunk

function ChainRulesCore.rrule(
Expand All @@ -13,16 +13,16 @@ function ChainRulesCore.rrule(
)
out = solve(prob, alg)
u = out.u
f = SciMLBase.unwrapped_f(prob.f)
f = unwrapped_f(prob.f)
function ∇bracketingnonlinear_solve_up(Δ)
Δ = Δ isa AbstractThunk ? unthunk(Δ) : Δ
# Δ = dg/du
Δ isa Tangent ? delu = Δ.u : delu = Δ
λ = only(ForwardDiff.derivative(u -> f(u, p), only(u)) \ delu)
λ = only(derivative(u -> f(u, p), only(u)) \ delu)
if p isa Number
dgdp = -λ * ForwardDiff.derivative(p -> f(u, p), p)
dgdp = -λ * derivative(p -> f(u, p), p)
else
dgdp = -λ * ForwardDiff.gradient(p -> f(u, p), p)
dgdp = -λ * gradient(p -> f(u, p), p)
end
return (NoTangent(), NoTangent(), NoTangent(),
dgdp, NoTangent(),
Expand All @@ -31,4 +31,4 @@ function ChainRulesCore.rrule(
return out, ∇bracketingnonlinear_solve_up
end

end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module BracketingNonlinearSolveForwardDiffExt

using CommonSolve: CommonSolve
using ForwardDiff: ForwardDiff, Dual
using ForwardDiff: Dual
using NonlinearSolveBase: nonlinearsolve_forwarddiff_solve, nonlinearsolve_dual_solution
using SciMLBase: SciMLBase, IntervalNonlinearProblem

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.