11module LineSearches
22
33using Printf: @sprintf
4- using LinearAlgebra: dot, norm
4+ using LinearAlgebra: norm
55using NaNMath: NaNMath
66using NLSolversBase: NLSolversBase, AbstractObjective
77
@@ -28,11 +28,8 @@ function make_ϕdϕ(df, x_new, x, s)
2828 # Move a distance of alpha in the direction of s
2929 x_new .= x .+ α.* s
3030
31- # Evaluate ∇f(x+α*s)
32- NLSolversBase. value_gradient! (df, x_new)
33-
3431 # Calculate ϕ(a_i), ϕ'(a_i)
35- NLSolversBase. value (df), real ( dot (NLSolversBase . gradient (df) , s) )
32+ return NLSolversBase. value_jvp! (df, x_new , s)
3633 end
3734 ϕdϕ
3835end
@@ -41,49 +38,16 @@ function make_ϕ_dϕ(df, x_new, x, s)
4138 # Move a distance of alpha in the direction of s
4239 x_new .= x .+ α.* s
4340
44- # Evaluate ∇f(x+α*s)
45- NLSolversBase. gradient! (df, x_new)
46-
4741 # Calculate ϕ'(a_i)
48- real ( dot ( NLSolversBase. gradient (df), s) )
42+ return NLSolversBase. jvp! (df, x_new, s )
4943 end
5044 make_ϕ (df, x_new, x, s), dϕ
5145end
5246function 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ϕ
47+ make_ϕ_dϕ (df, x_new, x, s)... , make_ϕdϕ (df, x_new, x, s)
7448end
7549function 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ϕ
50+ make_ϕ (df, x_new, x, s), make_ϕdϕ (df, x_new, x, s)
8751end
8852
8953include (" types.jl" )
0 commit comments