From 66a073214d2fa4b3786f3310536ce92b2fc7a277 Mon Sep 17 00:00:00 2001 From: FHoltorf Date: Tue, 21 Nov 2023 22:20:46 -0500 Subject: [PATCH] run formatter --- .../ext/SimpleNonlinearSolveNNlibExt.jl | 10 +++--- .../src/SimpleNonlinearSolve.jl | 2 +- lib/SimpleNonlinearSolve/src/ad.jl | 36 +++++++++---------- lib/SimpleNonlinearSolve/src/alefeld.jl | 6 ++-- .../src/batched/dfsane.jl | 12 +++---- .../src/batched/raphson.jl | 12 +++---- lib/SimpleNonlinearSolve/src/batched/utils.jl | 6 ++-- lib/SimpleNonlinearSolve/src/bisection.jl | 4 +-- lib/SimpleNonlinearSolve/src/brent.jl | 4 +-- lib/SimpleNonlinearSolve/src/broyden.jl | 8 ++--- lib/SimpleNonlinearSolve/src/dfsane.jl | 18 +++++----- lib/SimpleNonlinearSolve/src/falsi.jl | 4 +-- lib/SimpleNonlinearSolve/src/halley.jl | 8 ++--- lib/SimpleNonlinearSolve/src/itp.jl | 4 +-- lib/SimpleNonlinearSolve/src/klement.jl | 6 ++-- lib/SimpleNonlinearSolve/src/lbroyden.jl | 18 +++++----- lib/SimpleNonlinearSolve/src/raphson.jl | 19 +++++----- lib/SimpleNonlinearSolve/src/ridder.jl | 4 +-- lib/SimpleNonlinearSolve/src/trustRegion.jl | 28 +++++++-------- lib/SimpleNonlinearSolve/src/utils.jl | 8 ++--- lib/SimpleNonlinearSolve/test/inplace.jl | 4 +-- 21 files changed, 111 insertions(+), 110 deletions(-) diff --git a/lib/SimpleNonlinearSolve/ext/SimpleNonlinearSolveNNlibExt.jl b/lib/SimpleNonlinearSolve/ext/SimpleNonlinearSolveNNlibExt.jl index 5b06530a6..1132b64b7 100644 --- a/lib/SimpleNonlinearSolve/ext/SimpleNonlinearSolveNNlibExt.jl +++ b/lib/SimpleNonlinearSolve/ext/SimpleNonlinearSolveNNlibExt.jl @@ -10,11 +10,11 @@ function __init__() end @views function SciMLBase.__solve(prob::NonlinearProblem, - alg::BatchedBroyden; - abstol = nothing, - reltol = nothing, - maxiters = 1000, - kwargs...) + alg::BatchedBroyden; + abstol = nothing, + reltol = nothing, + maxiters = 1000, + kwargs...) iip = isinplace(prob) u, f, reconstruct = _construct_batched_problem_structure(prob) diff --git a/lib/SimpleNonlinearSolve/src/SimpleNonlinearSolve.jl b/lib/SimpleNonlinearSolve/src/SimpleNonlinearSolve.jl index cfd73e3b1..8c84c4377 100644 --- a/lib/SimpleNonlinearSolve/src/SimpleNonlinearSolve.jl +++ b/lib/SimpleNonlinearSolve/src/SimpleNonlinearSolve.jl @@ -50,7 +50,7 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem; kwargs...) end function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Nothing, - args...; kwargs...) + args...; kwargs...) SciMLBase.solve(prob, ITP(), args...; kwargs...) end diff --git a/lib/SimpleNonlinearSolve/src/ad.jl b/lib/SimpleNonlinearSolve/src/ad.jl index 009cd227b..b0fd9f11c 100644 --- a/lib/SimpleNonlinearSolve/src/ad.jl +++ b/lib/SimpleNonlinearSolve/src/ad.jl @@ -29,19 +29,19 @@ function scalar_nlsolve_ad(prob, alg, args...; kwargs...) end function SciMLBase.solve(prob::NonlinearProblem{<:Union{Number, StaticArraysCore.SVector}, - iip, - <:Dual{T, V, P}}, - alg::AbstractSimpleNonlinearSolveAlgorithm, - args...; kwargs...) where {iip, T, V, P} + iip, + <:Dual{T, V, P}}, + alg::AbstractSimpleNonlinearSolveAlgorithm, + args...; kwargs...) where {iip, T, V, P} sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...) return SciMLBase.build_solution(prob, alg, Dual{T, V, P}(sol.u, partials), sol.resid; retcode = sol.retcode) end function SciMLBase.solve(prob::NonlinearProblem{<:Union{Number, StaticArraysCore.SVector}, - iip, - <:AbstractArray{<:Dual{T, V, P}}}, - alg::AbstractSimpleNonlinearSolveAlgorithm, args...; - kwargs...) where {iip, T, V, P} + iip, + <:AbstractArray{<:Dual{T, V, P}}}, + alg::AbstractSimpleNonlinearSolveAlgorithm, args...; + kwargs...) where {iip, T, V, P} sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...) return SciMLBase.build_solution(prob, alg, Dual{T, V, P}(sol.u, partials), sol.resid; retcode = sol.retcode) @@ -50,9 +50,9 @@ end # avoid ambiguities for Alg in [Bisection] @eval function SciMLBase.solve(prob::IntervalNonlinearProblem{uType, iip, - <:Dual{T, V, P}}, - alg::$Alg, args...; - kwargs...) where {uType, iip, T, V, P} + <:Dual{T, V, P}}, + alg::$Alg, args...; + kwargs...) where {uType, iip, T, V, P} sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...) return SciMLBase.build_solution(prob, alg, Dual{T, V, P}(sol.u, partials), sol.resid; retcode = sol.retcode, @@ -61,13 +61,13 @@ for Alg in [Bisection] #return BracketingSolution(Dual{T,V,P}(sol.left, partials), Dual{T,V,P}(sol.right, partials), sol.retcode, sol.resid) end @eval function SciMLBase.solve(prob::IntervalNonlinearProblem{uType, iip, - <:AbstractArray{ - <:Dual{T, - V, - P}, - }}, - alg::$Alg, args...; - kwargs...) where {uType, iip, T, V, P} + <:AbstractArray{ + <:Dual{T, + V, + P}, + }}, + alg::$Alg, args...; + kwargs...) where {uType, iip, T, V, P} sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...) return SciMLBase.build_solution(prob, alg, Dual{T, V, P}(sol.u, partials), sol.resid; retcode = sol.retcode, diff --git a/lib/SimpleNonlinearSolve/src/alefeld.jl b/lib/SimpleNonlinearSolve/src/alefeld.jl index a2669ca96..0d4f56116 100644 --- a/lib/SimpleNonlinearSolve/src/alefeld.jl +++ b/lib/SimpleNonlinearSolve/src/alefeld.jl @@ -9,9 +9,9 @@ algorithm 4.1 because, in certain sense, the second algorithm(4.2) is an optimal struct Alefeld <: AbstractBracketingAlgorithm end function SciMLBase.solve(prob::IntervalNonlinearProblem, - alg::Alefeld, args...; abstol = nothing, - reltol = nothing, - maxiters = 1000, kwargs...) + alg::Alefeld, args...; abstol = nothing, + reltol = nothing, + maxiters = 1000, kwargs...) f = Base.Fix2(prob.f, prob.p) a, b = prob.tspan c = a - (b - a) / (f(b) - f(a)) * f(a) diff --git a/lib/SimpleNonlinearSolve/src/batched/dfsane.jl b/lib/SimpleNonlinearSolve/src/batched/dfsane.jl index 60bb6ae12..01b3b1996 100644 --- a/lib/SimpleNonlinearSolve/src/batched/dfsane.jl +++ b/lib/SimpleNonlinearSolve/src/batched/dfsane.jl @@ -16,12 +16,12 @@ Base.@kwdef struct BatchedSimpleDFSane{T, F, TC <: NLSolveTerminationCondition} end function SciMLBase.__solve(prob::NonlinearProblem, - alg::BatchedSimpleDFSane, - args...; - abstol = nothing, - reltol = nothing, - maxiters = 100, - kwargs...) + alg::BatchedSimpleDFSane, + args...; + abstol = nothing, + reltol = nothing, + maxiters = 100, + kwargs...) iip = isinplace(prob) u, f, reconstruct = _construct_batched_problem_structure(prob) diff --git a/lib/SimpleNonlinearSolve/src/batched/raphson.jl b/lib/SimpleNonlinearSolve/src/batched/raphson.jl index a141819bc..7bc7b8c4a 100644 --- a/lib/SimpleNonlinearSolve/src/batched/raphson.jl +++ b/lib/SimpleNonlinearSolve/src/batched/raphson.jl @@ -7,18 +7,18 @@ alg_autodiff(alg::BatchedSimpleNewtonRaphson{CS, AD, FDT}) where {CS, AD, FDT} = diff_type(alg::BatchedSimpleNewtonRaphson{CS, AD, FDT}) where {CS, AD, FDT} = FDT function BatchedSimpleNewtonRaphson(; chunk_size = Val{0}(), - autodiff = Val{true}(), - diff_type = Val{:forward}, - termination_condition = NLSolveTerminationCondition(NLSolveTerminationMode.NLSolveDefault; - abstol = nothing, - reltol = nothing)) + autodiff = Val{true}(), + diff_type = Val{:forward}, + termination_condition = NLSolveTerminationCondition(NLSolveTerminationMode.NLSolveDefault; + abstol = nothing, + reltol = nothing)) return BatchedSimpleNewtonRaphson{SciMLBase._unwrap_val(chunk_size), SciMLBase._unwrap_val(autodiff), SciMLBase._unwrap_val(diff_type), typeof(termination_condition)}(termination_condition) end function SciMLBase.__solve(prob::NonlinearProblem, alg::BatchedSimpleNewtonRaphson; - abstol = nothing, reltol = nothing, maxiters = 1000, kwargs...) + abstol = nothing, reltol = nothing, maxiters = 1000, kwargs...) iip = SciMLBase.isinplace(prob) iip && @assert alg_autodiff(alg) "Inplace BatchedSimpleNewtonRaphson currently only supports autodiff." diff --git a/lib/SimpleNonlinearSolve/src/batched/utils.jl b/lib/SimpleNonlinearSolve/src/batched/utils.jl index 7b85011f1..b8e66fe80 100644 --- a/lib/SimpleNonlinearSolve/src/batched/utils.jl +++ b/lib/SimpleNonlinearSolve/src/batched/utils.jl @@ -27,9 +27,9 @@ function _construct_batched_problem_structure(prob) end function _construct_batched_problem_structure(u0::AbstractArray{T, N}, - f, - p, - ::Val{iip}) where {T, N, iip} + f, + p, + ::Val{iip}) where {T, N, iip} # Reconstruct `u` reconstruct = N == 2 ? identity : Base.Fix2(reshape, size(u0)) # Standardize `u` diff --git a/lib/SimpleNonlinearSolve/src/bisection.jl b/lib/SimpleNonlinearSolve/src/bisection.jl index 24db4adcc..f7c98aa65 100644 --- a/lib/SimpleNonlinearSolve/src/bisection.jl +++ b/lib/SimpleNonlinearSolve/src/bisection.jl @@ -20,8 +20,8 @@ function Bisection(; exact_left = false, exact_right = false) end function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Bisection, args...; - maxiters = 1000, abstol = min(eps(prob.tspan[1]), eps(prob.tspan[2])), - kwargs...) + maxiters = 1000, abstol = min(eps(prob.tspan[1]), eps(prob.tspan[2])), + kwargs...) f = Base.Fix2(prob.f, prob.p) left, right = prob.tspan fl, fr = f(left), f(right) diff --git a/lib/SimpleNonlinearSolve/src/brent.jl b/lib/SimpleNonlinearSolve/src/brent.jl index 47e5495f0..7d7a6bcf9 100644 --- a/lib/SimpleNonlinearSolve/src/brent.jl +++ b/lib/SimpleNonlinearSolve/src/brent.jl @@ -7,8 +7,8 @@ A non-allocating Brent method struct Brent <: AbstractBracketingAlgorithm end function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Brent, args...; - maxiters = 1000, abstol = min(eps(prob.tspan[1]), eps(prob.tspan[2])), - kwargs...) + maxiters = 1000, abstol = min(eps(prob.tspan[1]), eps(prob.tspan[2])), + kwargs...) f = Base.Fix2(prob.f, prob.p) a, b = prob.tspan fa, fb = f(a), f(b) diff --git a/lib/SimpleNonlinearSolve/src/broyden.jl b/lib/SimpleNonlinearSolve/src/broyden.jl index 045345f29..07b2609f9 100644 --- a/lib/SimpleNonlinearSolve/src/broyden.jl +++ b/lib/SimpleNonlinearSolve/src/broyden.jl @@ -18,9 +18,9 @@ struct Broyden{TC <: NLSolveTerminationCondition} <: end function Broyden(; batched = false, - termination_condition = NLSolveTerminationCondition(NLSolveTerminationMode.NLSolveDefault; - abstol = nothing, - reltol = nothing)) + termination_condition = NLSolveTerminationCondition(NLSolveTerminationMode.NLSolveDefault; + abstol = nothing, + reltol = nothing)) if batched @assert NNlibExtLoaded[] "Please install and load `NNlib.jl` to use batched Broyden." return BatchedBroyden(termination_condition) @@ -29,7 +29,7 @@ function Broyden(; batched = false, end function SciMLBase.__solve(prob::NonlinearProblem, alg::Broyden, args...; - abstol = nothing, reltol = nothing, maxiters = 1000, kwargs...) + abstol = nothing, reltol = nothing, maxiters = 1000, kwargs...) tc = alg.termination_condition mode = DiffEqBase.get_termination_mode(tc) f = Base.Fix2(prob.f, prob.p) diff --git a/lib/SimpleNonlinearSolve/src/dfsane.jl b/lib/SimpleNonlinearSolve/src/dfsane.jl index 2e52cde4f..49c50bca3 100644 --- a/lib/SimpleNonlinearSolve/src/dfsane.jl +++ b/lib/SimpleNonlinearSolve/src/dfsane.jl @@ -65,13 +65,13 @@ struct SimpleDFSane{T, TC} <: AbstractSimpleNonlinearSolveAlgorithm end function SimpleDFSane(; σ_min::Real = 1e-10, σ_max::Real = 1e10, σ_1::Real = 1.0, - M::Int = 10, γ::Real = 1e-4, τ_min::Real = 0.1, τ_max::Real = 0.5, - nexp::Int = 2, η_strategy::Function = (f_1, k, x, F) -> f_1 ./ k^2, - termination_condition = NLSolveTerminationCondition(NLSolveTerminationMode.NLSolveDefault; - abstol = nothing, - reltol = nothing), - batched::Bool = false, - max_inner_iterations = 1000) + M::Int = 10, γ::Real = 1e-4, τ_min::Real = 0.1, τ_max::Real = 0.5, + nexp::Int = 2, η_strategy::Function = (f_1, k, x, F) -> f_1 ./ k^2, + termination_condition = NLSolveTerminationCondition(NLSolveTerminationMode.NLSolveDefault; + abstol = nothing, + reltol = nothing), + batched::Bool = false, + max_inner_iterations = 1000) if batched return BatchedSimpleDFSane(; σₘᵢₙ = σ_min, σₘₐₓ = σ_max, @@ -98,8 +98,8 @@ function SimpleDFSane(; σ_min::Real = 1e-10, σ_max::Real = 1e10, σ_1::Real = end function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleDFSane, - args...; abstol = nothing, reltol = nothing, maxiters = 1000, - kwargs...) + args...; abstol = nothing, reltol = nothing, maxiters = 1000, + kwargs...) tc = alg.termination_condition mode = DiffEqBase.get_termination_mode(tc) diff --git a/lib/SimpleNonlinearSolve/src/falsi.jl b/lib/SimpleNonlinearSolve/src/falsi.jl index de1079beb..eb2ea1f5f 100644 --- a/lib/SimpleNonlinearSolve/src/falsi.jl +++ b/lib/SimpleNonlinearSolve/src/falsi.jl @@ -4,8 +4,8 @@ struct Falsi <: AbstractBracketingAlgorithm end function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Falsi, args...; - maxiters = 1000, abstol = min(eps(prob.tspan[1]), eps(prob.tspan[2])), - kwargs...) + maxiters = 1000, abstol = min(eps(prob.tspan[1]), eps(prob.tspan[2])), + kwargs...) f = Base.Fix2(prob.f, prob.p) left, right = prob.tspan fl, fr = f(left), f(right) diff --git a/lib/SimpleNonlinearSolve/src/halley.jl b/lib/SimpleNonlinearSolve/src/halley.jl index 2c0496cfe..8107dde31 100644 --- a/lib/SimpleNonlinearSolve/src/halley.jl +++ b/lib/SimpleNonlinearSolve/src/halley.jl @@ -30,16 +30,16 @@ and static array problems. """ struct SimpleHalley{CS, AD, FDT} <: AbstractNewtonAlgorithm{CS, AD, FDT} function SimpleHalley(; chunk_size = Val{0}(), autodiff = Val{true}(), - diff_type = Val{:forward}) + diff_type = Val{:forward}) new{SciMLBase._unwrap_val(chunk_size), SciMLBase._unwrap_val(autodiff), SciMLBase._unwrap_val(diff_type)}() end end function SciMLBase.__solve(prob::NonlinearProblem, - alg::SimpleHalley, args...; abstol = nothing, - reltol = nothing, - maxiters = 1000, kwargs...) + alg::SimpleHalley, args...; abstol = nothing, + reltol = nothing, + maxiters = 1000, kwargs...) f = Base.Fix2(prob.f, prob.p) x = float(prob.u0) fx = f(x) diff --git a/lib/SimpleNonlinearSolve/src/itp.jl b/lib/SimpleNonlinearSolve/src/itp.jl index f6688381c..3147c526e 100644 --- a/lib/SimpleNonlinearSolve/src/itp.jl +++ b/lib/SimpleNonlinearSolve/src/itp.jl @@ -59,8 +59,8 @@ struct ITP{T} <: AbstractBracketingAlgorithm end function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::ITP, - args...; abstol = min(eps(prob.tspan[1]), eps(prob.tspan[2])), - maxiters = 1000, kwargs...) + args...; abstol = min(eps(prob.tspan[1]), eps(prob.tspan[2])), + maxiters = 1000, kwargs...) f = Base.Fix2(prob.f, prob.p) left, right = prob.tspan # a and b fl, fr = f(left), f(right) diff --git a/lib/SimpleNonlinearSolve/src/klement.jl b/lib/SimpleNonlinearSolve/src/klement.jl index 799ba5987..e6a38ecc2 100644 --- a/lib/SimpleNonlinearSolve/src/klement.jl +++ b/lib/SimpleNonlinearSolve/src/klement.jl @@ -9,9 +9,9 @@ This method is non-allocating on scalar problems. struct Klement <: AbstractSimpleNonlinearSolveAlgorithm end function SciMLBase.__solve(prob::NonlinearProblem, - alg::Klement, args...; abstol = nothing, - reltol = nothing, - maxiters = 1000, kwargs...) + alg::Klement, args...; abstol = nothing, + reltol = nothing, + maxiters = 1000, kwargs...) f = Base.Fix2(prob.f, prob.p) x = float(prob.u0) fₙ = f(x) diff --git a/lib/SimpleNonlinearSolve/src/lbroyden.jl b/lib/SimpleNonlinearSolve/src/lbroyden.jl index fc2b51a88..482092151 100644 --- a/lib/SimpleNonlinearSolve/src/lbroyden.jl +++ b/lib/SimpleNonlinearSolve/src/lbroyden.jl @@ -18,16 +18,16 @@ struct LBroyden{batched, TC <: NLSolveTerminationCondition} <: threshold::Int function LBroyden(; batched = false, threshold::Int = 27, - termination_condition = NLSolveTerminationCondition(NLSolveTerminationMode.NLSolveDefault; - abstol = nothing, - reltol = nothing)) + termination_condition = NLSolveTerminationCondition(NLSolveTerminationMode.NLSolveDefault; + abstol = nothing, + reltol = nothing)) return new{batched, typeof(termination_condition)}(termination_condition, threshold) end end @views function SciMLBase.__solve(prob::NonlinearProblem, alg::LBroyden{batched}, args...; - abstol = nothing, reltol = nothing, maxiters = 1000, - kwargs...) where {batched} + abstol = nothing, reltol = nothing, maxiters = 1000, + kwargs...) where {batched} tc = alg.termination_condition mode = DiffEqBase.get_termination_mode(tc) threshold = min(maxiters, alg.threshold) @@ -116,26 +116,26 @@ function _init_lbroyden_state(batched::Bool, x, threshold) end function _rmatvec(U::AbstractMatrix, Vᵀ::AbstractMatrix, - x::Union{<:AbstractVector, <:Number}) + x::Union{<:AbstractVector, <:Number}) length(U) == 0 && return x return -x .+ vec((x' * Vᵀ) * U) end function _rmatvec(U::AbstractArray{T1, 3}, Vᵀ::AbstractArray{T2, 3}, - x::AbstractMatrix) where {T1, T2} + x::AbstractMatrix) where {T1, T2} length(U) == 0 && return x Vᵀx = sum(Vᵀ .* reshape(x, size(x, 1), 1, size(x, 2)); dims = 1) return -x .+ _drdims_sum(U .* permutedims(Vᵀx, (2, 1, 3)); dims = 1) end function _matvec(U::AbstractMatrix, Vᵀ::AbstractMatrix, - x::Union{<:AbstractVector, <:Number}) + x::Union{<:AbstractVector, <:Number}) length(U) == 0 && return x return -x .+ vec(Vᵀ * (U * x)) end function _matvec(U::AbstractArray{T1, 3}, Vᵀ::AbstractArray{T2, 3}, - x::AbstractMatrix) where {T1, T2} + x::AbstractMatrix) where {T1, T2} length(U) == 0 && return x xUᵀ = sum(reshape(x, size(x, 1), 1, size(x, 2)) .* permutedims(U, (2, 1, 3)); dims = 1) return -x .+ _drdims_sum(xUᵀ .* Vᵀ; dims = 2) diff --git a/lib/SimpleNonlinearSolve/src/raphson.jl b/lib/SimpleNonlinearSolve/src/raphson.jl index d5bad8d13..138e6724d 100644 --- a/lib/SimpleNonlinearSolve/src/raphson.jl +++ b/lib/SimpleNonlinearSolve/src/raphson.jl @@ -34,10 +34,10 @@ and static array problems. struct SimpleNewtonRaphson{CS, AD, FDT} <: AbstractNewtonAlgorithm{CS, AD, FDT} end function SimpleNewtonRaphson(; batched = false, - chunk_size = Val{0}(), - autodiff = Val{true}(), - diff_type = Val{:forward}, - termination_condition = missing) + chunk_size = Val{0}(), + autodiff = Val{true}(), + diff_type = Val{:forward}, + termination_condition = missing) if !ismissing(termination_condition) && !batched throw(ArgumentError("`termination_condition` is currently only supported for batched problems")) end @@ -63,10 +63,10 @@ end const SimpleGaussNewton = SimpleNewtonRaphson -function SciMLBase.__solve(prob::Union{NonlinearProblem,NonlinearLeastSquaresProblem}, - alg::SimpleNewtonRaphson, args...; abstol = nothing, - reltol = nothing, - maxiters = 1000, kwargs...) +function SciMLBase.__solve(prob::Union{NonlinearProblem, NonlinearLeastSquaresProblem}, + alg::SimpleNewtonRaphson, args...; abstol = nothing, + reltol = nothing, + maxiters = 1000, kwargs...) f = Base.Fix2(prob.f, prob.p) x = float(prob.u0) fx = float(prob.u0) @@ -76,7 +76,8 @@ function SciMLBase.__solve(prob::Union{NonlinearProblem,NonlinearLeastSquaresPro error("SimpleNewtonRaphson currently only supports out-of-place nonlinear problems") end - if prob isa NonlinearLeastSquaresProblem && !(typeof(prob.u0) <: Union{Number, AbstractVector}) + if prob isa NonlinearLeastSquaresProblem && + !(typeof(prob.u0) <: Union{Number, AbstractVector}) error("SimpleGaussNewton only supports Number and AbstactVector types. Please convert any problem of AbstractArray into one with u0 as AbstractVector") end diff --git a/lib/SimpleNonlinearSolve/src/ridder.jl b/lib/SimpleNonlinearSolve/src/ridder.jl index ce95a178a..eabd7b2ac 100644 --- a/lib/SimpleNonlinearSolve/src/ridder.jl +++ b/lib/SimpleNonlinearSolve/src/ridder.jl @@ -7,8 +7,8 @@ A non-allocating ridder method struct Ridder <: AbstractBracketingAlgorithm end function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Ridder, args...; - maxiters = 1000, abstol = min(eps(prob.tspan[1]), eps(prob.tspan[2])), - kwargs...) + maxiters = 1000, abstol = min(eps(prob.tspan[1]), eps(prob.tspan[2])), + kwargs...) f = Base.Fix2(prob.f, prob.p) left, right = prob.tspan fl, fr = f(left), f(right) diff --git a/lib/SimpleNonlinearSolve/src/trustRegion.jl b/lib/SimpleNonlinearSolve/src/trustRegion.jl index ab28e1ce3..98a36d063 100644 --- a/lib/SimpleNonlinearSolve/src/trustRegion.jl +++ b/lib/SimpleNonlinearSolve/src/trustRegion.jl @@ -64,16 +64,16 @@ struct SimpleTrustRegion{T, CS, AD, FDT} <: AbstractNewtonAlgorithm{CS, AD, FDT} expand_factor::T max_shrink_times::Int function SimpleTrustRegion(; chunk_size = Val{0}(), - autodiff = Val{true}(), - diff_type = Val{:forward}, - max_trust_radius::Real = 0.0, - initial_trust_radius::Real = 0.0, - step_threshold::Real = 0.0001, - shrink_threshold::Real = 0.25, - expand_threshold::Real = 0.75, - shrink_factor::Real = 0.25, - expand_factor::Real = 2.0, - max_shrink_times::Int = 32) + autodiff = Val{true}(), + diff_type = Val{:forward}, + max_trust_radius::Real = 0.0, + initial_trust_radius::Real = 0.0, + step_threshold::Real = 0.0001, + shrink_threshold::Real = 0.25, + expand_threshold::Real = 0.75, + shrink_factor::Real = 0.25, + expand_factor::Real = 2.0, + max_shrink_times::Int = 32) new{typeof(initial_trust_radius), SciMLBase._unwrap_val(chunk_size), SciMLBase._unwrap_val(autodiff), @@ -89,9 +89,9 @@ struct SimpleTrustRegion{T, CS, AD, FDT} <: AbstractNewtonAlgorithm{CS, AD, FDT} end function SciMLBase.__solve(prob::NonlinearProblem, - alg::SimpleTrustRegion, args...; abstol = nothing, - reltol = nothing, - maxiters = 1000, kwargs...) + alg::SimpleTrustRegion, args...; abstol = nothing, + reltol = nothing, + maxiters = 1000, kwargs...) f = Base.Fix2(prob.f, prob.p) x = float(prob.u0) T = typeof(x) @@ -147,7 +147,7 @@ function SciMLBase.__solve(prob::NonlinearProblem, # Compute the ratio of the actual to predicted reduction. model = -(δ' * g + 0.5 * δ' * H * δ) - r = (fₖ - fₖ₊₁) / model + r = (fₖ - fₖ₊₁) / model # Update the trust region radius. if r < η₂ diff --git a/lib/SimpleNonlinearSolve/src/utils.jl b/lib/SimpleNonlinearSolve/src/utils.jl index 1c4400026..45df96410 100644 --- a/lib/SimpleNonlinearSolve/src/utils.jl +++ b/lib/SimpleNonlinearSolve/src/utils.jl @@ -36,10 +36,10 @@ value_derivative(f::F, x::AbstractArray) where {F} = f(x), ForwardDiff.jacobian( Inplace version of [`SimpleNonlinearSolve.value_derivative`](@ref). """ function value_derivative!(J::AbstractMatrix, - y::AbstractArray, - f!::F, - x::AbstractArray, - cfg::ForwardDiff.JacobianConfig = ForwardDiff.JacobianConfig(f!, y, x)) where {F} + y::AbstractArray, + f!::F, + x::AbstractArray, + cfg::ForwardDiff.JacobianConfig = ForwardDiff.JacobianConfig(f!, y, x)) where {F} ForwardDiff.jacobian!(J, f!, y, x, cfg) return y, J end diff --git a/lib/SimpleNonlinearSolve/test/inplace.jl b/lib/SimpleNonlinearSolve/test/inplace.jl index d4882105b..2e9d033a8 100644 --- a/lib/SimpleNonlinearSolve/test/inplace.jl +++ b/lib/SimpleNonlinearSolve/test/inplace.jl @@ -4,8 +4,8 @@ using SimpleNonlinearSolve, # Supported Solvers: BatchedBroyden, BatchedSimpleDFSane, BatchedSimpleNewtonRaphson function f!(du::AbstractArray{<:Number, N}, - u::AbstractArray{<:Number, N}, - p::AbstractVector) where {N} + u::AbstractArray{<:Number, N}, + p::AbstractVector) where {N} u_ = reshape(u, :, size(u, N)) du .= reshape(sum(abs2, u_; dims = 1) .- u_ .- reshape(p, 1, :), size(u)) return du