From 066912c3488dc65fbc625b3dbaa244182996436a Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Fri, 24 May 2024 19:10:54 -0700 Subject: [PATCH] Run formatter --- src/core/approximate_jacobian.jl | 9 ++++----- src/core/generalized_first_order.jl | 11 ++++++----- src/core/generic.jl | 2 +- src/descent/steepest.jl | 8 ++++---- src/globalization/line_search.jl | 8 ++++---- src/globalization/trust_region.jl | 4 ++-- src/internal/approximate_initialization.jl | 8 ++++---- src/internal/helpers.jl | 3 ++- src/internal/jacobian.jl | 9 ++++----- src/utils.jl | 5 +++-- 10 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/core/approximate_jacobian.jl b/src/core/approximate_jacobian.jl index 4711ed719..e61f34032 100644 --- a/src/core/approximate_jacobian.jl +++ b/src/core/approximate_jacobian.jl @@ -165,8 +165,8 @@ function SciMLBase.__init( INV = store_inverse_jacobian(alg.update_rule) linsolve = get_linear_solver(alg.descent) - initialization_cache = __internal_init( - prob, alg.initialization, alg, f, fu, u, p; stats, linsolve, maxiters, internalnorm) + initialization_cache = __internal_init(prob, alg.initialization, alg, f, fu, u, p; + stats, linsolve, maxiters, internalnorm) abstol, reltol, termination_cache = init_termination_cache( prob, abstol, reltol, fu, u, termination_condition) @@ -174,9 +174,8 @@ function SciMLBase.__init( J = initialization_cache(nothing) inv_workspace, J = INV ? __safe_inv_workspace(J) : (nothing, J) - descent_cache = __internal_init( - prob, alg.descent, J, fu, u; stats, abstol, reltol, internalnorm, - linsolve_kwargs, pre_inverted = Val(INV), timer) + descent_cache = __internal_init(prob, alg.descent, J, fu, u; stats, abstol, reltol, + internalnorm, linsolve_kwargs, pre_inverted = Val(INV), timer) du = get_du(descent_cache) reinit_rule_cache = __internal_init(alg.reinit_rule, J, fu, u, du) diff --git a/src/core/generalized_first_order.jl b/src/core/generalized_first_order.jl index 5e7e5f144..84e74478f 100644 --- a/src/core/generalized_first_order.jl +++ b/src/core/generalized_first_order.jl @@ -153,9 +153,10 @@ end function SciMLBase.__init( prob::AbstractNonlinearProblem{uType, iip}, alg::GeneralizedFirstOrderAlgorithm, - args...; stats=empty_nlstats(), alias_u0 = false, maxiters = 1000, abstol = nothing, - reltol = nothing, maxtime = nothing, termination_condition = nothing, - internalnorm = DEFAULT_NORM, linsolve_kwargs = (;), kwargs...) where {uType, iip} + args...; stats = empty_nlstats(), alias_u0 = false, maxiters = 1000, + abstol = nothing, reltol = nothing, maxtime = nothing, + termination_condition = nothing, internalnorm = DEFAULT_NORM, + linsolve_kwargs = (;), kwargs...) where {uType, iip} timer = get_timer_output() @static_timeit timer "cache construction" begin (; f, u0, p) = prob @@ -173,8 +174,8 @@ function SciMLBase.__init( prob, alg, f, fu, u, p; stats, autodiff = alg.jacobian_ad, linsolve, jvp_autodiff = alg.forward_ad, vjp_autodiff = alg.reverse_ad) J = jac_cache(nothing) - descent_cache = __internal_init(prob, alg.descent, J, fu, u; stats, abstol, reltol, - internalnorm, linsolve_kwargs, timer) + descent_cache = __internal_init(prob, alg.descent, J, fu, u; stats, abstol, + reltol, internalnorm, linsolve_kwargs, timer) du = get_du(descent_cache) if alg.trustregion !== missing && alg.linesearch !== missing diff --git a/src/core/generic.jl b/src/core/generic.jl index 76135115c..44e6e1152 100644 --- a/src/core/generic.jl +++ b/src/core/generic.jl @@ -1,5 +1,5 @@ function SciMLBase.__solve(prob::Union{NonlinearProblem, NonlinearLeastSquaresProblem}, - alg::AbstractNonlinearSolveAlgorithm, args...; stats=empty_nlstats(), kwargs...) + alg::AbstractNonlinearSolveAlgorithm, args...; stats = empty_nlstats(), kwargs...) cache = SciMLBase.__init(prob, alg, args...; stats, kwargs...) return solve!(cache) end diff --git a/src/descent/steepest.jl b/src/descent/steepest.jl index 46f2cf10c..cc2f4d128 100644 --- a/src/descent/steepest.jl +++ b/src/descent/steepest.jl @@ -30,8 +30,8 @@ end @internal_caches SteepestDescentCache :lincache @inline function __internal_init( - prob::AbstractNonlinearProblem, alg::SteepestDescent, J, fu, - u; stats, shared::Val{N} = Val(1), pre_inverted::Val{INV} = False, + prob::AbstractNonlinearProblem, alg::SteepestDescent, J, fu, u; + stats, shared::Val{N} = Val(1), pre_inverted::Val{INV} = False, linsolve_kwargs = (;), abstol = nothing, reltol = nothing, timer = get_timer_output(), kwargs...) where {INV, N} INV && @assert length(fu)==length(u) "Non-Square Jacobian Inverse doesn't make sense." @@ -40,8 +40,8 @@ end @bb δu_ = similar(u) end if INV - lincache = LinearSolverCache(alg, alg.linsolve, transpose(J), _vec(fu), - _vec(u); stats, abstol, reltol, linsolve_kwargs...) + lincache = LinearSolverCache(alg, alg.linsolve, transpose(J), _vec(fu), _vec(u); + stats, abstol, reltol, linsolve_kwargs...) else lincache = nothing end diff --git a/src/globalization/line_search.jl b/src/globalization/line_search.jl index f903a154f..038cc119a 100644 --- a/src/globalization/line_search.jl +++ b/src/globalization/line_search.jl @@ -251,8 +251,8 @@ end end function __internal_init( - prob::AbstractNonlinearProblem, alg::RobustNonMonotoneLineSearch, f::F, fu, - u, p, args...; stats, internalnorm::IN = DEFAULT_NORM, kwargs...) where {F, IN} + prob::AbstractNonlinearProblem, alg::RobustNonMonotoneLineSearch, f::F, fu, u, + p, args...; stats, internalnorm::IN = DEFAULT_NORM, kwargs...) where {F, IN} @bb u_cache = similar(u) @bb fu_cache = similar(fu) T = promote_type(eltype(fu), eltype(u)) @@ -343,8 +343,8 @@ end end function __internal_init( - prob::AbstractNonlinearProblem, alg::LiFukushimaLineSearch, f::F, fu, u, - p, args...; stats, internalnorm::IN = DEFAULT_NORM, kwargs...) where {F, IN} + prob::AbstractNonlinearProblem, alg::LiFukushimaLineSearch, f::F, fu, u, p, + args...; stats, internalnorm::IN = DEFAULT_NORM, kwargs...) where {F, IN} @bb u_cache = similar(u) @bb fu_cache = similar(fu) T = promote_type(eltype(fu), eltype(u)) diff --git a/src/globalization/trust_region.jl b/src/globalization/trust_region.jl index 6ff20266d..51b54959e 100644 --- a/src/globalization/trust_region.jl +++ b/src/globalization/trust_region.jl @@ -366,8 +366,8 @@ end @inline __expand_factor(::Nothing, ::Type{T}, method) where {T} = T(2) function __internal_init( - prob::AbstractNonlinearProblem, alg::GenericTrustRegionScheme, f::F, fu, - u, p, args...; stats, internalnorm::IF = DEFAULT_NORM, kwargs...) where {F, IF} + prob::AbstractNonlinearProblem, alg::GenericTrustRegionScheme, f::F, fu, u, + p, args...; stats, internalnorm::IF = DEFAULT_NORM, kwargs...) where {F, IF} T = promote_type(eltype(u), eltype(fu)) u0_norm = internalnorm(u) fu_norm = internalnorm(fu) diff --git a/src/internal/approximate_initialization.jl b/src/internal/approximate_initialization.jl index a1f36f475..4f17cd72f 100644 --- a/src/internal/approximate_initialization.jl +++ b/src/internal/approximate_initialization.jl @@ -145,12 +145,12 @@ make a selection automatically. autodiff end -function __internal_init( - prob::AbstractNonlinearProblem, alg::TrueJacobianInitialization, solver, f::F, fu, - u, p; linsolve = missing, internalnorm::IN = DEFAULT_NORM, kwargs...) where {F, IN} +function __internal_init(prob::AbstractNonlinearProblem, alg::TrueJacobianInitialization, + solver, f::F, fu, u, p; stats, linsolve = missing, + internalnorm::IN = DEFAULT_NORM, kwargs...) where {F, IN} autodiff = get_concrete_forward_ad( alg.autodiff, prob; check_forward_mode = false, kwargs...) - jac_cache = JacobianCache(prob, solver, prob.f, fu, u, p; autodiff, linsolve) + jac_cache = JacobianCache(prob, solver, prob.f, fu, u, p; stats, autodiff, linsolve) J = alg.structure(jac_cache(nothing)) return InitializedApproximateJacobianCache( J, alg.structure, alg, jac_cache, false, internalnorm) diff --git a/src/internal/helpers.jl b/src/internal/helpers.jl index 5211573f3..c5241481a 100644 --- a/src/internal/helpers.jl +++ b/src/internal/helpers.jl @@ -168,7 +168,8 @@ end function __construct_extension_jac(prob, alg, u0, fu; can_handle_oop::Val = False, can_handle_scalar::Val = False, kwargs...) - Jₚ = JacobianCache(prob, alg, prob.f, fu, u0, prob.p; kwargs...) + Jₚ = JacobianCache( + prob, alg, prob.f, fu, u0, prob.p; stats = empty_nlstats(), kwargs...) 𝓙 = (can_handle_scalar === False && prob.u0 isa Number) ? @closure(u->[Jₚ(u[1])]) : Jₚ diff --git a/src/internal/jacobian.jl b/src/internal/jacobian.jl index 87f02a0fa..2abd89336 100644 --- a/src/internal/jacobian.jl +++ b/src/internal/jacobian.jl @@ -49,9 +49,8 @@ function reinit_cache!(cache::JacobianCache{iip}, args...; p = cache.p, cache.uf = JacobianWrapper{iip}(cache.f, p) end -function JacobianCache( - prob, alg, f::F, fu_, u, p; stats, autodiff = nothing, vjp_autodiff = nothing, - jvp_autodiff = nothing, linsolve = missing) where {F} +function JacobianCache(prob, alg, f::F, fu_, u, p; stats, autodiff = nothing, + vjp_autodiff = nothing, jvp_autodiff = nothing, linsolve = missing) where {F} iip = isinplace(prob) uf = JacobianWrapper{iip}(f, p) @@ -96,8 +95,8 @@ function JacobianCache( J, f, uf, fu, u, p, jac_cache, alg, stats, autodiff, vjp_autodiff, jvp_autodiff) end -function JacobianCache( - prob, alg, f::F, ::Number, u::Number, p; stats, autodiff = nothing, kwargs...) where {F} +function JacobianCache(prob, alg, f::F, ::Number, u::Number, p; stats, + autodiff = nothing, kwargs...) where {F} uf = JacobianWrapper{false}(f, p) autodiff = get_concrete_forward_ad(autodiff, prob; check_forward_mode = false) if !(autodiff isa AutoForwardDiff || diff --git a/src/utils.jl b/src/utils.jl index 1cd552aa1..d13555259 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -146,8 +146,9 @@ function __build_solution_less_specialize(prob::AbstractNonlinearProblem, alg, u T = eltype(eltype(u)) N = ndims(u) - return SciMLBase.NonlinearSolution{T, N, typeof(u), typeof(resid), typeof(prob), - typeof(alg), Any, typeof(left), typeof(stats), typeof(trace)}( + return SciMLBase.NonlinearSolution{ + T, N, typeof(u), typeof(resid), typeof(prob), typeof(alg), + Any, typeof(left), typeof(stats), typeof(trace)}( u, resid, prob, alg, retcode, original, left, right, stats, trace) end