@@ -142,68 +142,69 @@ namespace internal {
142142 *
143143 * @param x_left Left endpoint of the current bracket.
144144 * @param f_left Function value at x_left, i.e. f(x_left).
145- * @param df_left Directional derivative at x_left with respect to increasing x,
146- * i.e. f'(x_left) in the search direction.
145+ * @param df_left Directional derivative at x_left with respect to increasing
146+ * x, i.e. f'(x_left) in the search direction.
147147 * @param x_right Right endpoint of the current bracket.
148148 * @param f_right Function value at x_right, i.e. f(x_right).
149- * @param df_right Directional derivative at x_right with respect to increasing x,
150- * i.e. f'(x_right) in the search direction.
149+ * @param df_right Directional derivative at x_right with respect to increasing
150+ * x, i.e. f'(x_right) in the search direction.
151151 *
152152 * @return A trial point in the trimmed interior of (x_left, x_right) chosen by
153153 * the cubic/derivative model. If inputs are degenerate, the midpoint
154154 * (x_left + x_right) / 2 is returned instead.
155155 */
156156template <typename Scalar>
157- [[nodiscard]] inline Scalar
158- cubic_or_bisect_max (Scalar x_left, Scalar f_left, Scalar df_left,
159- Scalar x_right, Scalar f_right, Scalar df_right) noexcept {
160-
157+ [[nodiscard]] inline Scalar cubic_or_bisect_max (Scalar x_left, Scalar f_left,
158+ Scalar df_left, Scalar x_right ,
159+ Scalar f_right,
160+ Scalar df_right) noexcept {
161161 const Scalar midpoint = (x_left + x_right) / Scalar (2 );
162162
163163 // Basic validation: ordering + finiteness.
164- if (!(x_right > x_left) ||
165- !std::isfinite (f_left) || !std::isfinite (f_right) ||
166- !std::isfinite (df_left) || !std::isfinite (df_right)) {
164+ if (!(x_right > x_left) || !std::isfinite (f_left) || !std::isfinite (f_right)
165+ || !std::isfinite (df_left) || !std::isfinite (df_right)) {
167166 return midpoint;
168167 }
169168
170169 const Scalar width = x_right - x_left;
171- const Scalar eps = std::numeric_limits<Scalar>::epsilon ();
170+ const Scalar eps = std::numeric_limits<Scalar>::epsilon ();
172171
173172 // If the bracket is extremely tight, just bisect.
174173 {
175- const Scalar x_scale =
176- std::max (std::max (std::abs (x_left), std::abs (x_right)), Scalar (1 ));
174+ const Scalar x_scale
175+ = std::max (std::max (std::abs (x_left), std::abs (x_right)), Scalar (1 ));
177176 if (width <= eps * x_scale) {
178177 return midpoint;
179178 }
180179 }
181180
182181 // Derivatives with respect to s, where x = x_left + s * width.
183- const Scalar df_left_s = width * df_left; // F'(0)
182+ const Scalar df_left_s = width * df_left; // F'(0)
184183 const Scalar df_right_s = width * df_right; // F'(1)
185184
186185 // Cubic Hermite coefficients in s ∈ [0,1]:
187186 // F(s) = a3*s^3 + a2*s^2 + a1*s + a0
188187 // with F(0) = f_left, F'(0) = df_left_s, F(1) = f_right, F'(1) = df_right_s.
189188 const Scalar a0 = f_left;
190189 const Scalar a1 = df_left_s;
191- const Scalar a2 = Scalar (3 ) * (f_right - f_left) - Scalar (2 ) * df_left_s - df_right_s;
190+ const Scalar a2
191+ = Scalar (3 ) * (f_right - f_left) - Scalar (2 ) * df_left_s - df_right_s;
192192 const Scalar a3 = Scalar (2 ) * (f_left - f_right) + df_left_s + df_right_s;
193193
194194 auto eval = [&](Scalar s) -> Scalar {
195195 // Horner evaluation of F(s).
196196 return ((a3 * s + a2) * s + a1) * s + a0;
197197 };
198198
199- // Candidates are restricted to a trimmed interior [edge_guard, 1 - edge_guard].
199+ // Candidates are restricted to a trimmed interior [edge_guard, 1 -
200+ // edge_guard].
200201 constexpr Scalar edge_guard = Scalar (1e-9 );
201202
202203 struct Candidate {
203204 Scalar s_;
204205 Scalar value_;
205206 };
206- Candidate best{ 0.5 , eval (0.5 ) }; // Start from bisection.
207+ Candidate best{0.5 , eval (0.5 )}; // Start from bisection.
207208 auto consider = [&](Scalar s) {
208209 if (!std::isfinite (s)) {
209210 return ;
@@ -213,18 +214,19 @@ cubic_or_bisect_max(Scalar x_left, Scalar f_left, Scalar df_left,
213214 }
214215 const Scalar value = eval (s);
215216 if (value > best.value_ ) {
216- best.s_ = s;
217+ best.s_ = s;
217218 best.value_ = value;
218219 }
219220 };
220221
221222 // 1) Secant estimate for the derivative root between s = 0 and s = 1.
222223 {
223- const Scalar denom = df_left_s - df_right_s;
224- const Scalar deriv_scale =
225- std::max (std::max ( std:: abs (df_left_s), std::abs (df_right_s)), Scalar (1 ));
224+ const Scalar denom = df_left_s - df_right_s;
225+ const Scalar deriv_scale = std::max (
226+ std::max (std::abs (df_left_s), std::abs (df_right_s)), Scalar (1 ));
226227 if (std::abs (denom) > eps * deriv_scale) {
227- const Scalar s_secant = df_left_s / denom; // Root of linear interpolation of F'.
228+ const Scalar s_secant
229+ = df_left_s / denom; // Root of linear interpolation of F'.
228230 consider (s_secant);
229231 }
230232 }
@@ -236,8 +238,8 @@ cubic_or_bisect_max(Scalar x_left, Scalar f_left, Scalar df_left,
236238 const Scalar B = Scalar (2 ) * a2;
237239 const Scalar C = a1;
238240
239- const Scalar scale =
240- std::max (std::max (std::abs (B), std::abs (C)), Scalar (1 ));
241+ const Scalar scale
242+ = std::max (std::max (std::abs (B), std::abs (C)), Scalar (1 ));
241243 const Scalar A_tol = eps * scale;
242244
243245 if (std::abs (A) <= A_tol) {
@@ -249,8 +251,8 @@ cubic_or_bisect_max(Scalar x_left, Scalar f_left, Scalar df_left,
249251 } else {
250252 // Proper quadratic: A*s^2 + B*s + C = 0.
251253 Scalar disc = std::fma (-Scalar (4 ) * A, C, B * B); // B^2 - 4AC
252- const Scalar disc_scale =
253- std::max (B * B + std::abs (Scalar (4 ) * A * C), Scalar (1 ));
254+ const Scalar disc_scale
255+ = std::max (B * B + std::abs (Scalar (4 ) * A * C), Scalar (1 ));
254256 const Scalar disc_tol = Scalar (10 ) * eps * disc_scale;
255257
256258 // Treat tiny negative discriminants as zero.
@@ -261,8 +263,7 @@ cubic_or_bisect_max(Scalar x_left, Scalar f_left, Scalar df_left,
261263 if (disc >= Scalar (0 )) {
262264 const Scalar r = std::sqrt (disc);
263265 const Scalar q = -Scalar (0.5 ) * (B + std::copysign (r, B));
264- const Scalar q_scale =
265- std::max (std::abs (B) + r, Scalar (1 ));
266+ const Scalar q_scale = std::max (std::abs (B) + r, Scalar (1 ));
266267 const Scalar q_tol = eps * q_scale;
267268
268269 if (std::abs (q) > q_tol) {
@@ -583,8 +584,8 @@ struct WolfeInfo {
583584 * 2. **Quick strong-Wolfe accept and “zoom-up”.**
584585 *
585586 * If the current `high` satisfies **both** Armijo and curvature, the code
586- * repeatedly *expands* \f$\alpha \leftarrow \alpha \cdot \text{opt.scale\_up}\f$
587- * while the strong-Wolfe tests continue to hold and
587+ * repeatedly *expands* \f$\alpha \leftarrow \alpha \cdot
588+ * \text{opt.scale\_up}\f$ while the strong-Wolfe tests continue to hold and
588589 * \f$\alpha \le \text{opt.max\_alpha}\f$. The last step that still passes
589590 * strong-Wolfe is stored and finally accepted into `curr_`, and the routine
590591 * returns with status `Wolfe`.
0 commit comments