-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from SciML/ap/explicit_imports
Improve Code Standards
- Loading branch information
Showing
34 changed files
with
436 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
style = "sciml" | ||
format_markdown = true | ||
annotate_untyped_fields_with_any = false | ||
format_docstrings = true | ||
format_docstrings = true | ||
join_lines_based_on_source = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 10 additions & 7 deletions
17
lib/SimpleNonlinearSolve/ext/SimpleNonlinearSolveChainRulesCoreExt.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
lib/SimpleNonlinearSolve/ext/SimpleNonlinearSolvePolyesterForwardDiffExt.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 53 additions & 46 deletions
99
lib/SimpleNonlinearSolve/ext/SimpleNonlinearSolveReverseDiffExt.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,67 @@ | ||
module SimpleNonlinearSolveReverseDiffExt | ||
|
||
using ArrayInterface, DiffEqBase, ReverseDiff, SciMLBase, SimpleNonlinearSolve | ||
import ReverseDiff: TrackedArray, TrackedReal | ||
using ArrayInterface: ArrayInterface | ||
using DiffEqBase: DiffEqBase | ||
using ReverseDiff: ReverseDiff, TrackedArray, TrackedReal | ||
using SciMLBase: ReverseDiffOriginator, NonlinearProblem, NonlinearLeastSquaresProblem | ||
using SimpleNonlinearSolve: SimpleNonlinearSolve | ||
import SimpleNonlinearSolve: __internal_solve_up | ||
|
||
function __internal_solve_up( | ||
prob::NonlinearProblem, sensealg, u0::TrackedArray, u0_changed, | ||
p::TrackedArray, p_changed, alg, args...; kwargs...) | ||
return ReverseDiff.track(__internal_solve_up, prob, sensealg, u0, | ||
u0_changed, p, p_changed, alg, args...; kwargs...) | ||
end | ||
for pType in (NonlinearProblem, NonlinearLeastSquaresProblem) | ||
@eval begin | ||
function __internal_solve_up(prob::$(pType), sensealg, u0::TrackedArray, u0_changed, | ||
p::TrackedArray, p_changed, alg, args...; kwargs...) | ||
return ReverseDiff.track(__internal_solve_up, prob, sensealg, u0, | ||
u0_changed, p, p_changed, alg, args...; kwargs...) | ||
end | ||
|
||
function __internal_solve_up( | ||
prob::NonlinearProblem, sensealg, u0, u0_changed, | ||
p::TrackedArray, p_changed, alg, args...; kwargs...) | ||
return ReverseDiff.track(__internal_solve_up, prob, sensealg, u0, | ||
u0_changed, p, p_changed, alg, args...; kwargs...) | ||
end | ||
function __internal_solve_up(prob::$(pType), sensealg, u0, u0_changed, | ||
p::TrackedArray, p_changed, alg, args...; kwargs...) | ||
return ReverseDiff.track(__internal_solve_up, prob, sensealg, u0, | ||
u0_changed, p, p_changed, alg, args...; kwargs...) | ||
end | ||
|
||
function __internal_solve_up( | ||
prob::NonlinearProblem, sensealg, u0::TrackedArray, u0_changed, | ||
p, p_changed, alg, args...; kwargs...) | ||
return ReverseDiff.track(__internal_solve_up, prob, sensealg, u0, | ||
u0_changed, p, p_changed, alg, args...; kwargs...) | ||
end | ||
function __internal_solve_up(prob::$(pType), sensealg, u0::TrackedArray, | ||
u0_changed, p, p_changed, alg, args...; kwargs...) | ||
return ReverseDiff.track(__internal_solve_up, prob, sensealg, u0, | ||
u0_changed, p, p_changed, alg, args...; kwargs...) | ||
end | ||
|
||
function __internal_solve_up(prob::NonlinearProblem, sensealg, | ||
u0::AbstractArray{<:TrackedReal}, u0_changed, p::AbstractArray{<:TrackedReal}, | ||
p_changed, alg, args...; kwargs...) | ||
return __internal_solve_up( | ||
prob, sensealg, ArrayInterface.aos_to_soa(u0), true, | ||
ArrayInterface.aos_to_soa(p), true, alg, args...; kwargs...) | ||
end | ||
function __internal_solve_up( | ||
prob::$(pType), sensealg, u0::AbstractArray{<:TrackedReal}, u0_changed, | ||
p::AbstractArray{<:TrackedReal}, p_changed, alg, args...; kwargs...) | ||
return __internal_solve_up(prob, sensealg, ArrayInterface.aos_to_soa(u0), true, | ||
ArrayInterface.aos_to_soa(p), true, alg, args...; kwargs...) | ||
end | ||
|
||
function __internal_solve_up(prob::NonlinearProblem, sensealg, u0, u0_changed, | ||
p::AbstractArray{<:TrackedReal}, p_changed, alg, args...; kwargs...) | ||
return __internal_solve_up( | ||
prob, sensealg, u0, true, ArrayInterface.aos_to_soa(p), true, alg, args...; kwargs...) | ||
end | ||
function __internal_solve_up(prob::$(pType), sensealg, u0, u0_changed, | ||
p::AbstractArray{<:TrackedReal}, p_changed, alg, args...; kwargs...) | ||
return __internal_solve_up( | ||
prob, sensealg, u0, true, ArrayInterface.aos_to_soa(p), | ||
true, alg, args...; kwargs...) | ||
end | ||
|
||
function __internal_solve_up(prob::NonlinearProblem, sensealg, | ||
u0::AbstractArray{<:TrackedReal}, u0_changed, p, p_changed, alg, args...; kwargs...) | ||
return __internal_solve_up( | ||
prob, sensealg, u0, true, ArrayInterface.aos_to_soa(p), true, alg, args...; kwargs...) | ||
end | ||
function __internal_solve_up( | ||
prob::$(pType), sensealg, u0::AbstractArray{<:TrackedReal}, | ||
u0_changed, p, p_changed, alg, args...; kwargs...) | ||
return __internal_solve_up( | ||
prob, sensealg, u0, true, ArrayInterface.aos_to_soa(p), | ||
true, alg, args...; kwargs...) | ||
end | ||
|
||
ReverseDiff.@grad function __internal_solve_up( | ||
prob::NonlinearProblem, sensealg, u0, u0_changed, p, p_changed, alg, args...; kwargs...) | ||
out, ∇internal = DiffEqBase._solve_adjoint( | ||
prob, sensealg, ReverseDiff.value(u0), ReverseDiff.value(p), | ||
SciMLBase.ReverseDiffOriginator(), alg, args...; kwargs...) | ||
function ∇__internal_solve_up(_args...) | ||
∂prob, ∂sensealg, ∂u0, ∂p, ∂originator, ∂args... = ∇internal(_args...) | ||
return (∂prob, ∂sensealg, ∂u0, nothing, ∂p, nothing, nothing, ∂args...) | ||
ReverseDiff.@grad function __internal_solve_up( | ||
prob::$(pType), sensealg, u0, u0_changed, | ||
p, p_changed, alg, args...; kwargs...) | ||
out, ∇internal = DiffEqBase._solve_adjoint( | ||
prob, sensealg, ReverseDiff.value(u0), ReverseDiff.value(p), | ||
ReverseDiffOriginator(), alg, args...; kwargs...) | ||
function ∇__internal_solve_up(_args...) | ||
∂prob, ∂sensealg, ∂u0, ∂p, ∂originator, ∂args... = ∇internal(_args...) | ||
return (∂prob, ∂sensealg, ∂u0, nothing, ∂p, nothing, nothing, ∂args...) | ||
end | ||
return Array(out), ∇__internal_solve_up | ||
end | ||
end | ||
return Array(out), ∇__internal_solve_up | ||
end | ||
|
||
end |
2 changes: 1 addition & 1 deletion
2
lib/SimpleNonlinearSolve/ext/SimpleNonlinearSolveStaticArraysExt.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 43 additions & 36 deletions
79
lib/SimpleNonlinearSolve/ext/SimpleNonlinearSolveTrackerExt.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,49 @@ | ||
module SimpleNonlinearSolveTrackerExt | ||
|
||
using DiffEqBase, SciMLBase, SimpleNonlinearSolve, Tracker | ||
|
||
function SimpleNonlinearSolve.__internal_solve_up(prob::NonlinearProblem, | ||
sensealg, u0::TrackedArray, u0_changed, p, p_changed, alg, args...; kwargs...) | ||
return Tracker.track( | ||
SimpleNonlinearSolve.__internal_solve_up, prob, sensealg, u0, u0_changed, | ||
p, p_changed, alg, args...; kwargs...) | ||
end | ||
|
||
function SimpleNonlinearSolve.__internal_solve_up( | ||
prob::NonlinearProblem, sensealg, u0::TrackedArray, u0_changed, | ||
p::TrackedArray, p_changed, alg, args...; kwargs...) | ||
return Tracker.track( | ||
SimpleNonlinearSolve.__internal_solve_up, prob, sensealg, u0, u0_changed, | ||
p, p_changed, alg, args...; kwargs...) | ||
end | ||
|
||
function SimpleNonlinearSolve.__internal_solve_up(prob::NonlinearProblem, | ||
sensealg, u0, u0_changed, p::TrackedArray, p_changed, alg, args...; kwargs...) | ||
return Tracker.track( | ||
SimpleNonlinearSolve.__internal_solve_up, prob, sensealg, u0, u0_changed, | ||
p, p_changed, alg, args...; kwargs...) | ||
end | ||
|
||
Tracker.@grad function SimpleNonlinearSolve.__internal_solve_up(_prob::NonlinearProblem, | ||
sensealg, u0_, u0_changed, p_, p_changed, alg, args...; kwargs...) | ||
u0, p = Tracker.data(u0_), Tracker.data(p_) | ||
prob = remake(_prob; u0, p) | ||
out, ∇internal = DiffEqBase._solve_adjoint(prob, sensealg, u0, p, | ||
SciMLBase.TrackerOriginator(), alg, args...; kwargs...) | ||
|
||
function ∇__internal_solve_up(Δ) | ||
∂prob, ∂sensealg, ∂u0, ∂p, ∂originator, ∂args... = ∇internal(Δ) | ||
return (∂prob, ∂sensealg, ∂u0, nothing, ∂p, nothing, nothing, ∂args...) | ||
using DiffEqBase: DiffEqBase | ||
using SciMLBase: TrackerOriginator, NonlinearProblem, NonlinearLeastSquaresProblem, remake | ||
using SimpleNonlinearSolve: SimpleNonlinearSolve | ||
using Tracker: Tracker, TrackedArray | ||
|
||
for pType in (NonlinearProblem, NonlinearLeastSquaresProblem) | ||
@eval begin | ||
function SimpleNonlinearSolve.__internal_solve_up( | ||
prob::$(pType), sensealg, u0::TrackedArray, | ||
u0_changed, p, p_changed, alg, args...; kwargs...) | ||
return Tracker.track(SimpleNonlinearSolve.__internal_solve_up, prob, sensealg, | ||
u0, u0_changed, p, p_changed, alg, args...; kwargs...) | ||
end | ||
|
||
function SimpleNonlinearSolve.__internal_solve_up( | ||
prob::$(pType), sensealg, u0::TrackedArray, u0_changed, | ||
p::TrackedArray, p_changed, alg, args...; kwargs...) | ||
return Tracker.track(SimpleNonlinearSolve.__internal_solve_up, prob, sensealg, | ||
u0, u0_changed, p, p_changed, alg, args...; kwargs...) | ||
end | ||
|
||
function SimpleNonlinearSolve.__internal_solve_up( | ||
prob::$(pType), sensealg, u0, u0_changed, | ||
p::TrackedArray, p_changed, alg, args...; kwargs...) | ||
return Tracker.track(SimpleNonlinearSolve.__internal_solve_up, prob, sensealg, | ||
u0, u0_changed, p, p_changed, alg, args...; kwargs...) | ||
end | ||
|
||
Tracker.@grad function SimpleNonlinearSolve.__internal_solve_up( | ||
_prob::$(pType), sensealg, u0_, u0_changed, | ||
p_, p_changed, alg, args...; kwargs...) | ||
u0, p = Tracker.data(u0_), Tracker.data(p_) | ||
prob = remake(_prob; u0, p) | ||
out, ∇internal = DiffEqBase._solve_adjoint( | ||
prob, sensealg, u0, p, TrackerOriginator(), alg, args...; kwargs...) | ||
|
||
function ∇__internal_solve_up(Δ) | ||
∂prob, ∂sensealg, ∂u0, ∂p, ∂originator, ∂args... = ∇internal(Δ) | ||
return (∂prob, ∂sensealg, ∂u0, nothing, ∂p, nothing, nothing, ∂args...) | ||
end | ||
|
||
return out, ∇__internal_solve_up | ||
end | ||
end | ||
|
||
return out, ∇__internal_solve_up | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.