diff --git a/src/backtracking.jl b/src/backtracking.jl index fff1440..b347c4c 100644 --- a/src/backtracking.jl +++ b/src/backtracking.jl @@ -146,7 +146,7 @@ end a = (a₁ - a₂) * div b = (-α₁ * a₁ + α₂ * a₂) * div - return ifelse(iszero(a), dϕ₀ / 2b, (-b + sqrt(max(b^2 - 3a * dϕ₀, T(0)))) / 3a) + return ifelse(iszero(a), -dϕ₀ / 2b, (-b + sqrt(max(b^2 - 3a * dϕ₀, T(0)))) / 3a) end function SciMLBase.reinit!( diff --git a/test/root_finding_tests.jl b/test/root_finding_tests.jl index eb20230..5ecc1ac 100644 --- a/test/root_finding_tests.jl +++ b/test/root_finding_tests.jl @@ -210,6 +210,11 @@ end end end +@testset "BackTracking cubic step on a quadratic merit" begin + # ϕ(α) = (1 - α)², sampled at α = 1 and 1/2: the cubic coefficient vanishes and the minimizer is α = 1. + @test LineSearch.compute_alpha_backtracking(Val(3), Float64, -2.0, 1.0, 0.0, 0.25, 1.0, 0.5) == 1.0 +end + @testset "Static Strong Wolfe residual mode" begin using CommonSolve: init, solve! using SciMLBase: NonlinearProblem, ReturnCode