From aaacd051270bb88c9633fc3bc4fdf79c3725713c Mon Sep 17 00:00:00 2001 From: Iskaban10 Date: Tue, 14 Apr 2026 01:10:16 +0530 Subject: [PATCH 01/10] added golden section method --- src/LineSearch.jl | 2 ++ src/golden_section.jl | 60 ++++++++++++++++++++++++++++++++++ test/custom_optimizer_tests.jl | 2 ++ test/root_finding_tests.jl | 2 ++ 4 files changed, 66 insertions(+) create mode 100644 src/golden_section.jl diff --git a/src/LineSearch.jl b/src/LineSearch.jl index c3f5963..aeb982b 100644 --- a/src/LineSearch.jl +++ b/src/LineSearch.jl @@ -22,6 +22,7 @@ function SciMLBase.reinit!(::AbstractLineSearchCache; kwargs...) end include("utils.jl") include("backtracking.jl") +include("golden_section.jl") include("li_fukushima.jl") include("no_search.jl") include("robust_non_monotone.jl") @@ -36,6 +37,7 @@ end export LineSearchSolution export BackTracking +export GoldenSection export NoLineSearch, LiFukushimaLineSearch, RobustNonMonotoneLineSearch export LineSearchesJL diff --git a/src/golden_section.jl b/src/golden_section.jl new file mode 100644 index 0000000..e2ce395 --- /dev/null +++ b/src/golden_section.jl @@ -0,0 +1,60 @@ +""" + GoldenSection() + +A derivative-free line search method that minimizes a unimodal function by +successively narrowing the range of values inside which the local minimum must lie. +""" +struct GoldenSection{T<:AbstractFloat} + tol::T + maxiter::Int +end + +# Default constructor +GoldenSection(; tol=1e-7, maxiter=100) = GoldenSection(tol, maxiter) + +function (gs::GoldenSection)(f, x, d, α_initial, f_x, g_x) + T = typeof(α_initial) + + # Defines the 1D objective: ϕ(α) = f(x + αd) + ϕ(α) = f(x + α .* d) + + a = T(0.0) + b = α_initial + + # Golden ratio constants + φ = (sqrt(T(5)) + 1) / 2 + resphi = 2 - φ # ~0.382 + + # Initial internal points + x1 = a + resphi * (b - a) + x2 = b - resphi * (b - a) + + f1 = ϕ(x1) + f2 = ϕ(x2) + + α_best = α_initial + f_best = f_x + iter = 0 + + while abs(b - a) > gs.tol && iter < gs.maxiter + iter += 1 + if f1 < f2 + b = x2 + x2 = x1 + f2 = f1 + x1 = a + resphi * (b - a) + f1 = ϕ(x1) + else + a = x1 + x1 = x2 + f1 = f2 + x2 = b - resphi * (b - a) + f2 = ϕ(x2) + end + end + + α_best = (a + b) / 2 + f_best = ϕ(α_best) + + return α_best, f_best +end \ No newline at end of file diff --git a/test/custom_optimizer_tests.jl b/test/custom_optimizer_tests.jl index 2967b08..56d5ea9 100644 --- a/test/custom_optimizer_tests.jl +++ b/test/custom_optimizer_tests.jl @@ -117,6 +117,7 @@ end @testset "method: $(nameof(typeof(method)))" for method in ( LiFukushimaLineSearch(), NoLineSearch(0.001), + GoldenSection(; tol = 1e-4), BackTracking(; order = Val(3), autodiff), BackTracking(; order = Val(2), autodiff), ) @@ -139,6 +140,7 @@ end @testset "method: $(nameof(typeof(method)))" for method in ( LiFukushimaLineSearch(), NoLineSearch(0.001), + GoldenSection(; tol = 1e-4), BackTracking(; order = Val(3), autodiff), BackTracking(; order = Val(2), autodiff), ) diff --git a/test/root_finding_tests.jl b/test/root_finding_tests.jl index 8604e2e..7996be0 100644 --- a/test/root_finding_tests.jl +++ b/test/root_finding_tests.jl @@ -138,6 +138,7 @@ end @testset "method: $(nameof(typeof(method)))" for method in ( LiFukushimaLineSearch(), NoLineSearch(0.5), + GoldenSection(; tol = 1e-4), ) converged, fu, u, iter, alphas = newton_raphson(nlp, method) @@ -168,6 +169,7 @@ end @testset "method: $(nameof(typeof(method)))" for method in ( LiFukushimaLineSearch(), NoLineSearch(0.5), + GoldenSection(; tol = 1e-4), ) converged, fu, u, iter, alphas = newton_raphson(nlp, method) From 64f6e38ef0601c49cd4f7fb61b80ecddfdf051ef Mon Sep 17 00:00:00 2001 From: Iskaban10 Date: Tue, 14 Apr 2026 01:21:44 +0530 Subject: [PATCH 02/10] formatting changed --- test/custom_optimizer_tests.jl | 4 ++-- test/root_finding_tests.jl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/custom_optimizer_tests.jl b/test/custom_optimizer_tests.jl index 56d5ea9..d93f25c 100644 --- a/test/custom_optimizer_tests.jl +++ b/test/custom_optimizer_tests.jl @@ -117,7 +117,7 @@ end @testset "method: $(nameof(typeof(method)))" for method in ( LiFukushimaLineSearch(), NoLineSearch(0.001), - GoldenSection(; tol = 1e-4), + GoldenSection(; tol = 1.0e-4), BackTracking(; order = Val(3), autodiff), BackTracking(; order = Val(2), autodiff), ) @@ -140,7 +140,7 @@ end @testset "method: $(nameof(typeof(method)))" for method in ( LiFukushimaLineSearch(), NoLineSearch(0.001), - GoldenSection(; tol = 1e-4), + GoldenSection(; tol = 1.0e-4), BackTracking(; order = Val(3), autodiff), BackTracking(; order = Val(2), autodiff), ) diff --git a/test/root_finding_tests.jl b/test/root_finding_tests.jl index 7996be0..e3c1da6 100644 --- a/test/root_finding_tests.jl +++ b/test/root_finding_tests.jl @@ -138,7 +138,7 @@ end @testset "method: $(nameof(typeof(method)))" for method in ( LiFukushimaLineSearch(), NoLineSearch(0.5), - GoldenSection(; tol = 1e-4), + GoldenSection(; tol = 1.0e-4), ) converged, fu, u, iter, alphas = newton_raphson(nlp, method) @@ -169,7 +169,7 @@ end @testset "method: $(nameof(typeof(method)))" for method in ( LiFukushimaLineSearch(), NoLineSearch(0.5), - GoldenSection(; tol = 1e-4), + GoldenSection(; tol = 1.0e-4), ) converged, fu, u, iter, alphas = newton_raphson(nlp, method) From fd955774dd6bd087b0c4df84e3f6875d676604c2 Mon Sep 17 00:00:00 2001 From: Iskaban10 Date: Fri, 17 Apr 2026 01:22:46 +0530 Subject: [PATCH 03/10] updated --- .github/workflows/Documentation.yml | 2 +- .github/workflows/Tests.yml | 2 +- Project.toml | 4 ++-- src/golden_section.jl | 32 +++++++++-------------------- src/utils.jl | 14 ++++++++----- test/root_finding_tests.jl | 14 +++++++++++++ 6 files changed, 37 insertions(+), 31 deletions(-) diff --git a/.github/workflows/Documentation.yml b/.github/workflows/Documentation.yml index 5a55797..bd75221 100644 --- a/.github/workflows/Documentation.yml +++ b/.github/workflows/Documentation.yml @@ -31,7 +31,7 @@ jobs: DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key run: julia --project=docs/ --code-coverage=user --color=yes docs/make.jl - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v5 + - uses: codecov/codecov-action@v6 with: files: lcov.info token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml index 1854e50..d0d615d 100644 --- a/.github/workflows/Tests.yml +++ b/.github/workflows/Tests.yml @@ -45,7 +45,7 @@ jobs: env: GROUP: ${{ matrix.group }} - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v5 + - uses: codecov/codecov-action@v6 with: files: lcov.info token: ${{ secrets.CODECOV_TOKEN }} diff --git a/Project.toml b/Project.toml index 3841803..71a47f0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "LineSearch" uuid = "87fe0de2-c867-4266-b59a-2f0a94fc965b" -version = "0.1.6" +version = "0.1.7" authors = ["SciML"] [deps] @@ -39,7 +39,7 @@ NonlinearProblemLibrary = "0.1.2" PrecompileTools = "1" ReTestItems = "1.28.0" ReverseDiff = "1.15.3" -SciMLBase = "2.53.1" +SciMLBase = "2.53.1, 3.0" SciMLJacobianOperators = "0.1" StaticArraysCore = "1.4" Test = "1.10" diff --git a/src/golden_section.jl b/src/golden_section.jl index e2ce395..ebe8921 100644 --- a/src/golden_section.jl +++ b/src/golden_section.jl @@ -9,45 +9,34 @@ struct GoldenSection{T<:AbstractFloat} maxiter::Int end -# Default constructor GoldenSection(; tol=1e-7, maxiter=100) = GoldenSection(tol, maxiter) function (gs::GoldenSection)(f, x, d, α_initial, f_x, g_x) T = typeof(α_initial) - - # Defines the 1D objective: ϕ(α) = f(x + αd) - ϕ(α) = f(x + α .* d) - - a = T(0.0) - b = α_initial - - # Golden ratio constants + + xc = similar(x) + ϕ(α) = (@. xc = x + α * d; f(xc)) + + a = T(0) + b = α_initial + φ = (sqrt(T(5)) + 1) / 2 - resphi = 2 - φ # ~0.382 + resphi = 2 - φ - # Initial internal points x1 = a + resphi * (b - a) x2 = b - resphi * (b - a) - f1 = ϕ(x1) f2 = ϕ(x2) - α_best = α_initial - f_best = f_x iter = 0 - while abs(b - a) > gs.tol && iter < gs.maxiter iter += 1 if f1 < f2 - b = x2 - x2 = x1 - f2 = f1 + b = x2; x2 = x1; f2 = f1 x1 = a + resphi * (b - a) f1 = ϕ(x1) else - a = x1 - x1 = x2 - f1 = f2 + a = x1; x1 = x2; f1 = f2 x2 = b - resphi * (b - a) f2 = ϕ(x2) end @@ -55,6 +44,5 @@ function (gs::GoldenSection)(f, x, d, α_initial, f_x, g_x) α_best = (a + b) / 2 f_best = ϕ(α_best) - return α_best, f_best end \ No newline at end of file diff --git a/src/utils.jl b/src/utils.jl index f909c0c..51d3084 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -38,11 +38,15 @@ function construct_jvp_or_vjp_operator(prob::AbstractNonlinearProblem, fu, u; au pass it to `init` as a keyword argument.") end - deriv_op = if jvp_op !== nothing - @closure (du, u, fu, p) -> dot(fu, jvp_op(du, u, p)) - else - @closure (du, u, fu, p) -> dot(du, vjp_op(fu, u, p)) - end + deriv_op = _get_deriv_op(jvp_op, vjp_op) return jvp_op, vjp_op, deriv_op end + +function _get_deriv_op(jvp_op, vjp_op) + return @closure (du, u, fu, p) -> dot(fu, jvp_op(du, u, p)) +end + +function _get_deriv_op(jvp_op::Nothing, vjp_op) + return @closure (du, u, fu, p) -> dot(du, vjp_op(fu, u, p)) +end diff --git a/test/root_finding_tests.jl b/test/root_finding_tests.jl index e3c1da6..e18bfb4 100644 --- a/test/root_finding_tests.jl +++ b/test/root_finding_tests.jl @@ -138,7 +138,14 @@ end @testset "method: $(nameof(typeof(method)))" for method in ( LiFukushimaLineSearch(), NoLineSearch(0.5), +<<<<<<< HEAD GoldenSection(; tol = 1.0e-4), +======= + GoldenSection(; tol = 1e-4), + RobustNonMonotoneLineSearch(), + RobustNonMonotoneLineSearch(; M = 1), #strictly monotonous case + RobustNonMonotoneLineSearch(; M = 15), +>>>>>>> 315110466db3b53104c87dbe503ef6c3631ebc1c ) converged, fu, u, iter, alphas = newton_raphson(nlp, method) @@ -169,7 +176,14 @@ end @testset "method: $(nameof(typeof(method)))" for method in ( LiFukushimaLineSearch(), NoLineSearch(0.5), +<<<<<<< HEAD GoldenSection(; tol = 1.0e-4), +======= + GoldenSection(; tol = 1e-4), + RobustNonMonotoneLineSearch(), + RobustNonMonotoneLineSearch(; M = 1), #strictly monotonous case + RobustNonMonotoneLineSearch(; M = 15), +>>>>>>> 315110466db3b53104c87dbe503ef6c3631ebc1c ) converged, fu, u, iter, alphas = newton_raphson(nlp, method) From bd4520a287ec2fb33d0afc99ab92e0f88af00d8b Mon Sep 17 00:00:00 2001 From: Iskaban10 Date: Fri, 17 Apr 2026 01:25:45 +0530 Subject: [PATCH 04/10] reslved changes --- test/root_finding_tests.jl | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/root_finding_tests.jl b/test/root_finding_tests.jl index e18bfb4..4ff6c26 100644 --- a/test/root_finding_tests.jl +++ b/test/root_finding_tests.jl @@ -138,14 +138,10 @@ end @testset "method: $(nameof(typeof(method)))" for method in ( LiFukushimaLineSearch(), NoLineSearch(0.5), -<<<<<<< HEAD - GoldenSection(; tol = 1.0e-4), -======= GoldenSection(; tol = 1e-4), RobustNonMonotoneLineSearch(), RobustNonMonotoneLineSearch(; M = 1), #strictly monotonous case RobustNonMonotoneLineSearch(; M = 15), ->>>>>>> 315110466db3b53104c87dbe503ef6c3631ebc1c ) converged, fu, u, iter, alphas = newton_raphson(nlp, method) @@ -176,14 +172,10 @@ end @testset "method: $(nameof(typeof(method)))" for method in ( LiFukushimaLineSearch(), NoLineSearch(0.5), -<<<<<<< HEAD - GoldenSection(; tol = 1.0e-4), -======= GoldenSection(; tol = 1e-4), RobustNonMonotoneLineSearch(), RobustNonMonotoneLineSearch(; M = 1), #strictly monotonous case RobustNonMonotoneLineSearch(; M = 15), ->>>>>>> 315110466db3b53104c87dbe503ef6c3631ebc1c ) converged, fu, u, iter, alphas = newton_raphson(nlp, method) From b067c4734693cf956fe10ebd72cd290a3621a751 Mon Sep 17 00:00:00 2001 From: Iskaban10 Date: Fri, 17 Apr 2026 01:35:45 +0530 Subject: [PATCH 05/10] goden_section.jl updated and formatted according to backtracking.jl --- src/golden_section.jl | 81 ++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/src/golden_section.jl b/src/golden_section.jl index ebe8921..03e70b1 100644 --- a/src/golden_section.jl +++ b/src/golden_section.jl @@ -1,48 +1,79 @@ """ - GoldenSection() + GoldenSection(; tol = 1e-7, maxiters = 100) -A derivative-free line search method that minimizes a unimodal function by -successively narrowing the range of values inside which the local minimum must lie. +A derivative-free line search that minimizes a unimodal function by successively +narrowing the interval containing the minimum using the golden ratio. """ -struct GoldenSection{T<:AbstractFloat} - tol::T - maxiter::Int +@kwdef @concrete struct GoldenSection <: AbstractLineSearchAlgorithm + tol = 1e-7 + maxiters::Int = 100 end -GoldenSection(; tol=1e-7, maxiter=100) = GoldenSection(tol, maxiter) +@concrete mutable struct GoldenSectionCache <: AbstractLineSearchCache + ϕ + f + p + u_cache + fu_cache + α + stats <: Union{SciMLBase.NLStats, Nothing} + alg <: GoldenSection + maxiters::Int +end + +function CommonSolve.init( + prob::AbstractNonlinearProblem, alg::GoldenSection, fu, u; + stats::Union{SciMLBase.NLStats, Nothing} = nothing, kwargs... + ) + T = promote_type(eltype(fu), eltype(u)) -function (gs::GoldenSection)(f, x, d, α_initial, f_x, g_x) - T = typeof(α_initial) + @bb u_cache = similar(u) + @bb fu_cache = similar(fu) - xc = similar(x) - ϕ(α) = (@. xc = x + α * d; f(xc)) + ϕ = @closure (f, p, u, du, α, u_cache, fu_cache) -> begin + @bb @. u_cache = u + α * du + fu_cache = evaluate_f!!(f, fu_cache, u_cache, p) + add_nf!(stats) + return @fastmath norm(fu_cache)^2 / 2 + end - a = T(0) - b = α_initial + return GoldenSectionCache( + ϕ, prob.f, prob.p, u_cache, fu_cache, T(1), stats, alg, alg.maxiters + ) +end +function CommonSolve.solve!(cache::GoldenSectionCache, u, du) + T = promote_type(eltype(du), eltype(u)) + ϕ = @closure α -> cache.ϕ(cache.f, cache.p, u, du, α, cache.u_cache, cache.fu_cache) + + a, b = zero(T), T(cache.α) φ = (sqrt(T(5)) + 1) / 2 - resphi = 2 - φ + resphi = 2 - φ # ≈ 0.382 x1 = a + resphi * (b - a) x2 = b - resphi * (b - a) - f1 = ϕ(x1) - f2 = ϕ(x2) + f1, f2 = ϕ(x1), ϕ(x2) - iter = 0 - while abs(b - a) > gs.tol && iter < gs.maxiter - iter += 1 + for _ in 1:(cache.maxiters) + abs(b - a) ≤ cache.alg.tol && break if f1 < f2 b = x2; x2 = x1; f2 = f1 - x1 = a + resphi * (b - a) - f1 = ϕ(x1) + x1 = a + resphi * (b - a); f1 = ϕ(x1) else a = x1; x1 = x2; f1 = f2 - x2 = b - resphi * (b - a) - f2 = ϕ(x2) + x2 = b - resphi * (b - a); f2 = ϕ(x2) end end α_best = (a + b) / 2 - f_best = ϕ(α_best) - return α_best, f_best + return LineSearchSolution(α_best, ReturnCode.Success) +end + +function SciMLBase.reinit!( + cache::GoldenSectionCache; p = missing, stats = missing, kwargs... + ) + p !== missing && (cache.p = p) + stats !== missing && (cache.stats = stats) + cache.α = oftype(cache.α, true) + return cache end \ No newline at end of file From bdfc59408ae60232a65d15aa4557e8e9a1d99420 Mon Sep 17 00:00:00 2001 From: Iskaban10 Date: Fri, 17 Apr 2026 23:55:29 +0530 Subject: [PATCH 06/10] updated --- src/golden_section.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/golden_section.jl b/src/golden_section.jl index 03e70b1..1f5e826 100644 --- a/src/golden_section.jl +++ b/src/golden_section.jl @@ -76,4 +76,4 @@ function SciMLBase.reinit!( stats !== missing && (cache.stats = stats) cache.α = oftype(cache.α, true) return cache -end \ No newline at end of file +end From 5131f933a0bc2d473a6dbfe75cc02ec1822bdb07 Mon Sep 17 00:00:00 2001 From: Iskaban10 Date: Fri, 17 Apr 2026 23:56:37 +0530 Subject: [PATCH 07/10] updated --- test/root_finding_tests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/root_finding_tests.jl b/test/root_finding_tests.jl index 4ff6c26..302ce61 100644 --- a/test/root_finding_tests.jl +++ b/test/root_finding_tests.jl @@ -138,7 +138,7 @@ end @testset "method: $(nameof(typeof(method)))" for method in ( LiFukushimaLineSearch(), NoLineSearch(0.5), - GoldenSection(; tol = 1e-4), + GoldenSection(; tol = 1.0e-4), RobustNonMonotoneLineSearch(), RobustNonMonotoneLineSearch(; M = 1), #strictly monotonous case RobustNonMonotoneLineSearch(; M = 15), @@ -172,7 +172,7 @@ end @testset "method: $(nameof(typeof(method)))" for method in ( LiFukushimaLineSearch(), NoLineSearch(0.5), - GoldenSection(; tol = 1e-4), + GoldenSection(; tol = 1.0e-4), RobustNonMonotoneLineSearch(), RobustNonMonotoneLineSearch(; M = 1), #strictly monotonous case RobustNonMonotoneLineSearch(; M = 15), From e9e41e34b032b06bf770eb301a2d619be092a603 Mon Sep 17 00:00:00 2001 From: Iskaban10 Date: Fri, 17 Apr 2026 23:59:09 +0530 Subject: [PATCH 08/10] updated --- src/golden_section.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/golden_section.jl b/src/golden_section.jl index 1f5e826..cb200a2 100644 --- a/src/golden_section.jl +++ b/src/golden_section.jl @@ -5,7 +5,7 @@ A derivative-free line search that minimizes a unimodal function by successively narrowing the interval containing the minimum using the golden ratio. """ @kwdef @concrete struct GoldenSection <: AbstractLineSearchAlgorithm - tol = 1e-7 + tol = 1.0e-7 maxiters::Int = 100 end From 75c7483203e6c43c3d9466518d1325da1a7add67 Mon Sep 17 00:00:00 2001 From: Iskaban10 Date: Sat, 18 Apr 2026 01:16:13 +0530 Subject: [PATCH 09/10] shifted phi and resphi to init from solve --- src/golden_section.jl | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/golden_section.jl b/src/golden_section.jl index cb200a2..3223820 100644 --- a/src/golden_section.jl +++ b/src/golden_section.jl @@ -16,6 +16,8 @@ end u_cache fu_cache α + φ + resphi stats <: Union{SciMLBase.NLStats, Nothing} alg <: GoldenSection maxiters::Int @@ -27,6 +29,9 @@ function CommonSolve.init( ) T = promote_type(eltype(fu), eltype(u)) + φ = (sqrt(T(5)) + 1) / 2 + resphi = 2 - φ + @bb u_cache = similar(u) @bb fu_cache = similar(fu) @@ -38,7 +43,7 @@ function CommonSolve.init( end return GoldenSectionCache( - ϕ, prob.f, prob.p, u_cache, fu_cache, T(1), stats, alg, alg.maxiters + ϕ, prob.f, prob.p, u_cache, fu_cache, T(1), φ, resphi, stats, alg, alg.maxiters ) end @@ -46,22 +51,20 @@ function CommonSolve.solve!(cache::GoldenSectionCache, u, du) T = promote_type(eltype(du), eltype(u)) ϕ = @closure α -> cache.ϕ(cache.f, cache.p, u, du, α, cache.u_cache, cache.fu_cache) - a, b = zero(T), T(cache.α) - φ = (sqrt(T(5)) + 1) / 2 - resphi = 2 - φ # ≈ 0.382 + a, b = zero(T), T(cache.α) - x1 = a + resphi * (b - a) - x2 = b - resphi * (b - a) + x1 = a + cache.resphi * (b - a) + x2 = b - cache.resphi * (b - a) f1, f2 = ϕ(x1), ϕ(x2) for _ in 1:(cache.maxiters) abs(b - a) ≤ cache.alg.tol && break if f1 < f2 b = x2; x2 = x1; f2 = f1 - x1 = a + resphi * (b - a); f1 = ϕ(x1) + x1 = a + cache.resphi * (b - a); f1 = ϕ(x1) else a = x1; x1 = x2; f1 = f2 - x2 = b - resphi * (b - a); f2 = ϕ(x2) + x2 = b - cache.resphi * (b - a); f2 = ϕ(x2) end end From 256541e5ec356dd5142a555eadef297966d64d19 Mon Sep 17 00:00:00 2001 From: Iskaban10 Date: Sat, 18 Apr 2026 01:21:54 +0530 Subject: [PATCH 10/10] updated --- src/golden_section.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/golden_section.jl b/src/golden_section.jl index 3223820..19e552f 100644 --- a/src/golden_section.jl +++ b/src/golden_section.jl @@ -30,7 +30,7 @@ function CommonSolve.init( T = promote_type(eltype(fu), eltype(u)) φ = (sqrt(T(5)) + 1) / 2 - resphi = 2 - φ + resphi = 2 - φ @bb u_cache = similar(u) @bb fu_cache = similar(fu) @@ -51,7 +51,7 @@ function CommonSolve.solve!(cache::GoldenSectionCache, u, du) T = promote_type(eltype(du), eltype(u)) ϕ = @closure α -> cache.ϕ(cache.f, cache.p, u, du, α, cache.u_cache, cache.fu_cache) - a, b = zero(T), T(cache.α) + a, b = zero(T), T(cache.α) x1 = a + cache.resphi * (b - a) x2 = b - cache.resphi * (b - a)