@@ -13,6 +13,8 @@ is scaled with the `l_2` norm of the step direction.
1313end
1414
1515function (is:: InitialStatic{T} )(ls, state, phi_0, dphi_0, df) where T
16+ # phi_0 is (or should be) equal to NLSolversBase.value(df, state.x) and `state.f_x`
17+ @assert ! hasproperty (state, :f_x ) || phi_0 == state. f_x
1618 PT = promote_type (T, real (eltype (state. s)))
1719 if is. scaled == true && (ns = real (norm (state. s))) > convert (PT, 0 )
1820 # TODO : Type instability if there's a type mismatch between is.alpha and ns?
@@ -70,6 +72,8 @@ If αmax ≠ 1.0, then you should consider to ensure that snap2one[2] < αmax.
7072end
7173
7274function (is:: InitialQuadratic{T} )(ls, state, phi_0, dphi_0, df) where T
75+ # phi_0 is (or should be) equal to NLSolversBase.value(df, state.x) and `state.f_x`
76+ @assert ! hasproperty (state, :f_x ) || phi_0 == state. f_x
7377 if ! isfinite (state. f_x_previous) || isapprox (dphi_0, convert (T, 0 ), atol= eps (T)) # Need to add a tolerance
7478 # If we're at the first iteration
7579 αguess = is. α0
@@ -135,6 +139,8 @@ function InitialConstantChange(; αmin = 1e-12,
135139end
136140
137141function (is:: InitialConstantChange{T} )(ls, state, phi_0, dphi_0, df) where T
142+ # phi_0 is (or should be) equal to NLSolversBase.value(df, state.x) and `state.f_x`
143+ @assert ! hasproperty (state, :f_x ) || phi_0 == state. f_x
138144 if ! isfinite (is. dϕ_0_previous[]) || ! isfinite (state. alpha) ||
139145 isapprox (dphi_0, convert (T, 0 ), atol= eps (T))
140146 # If we're at the first iteration
@@ -175,14 +181,18 @@ otherwise, we select according to procedure I1-2, with starting value α0.
175181end
176182
177183function (is:: InitialHagerZhang )(ls:: Tls , state, phi_0, dphi_0, df) where Tls
184+ # phi_0 is (or should be) equal to NLSolversBase.value(df, state.x) and `state.f_x`
185+ @assert ! hasproperty (state, :f_x ) || phi_0 == state. f_x
178186 if isnan (state. f_x_previous) && isnan (is. α0)
179187 # If we're at the first iteration (f_x_previous is NaN)
180188 # and the user has not provided an initial step size (is.α0 is NaN),
181189 # then we
182190 # pick the initial step size according to HZ #I0
183- # phi_0 is (or should be) equal to NLSolversBase.value(df, state.x)
184- # TODO : Make the gradient available as part of the state?
185- g_x = NLSolversBase. gradient! (df, state. x)
191+ g_x = if hasproperty (state, :g_x )
192+ state. g_x
193+ else
194+ NLSolversBase. gradient! (df, state. x)
195+ end
186196 state. alpha = _hzI0 (state. x, g_x, phi_0,
187197 is. αmax,
188198 convert (eltype (state. x), is. ψ0)) # Hack to deal with type instability between is{T} and state.x
0 commit comments