11module LineSearches
22
33using Printf: @sprintf
4- using LinearAlgebra: dot, norm
4+ using LinearAlgebra: norm
55using NaNMath: NaNMath
66using NLSolversBase: NLSolversBase, AbstractObjective
77
@@ -16,74 +16,40 @@ export InitialHagerZhang, InitialStatic, InitialPrevious,
1616function make_ϕ (df, x_new, x, s)
1717 function ϕ (α)
1818 # Move a distance of alpha in the direction of s
19- x_new .= x .+ α .* s
19+ x_new .= muladd .(α, s, x)
2020
2121 # Evaluate f(x+α*s)
22- NLSolversBase. value! (df, x_new)
22+ return NLSolversBase. value! (df, x_new)
2323 end
2424 ϕ
2525end
2626function make_ϕdϕ (df, x_new, x, s)
2727 function ϕdϕ (α)
2828 # Move a distance of alpha in the direction of s
29- x_new .= x .+ α.* s
30-
31- # Evaluate ∇f(x+α*s)
32- NLSolversBase. value_gradient! (df, x_new)
29+ x_new .= muladd .(α, s, x)
3330
3431 # Calculate ϕ(a_i), ϕ'(a_i)
35- NLSolversBase. value (df), real (dot (NLSolversBase. gradient (df), s))
32+ ϕ, dϕ = NLSolversBase. value_jvp! (df, x_new, s)
33+
34+ return ϕ, real (dϕ)
3635 end
3736 ϕdϕ
3837end
3938function make_ϕ_dϕ (df, x_new, x, s)
4039 function dϕ (α)
4140 # Move a distance of alpha in the direction of s
42- x_new .= x .+ α.* s
43-
44- # Evaluate ∇f(x+α*s)
45- NLSolversBase. gradient! (df, x_new)
41+ x_new .= muladd .(α, s, x)
4642
4743 # Calculate ϕ'(a_i)
48- real (dot ( NLSolversBase. gradient (df) , s))
44+ return real (NLSolversBase. jvp! (df, x_new , s))
4945 end
5046 make_ϕ (df, x_new, x, s), dϕ
5147end
5248function make_ϕ_dϕ_ϕdϕ (df, x_new, x, s)
53- function dϕ (α)
54- # Move a distance of alpha in the direction of s
55- x_new .= x .+ α.* s
56-
57- # Evaluate f(x+α*s) and ∇f(x+α*s)
58- NLSolversBase. gradient! (df, x_new)
59-
60- # Calculate ϕ'(a_i)
61- real (dot (NLSolversBase. gradient (df), s))
62- end
63- function ϕdϕ (α)
64- # Move a distance of alpha in the direction of s
65- x_new .= x .+ α.* s
66-
67- # Evaluate ∇f(x+α*s)
68- NLSolversBase. value_gradient! (df, x_new)
69-
70- # Calculate ϕ'(a_i)
71- NLSolversBase. value (df), real (dot (NLSolversBase. gradient (df), s))
72- end
73- make_ϕ (df, x_new, x, s), dϕ, ϕdϕ
49+ make_ϕ_dϕ (df, x_new, x, s)... , make_ϕdϕ (df, x_new, x, s)
7450end
7551function make_ϕ_ϕdϕ (df, x_new, x, s)
76- function ϕdϕ (α)
77- # Move a distance of alpha in the direction of s
78- x_new .= x .+ α.* s
79-
80- # Evaluate ∇f(x+α*s)
81- NLSolversBase. value_gradient! (df, x_new)
82-
83- # Calculate ϕ'(a_i)
84- NLSolversBase. value (df), real (dot (NLSolversBase. gradient (df), s))
85- end
86- make_ϕ (df, x_new, x, s), ϕdϕ
52+ make_ϕ (df, x_new, x, s), make_ϕdϕ (df, x_new, x, s)
8753end
8854
8955include (" types.jl" )
0 commit comments