Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Feb 19, 2023
1 parent e713d66 commit 6cdd257
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/SimpleNonlinearSolve/src/SimpleNonlinearSolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ import SnoopPrecompile

SnoopPrecompile.@precompile_all_calls begin for T in (Float32, Float64)
prob_no_brack = NonlinearProblem{false}((u, p) -> u .* u .- p, T(0.1), T(2))
for alg in (SimpleNewtonRaphson, Halley, Broyden, Klement, SimpleTrustRegion, SimpleDFSane)
for alg in (SimpleNewtonRaphson, Halley, Broyden, Klement, SimpleTrustRegion,
SimpleDFSane)
solve(prob_no_brack, alg(), abstol = T(1e-2))
end

Expand Down
7 changes: 4 additions & 3 deletions lib/SimpleNonlinearSolve/src/halley.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ and static array problems.
"""
struct Halley{CS, AD, FDT} <: AbstractNewtonAlgorithm{CS, AD, FDT}
function Halley(; 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
Expand Down Expand Up @@ -73,12 +73,13 @@ function SciMLBase.__solve(prob::NonlinearProblem,
fx = f(x)
dfx = FiniteDiff.finite_difference_derivative(f, x, diff_type(alg), eltype(x),
fx)
d2fx = FiniteDiff.finite_difference_derivative(x -> FiniteDiff.finite_difference_derivative(f, x),
d2fx = FiniteDiff.finite_difference_derivative(x -> FiniteDiff.finite_difference_derivative(f,
x),
x, diff_type(alg), eltype(x), fx)
end
iszero(fx) &&
return SciMLBase.build_solution(prob, alg, x, fx; retcode = ReturnCode.Success)
Δx = (2*dfx^2 - fx*d2fx) \ (2fx*dfx)
Δx = (2 * dfx^2 - fx * d2fx) \ (2fx * dfx)
x -= Δx
if isapprox(x, xo, atol = atol, rtol = rtol)
return SciMLBase.build_solution(prob, alg, x, fx; retcode = ReturnCode.Success)
Expand Down
1 change: 0 additions & 1 deletion lib/SimpleNonlinearSolve/test/basictests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ probN = NonlinearProblem(f, u0)

@test solve(probN, Halley()).u sqrt(2.0)


for u0 in [1.0, [1, 1.0]]
local f, probN, sol
f = (u, p) -> u .* u .- 2.0
Expand Down

0 comments on commit 6cdd257

Please sign in to comment.