From 4d1c76191b7c5e58b17be42cefe5bbb0a1f5a929 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas <1814174+ChrisRackauckas@users.noreply.github.com> Date: Sun, 11 Feb 2024 00:19:29 +0000 Subject: [PATCH] Format .jl files --- .../src/SimpleNonlinearSolve.jl | 17 ++++++++++------- lib/SimpleNonlinearSolve/src/ad.jl | 9 ++++++--- .../src/bracketing/alefeld.jl | 9 ++++++--- .../src/bracketing/bisection.jl | 3 ++- .../src/bracketing/brent.jl | 3 ++- .../src/bracketing/falsi.jl | 3 ++- lib/SimpleNonlinearSolve/src/bracketing/itp.jl | 3 ++- .../src/bracketing/ridder.jl | 3 ++- .../src/nlsolve/lbroyden.jl | 3 ++- .../test/core/rootfind_tests.jl | 9 +++++---- 10 files changed, 39 insertions(+), 23 deletions(-) diff --git a/lib/SimpleNonlinearSolve/src/SimpleNonlinearSolve.jl b/lib/SimpleNonlinearSolve/src/SimpleNonlinearSolve.jl index 3f12d8888..894195106 100644 --- a/lib/SimpleNonlinearSolve/src/SimpleNonlinearSolve.jl +++ b/lib/SimpleNonlinearSolve/src/SimpleNonlinearSolve.jl @@ -4,12 +4,13 @@ import PrecompileTools: @compile_workload, @setup_workload, @recompile_invalidat @recompile_invalidations begin using ADTypes, ArrayInterface, ConcreteStructs, DiffEqBase, FastClosures, FiniteDiff, - ForwardDiff, Reexport, LinearAlgebra, SciMLBase + ForwardDiff, Reexport, LinearAlgebra, SciMLBase import DiffEqBase: AbstractNonlinearTerminationMode, - AbstractSafeNonlinearTerminationMode, AbstractSafeBestNonlinearTerminationMode, - NonlinearSafeTerminationReturnCode, get_termination_mode, - NONLINEARSOLVE_DEFAULT_NORM + AbstractSafeNonlinearTerminationMode, + AbstractSafeBestNonlinearTerminationMode, + NonlinearSafeTerminationReturnCode, get_termination_mode, + NONLINEARSOLVE_DEFAULT_NORM import ForwardDiff: Dual import MaybeInplace: @bb, setindex_trait, CanSetindex, CannotSetindex import SciMLBase: AbstractNonlinearAlgorithm, build_solution, isinplace, _unwrap_val @@ -56,14 +57,16 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Nothing, args...; end # By Pass the highlevel checks for NonlinearProblem for Simple Algorithms -function SciMLBase.solve(prob::NonlinearProblem, alg::AbstractSimpleNonlinearSolveAlgorithm, +function SciMLBase.solve( + prob::NonlinearProblem, alg::AbstractSimpleNonlinearSolveAlgorithm, args...; sensealg = nothing, u0 = nothing, p = nothing, kwargs...) if sensealg === nothing && haskey(prob.kwargs, :sensealg) sensealg = prob.kwargs[:sensealg] end new_u0 = u0 !== nothing ? u0 : prob.u0 new_p = p !== nothing ? p : prob.p - return __internal_solve_up(prob, sensealg, new_u0, u0 === nothing, new_p, p === nothing, + return __internal_solve_up( + prob, sensealg, new_u0, u0 === nothing, new_p, p === nothing, alg, args...; kwargs...) end @@ -111,7 +114,7 @@ end end export SimpleBroyden, SimpleDFSane, SimpleGaussNewton, SimpleHalley, SimpleKlement, - SimpleLimitedMemoryBroyden, SimpleNewtonRaphson, SimpleTrustRegion + SimpleLimitedMemoryBroyden, SimpleNewtonRaphson, SimpleTrustRegion export Alefeld, Bisection, Brent, Falsi, ITP, Ridder end # module diff --git a/lib/SimpleNonlinearSolve/src/ad.jl b/lib/SimpleNonlinearSolve/src/ad.jl index a4a777be6..b4f7f41b9 100644 --- a/lib/SimpleNonlinearSolve/src/ad.jl +++ b/lib/SimpleNonlinearSolve/src/ad.jl @@ -1,15 +1,18 @@ -function SciMLBase.solve(prob::NonlinearProblem{<:Union{Number, <:AbstractArray}, +function SciMLBase.solve( + prob::NonlinearProblem{<:Union{Number, <:AbstractArray}, iip, <:Union{<:Dual{T, V, P}, <:AbstractArray{<:Dual{T, V, P}}}}, alg::AbstractSimpleNonlinearSolveAlgorithm, args...; kwargs...) where {T, V, P, iip} sol, partials = __nlsolve_ad(prob, alg, args...; kwargs...) dual_soln = __nlsolve_dual_soln(sol.u, partials, prob.p) - return SciMLBase.build_solution(prob, alg, dual_soln, sol.resid; sol.retcode, sol.stats, + return SciMLBase.build_solution( + prob, alg, dual_soln, sol.resid; sol.retcode, sol.stats, sol.original) end for algType in (Bisection, Brent, Alefeld, Falsi, ITP, Ridder) @eval begin - function SciMLBase.solve(prob::IntervalNonlinearProblem{uType, iip, + function SciMLBase.solve( + prob::IntervalNonlinearProblem{uType, iip, <:Union{<:Dual{T, V, P}, <:AbstractArray{<:Dual{T, V, P}}}}, alg::$(algType), args...; kwargs...) where {uType, T, V, P, iip} sol, partials = __nlsolve_ad(prob, alg, args...; kwargs...) diff --git a/lib/SimpleNonlinearSolve/src/bracketing/alefeld.jl b/lib/SimpleNonlinearSolve/src/bracketing/alefeld.jl index 39c984fd5..3b89751a7 100644 --- a/lib/SimpleNonlinearSolve/src/bracketing/alefeld.jl +++ b/lib/SimpleNonlinearSolve/src/bracketing/alefeld.jl @@ -38,7 +38,8 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Alefeld, args...; end ē, fc = d, f(c) (a == c || b == c) && - return build_solution(prob, alg, c, fc; retcode = ReturnCode.FloatingPointLimit, + return build_solution( + prob, alg, c, fc; retcode = ReturnCode.FloatingPointLimit, left = a, right = b) iszero(fc) && return build_solution(prob, alg, c, fc; retcode = ReturnCode.Success, @@ -57,7 +58,8 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Alefeld, args...; end fc = f(c) (ā == c || b̄ == c) && - return build_solution(prob, alg, c, fc; retcode = ReturnCode.FloatingPointLimit, + return build_solution( + prob, alg, c, fc; retcode = ReturnCode.FloatingPointLimit, left = ā, right = b̄) iszero(fc) && return build_solution(prob, alg, c, fc; retcode = ReturnCode.Success, @@ -76,7 +78,8 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Alefeld, args...; end fc = f(c) (ā == c || b̄ == c) && - return build_solution(prob, alg, c, fc; retcode = ReturnCode.FloatingPointLimit, + return build_solution( + prob, alg, c, fc; retcode = ReturnCode.FloatingPointLimit, left = ā, right = b̄) iszero(fc) && return build_solution(prob, alg, c, fc; retcode = ReturnCode.Success, diff --git a/lib/SimpleNonlinearSolve/src/bracketing/bisection.jl b/lib/SimpleNonlinearSolve/src/bracketing/bisection.jl index 38f9cb9eb..acadf6aa1 100644 --- a/lib/SimpleNonlinearSolve/src/bracketing/bisection.jl +++ b/lib/SimpleNonlinearSolve/src/bracketing/bisection.jl @@ -35,7 +35,8 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Bisection, args... end if iszero(fr) - return build_solution(prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, + return build_solution( + prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, left, right) end diff --git a/lib/SimpleNonlinearSolve/src/bracketing/brent.jl b/lib/SimpleNonlinearSolve/src/bracketing/brent.jl index f37c45e4a..89b2e60be 100644 --- a/lib/SimpleNonlinearSolve/src/bracketing/brent.jl +++ b/lib/SimpleNonlinearSolve/src/bracketing/brent.jl @@ -22,7 +22,8 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Brent, args...; end if iszero(fr) - return build_solution(prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, + return build_solution( + prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, left, right) end diff --git a/lib/SimpleNonlinearSolve/src/bracketing/falsi.jl b/lib/SimpleNonlinearSolve/src/bracketing/falsi.jl index 86086f81a..896e07329 100644 --- a/lib/SimpleNonlinearSolve/src/bracketing/falsi.jl +++ b/lib/SimpleNonlinearSolve/src/bracketing/falsi.jl @@ -21,7 +21,8 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Falsi, args...; end if iszero(fr) - return build_solution(prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, + return build_solution( + prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, left, right) end diff --git a/lib/SimpleNonlinearSolve/src/bracketing/itp.jl b/lib/SimpleNonlinearSolve/src/bracketing/itp.jl index cce5eafea..3f2069b72 100644 --- a/lib/SimpleNonlinearSolve/src/bracketing/itp.jl +++ b/lib/SimpleNonlinearSolve/src/bracketing/itp.jl @@ -67,7 +67,8 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::ITP, args...; end if iszero(fr) - return build_solution(prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, + return build_solution( + prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, left, right) end ϵ = abstol diff --git a/lib/SimpleNonlinearSolve/src/bracketing/ridder.jl b/lib/SimpleNonlinearSolve/src/bracketing/ridder.jl index cd18060d5..3b23f4287 100644 --- a/lib/SimpleNonlinearSolve/src/bracketing/ridder.jl +++ b/lib/SimpleNonlinearSolve/src/bracketing/ridder.jl @@ -21,7 +21,8 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Ridder, args...; end if iszero(fr) - return build_solution(prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, + return build_solution( + prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, left, right) end diff --git a/lib/SimpleNonlinearSolve/src/nlsolve/lbroyden.jl b/lib/SimpleNonlinearSolve/src/nlsolve/lbroyden.jl index 9f8896ed1..145a5467d 100644 --- a/lib/SimpleNonlinearSolve/src/nlsolve/lbroyden.jl +++ b/lib/SimpleNonlinearSolve/src/nlsolve/lbroyden.jl @@ -137,7 +137,8 @@ function __static_solve(prob::NonlinearProblem{<:SArray}, alg::SimpleLimitedMemo init_α = inv(alg.alpha) end - converged, res = __unrolled_lbroyden_initial_iterations(prob, xo, fo, δx, abstol, U, Vᵀ, + converged, res = __unrolled_lbroyden_initial_iterations( + prob, xo, fo, δx, abstol, U, Vᵀ, threshold, ls_cache, init_α) converged && diff --git a/lib/SimpleNonlinearSolve/test/core/rootfind_tests.jl b/lib/SimpleNonlinearSolve/test/core/rootfind_tests.jl index dc6054273..005651568 100644 --- a/lib/SimpleNonlinearSolve/test/core/rootfind_tests.jl +++ b/lib/SimpleNonlinearSolve/test/core/rootfind_tests.jl @@ -1,7 +1,7 @@ @testsetup module RootfindingTesting using Reexport @reexport using AllocCheck, - LinearSolve, StaticArrays, Random, LinearAlgebra, ForwardDiff, DiffEqBase + LinearSolve, StaticArrays, Random, LinearAlgebra, ForwardDiff, DiffEqBase import PolyesterForwardDiff quadratic_f(u, p) = u .* u .- p @@ -22,7 +22,7 @@ end const TERMINATION_CONDITIONS = [ NormTerminationMode(), RelTerminationMode(), RelNormTerminationMode(), AbsTerminationMode(), AbsNormTerminationMode(), RelSafeTerminationMode(), - AbsSafeTerminationMode(), RelSafeBestTerminationMode(), AbsSafeBestTerminationMode(), + AbsSafeTerminationMode(), RelSafeBestTerminationMode(), AbsSafeBestTerminationMode() ] function benchmark_nlsolve_oop(f::F, u0, p = 2.0; solver) where {F} @@ -35,7 +35,7 @@ function benchmark_nlsolve_iip(f!::F, u0, p = 2.0; solver) where {F} end export quadratic_f, quadratic_f!, quadratic_f2, newton_fails, TERMINATION_CONDITIONS, - benchmark_nlsolve_oop, benchmark_nlsolve_iip + benchmark_nlsolve_oop, benchmark_nlsolve_iip end @@ -43,7 +43,8 @@ end @testset "$(alg)" for alg in (SimpleNewtonRaphson, SimpleTrustRegion, (args...; kwargs...) -> SimpleTrustRegion(args...; nlsolve_update_rule = Val(true), kwargs...)) - @testset "AutoDiff: $(nameof(typeof(autodiff))))" for autodiff in (AutoFiniteDiff(), + @testset "AutoDiff: $(nameof(typeof(autodiff))))" for autodiff in ( + AutoFiniteDiff(), AutoForwardDiff(), AutoPolyesterForwardDiff()) @testset "[OOP] u0: $(typeof(u0))" for u0 in ([1.0, 1.0], @SVector[1.0, 1.0], 1.0)