Skip to content

Commit 52aaa06

Browse files
committed
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
1 parent 184f792 commit 52aaa06

File tree

4 files changed

+52
-54
lines changed

4 files changed

+52
-54
lines changed

stan/math/mix/functor/laplace_marginal_density_estimator.hpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,12 @@ struct NewtonState {
374374
* @param a_init Initial a value consistent with theta_init
375375
* @param theta_init Initial theta value
376376
*/
377-
template <typename ObjFun, typename ThetaGradFun, typename CovarianceT, typename ThetaInitializer>
377+
template <typename ObjFun, typename ThetaGradFun, typename CovarianceT,
378+
typename ThetaInitializer>
378379
NewtonState(int theta_size, ObjFun&& obj_fun, ThetaGradFun&& theta_grad_f,
379380
CovarianceT&& covariance, ThetaInitializer&& theta_init)
380-
: wolfe_info(std::forward<ObjFun>(obj_fun), covariance.llt().solve(theta_init),
381+
: wolfe_info(std::forward<ObjFun>(obj_fun),
382+
covariance.llt().solve(theta_init),
381383
std::forward<ThetaInitializer>(theta_init),
382384
std::forward<ThetaGradFun>(theta_grad_f)),
383385
proposal(theta_size),
@@ -950,9 +952,9 @@ inline auto run_newton_loop(SolverPolicy& solver, NewtonStateT& state,
950952
state.wolfe_info.flip_direction();
951953
auto&& scratch = state.wolfe_info.scratch_;
952954
proposal.eval_.alpha() = 1.0;
953-
const bool proposal_valid = update_fun(
954-
proposal, state.curr(), state.prev(), proposal.eval_,
955-
state.wolfe_info.p_);
955+
const bool proposal_valid
956+
= update_fun(proposal, state.curr(), state.prev(), proposal.eval_,
957+
state.wolfe_info.p_);
956958
const bool cached_proposal_ok
957959
= proposal_valid && std::isfinite(proposal.obj())
958960
&& std::isfinite(proposal.dir())
@@ -979,14 +981,13 @@ inline auto run_newton_loop(SolverPolicy& solver, NewtonStateT& state,
979981
const bool proposal_armijo_ok
980982
= cached_proposal_ok
981983
&& internal::check_armijo(
982-
proposal.obj(), state.prev().obj(), proposal.alpha(),
983-
state.wolfe_info.init_dir_, options.line_search);
984+
proposal.obj(), state.prev().obj(), proposal.alpha(),
985+
state.wolfe_info.init_dir_, options.line_search);
984986
if (search_failed && proposal_armijo_ok) {
985987
state.curr().update(proposal);
986-
state.wolfe_status = WolfeStatus{WolfeReturn::Armijo,
987-
state.wolfe_status.num_evals_,
988-
state.wolfe_status.num_backtracks_,
989-
true};
988+
state.wolfe_status
989+
= WolfeStatus{WolfeReturn::Armijo, state.wolfe_status.num_evals_,
990+
state.wolfe_status.num_backtracks_, true};
990991
search_failed = false;
991992
}
992993
bool objective_converged
@@ -1187,7 +1188,8 @@ inline auto laplace_marginal_density_est(
11871188
// the prior term -0.5 * a'*theta vanishes (a=0 while theta!=0), inflating
11881189
// the initial objective and causing the Wolfe line search to reject the
11891190
// first Newton step.
1190-
auto state = NewtonState(theta_size, obj_fun, theta_grad_f, covariance, theta_init);
1191+
auto state
1192+
= NewtonState(theta_size, obj_fun, theta_grad_f, covariance, theta_init);
11911193
// Start with safe step size
11921194
auto update_fun = create_update_fun(
11931195
std::move(obj_fun), std::move(theta_grad_f), covariance, options);

stan/math/mix/functor/wolfe_line_search.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ struct WolfeInfo {
515515
* an inflated initial objective (the prior term -0.5 * a'*theta would
516516
* otherwise vanish when a is zero but theta is not).
517517
*/
518-
template <typename ObjFun, typename Theta0, typename AInit, typename ThetaGradF>
518+
template <typename ObjFun, typename Theta0, typename AInit,
519+
typename ThetaGradF>
519520
WolfeInfo(ObjFun&& obj_fun, AInit&& a_init, Theta0&& theta0,
520521
ThetaGradF&& theta_grad_f)
521522
: curr_(std::forward<ObjFun>(obj_fun), std::forward<AInit>(a_init),

test/unit/math/laplace/laplace_marginal_density_estimator_test.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ TEST(LaplaceMarginalDensityEstimator, PublicLineSearchMatchesDirectStep) {
6969
std::ostringstream no_search_msgs;
7070
std::ostringstream wolfe_msgs;
7171

72-
const double no_search = run_laplace(QuarticLikelihood{}, 2.0, 1e-12, 50, 0,
73-
&no_search_msgs);
74-
const double with_wolfe = run_laplace(QuarticLikelihood{}, 2.0, 1e-12, 50,
75-
1000, &wolfe_msgs);
72+
const double no_search
73+
= run_laplace(QuarticLikelihood{}, 2.0, 1e-12, 50, 0, &no_search_msgs);
74+
const double with_wolfe
75+
= run_laplace(QuarticLikelihood{}, 2.0, 1e-12, 50, 1000, &wolfe_msgs);
7676

7777
EXPECT_TRUE(std::isfinite(no_search));
7878
EXPECT_TRUE(std::isfinite(with_wolfe));
@@ -93,12 +93,9 @@ TEST(LaplaceMarginalDensityEstimator,
9393
InvalidCachedProposalDoesNotTriggerArmijoFallback) {
9494
Eigen::MatrixXd covariance = Eigen::MatrixXd::Identity(1, 1);
9595
Eigen::VectorXd theta0 = Eigen::VectorXd::Zero(1);
96-
auto obj_fun = [](const auto& /*a*/, const auto& /*theta*/) {
97-
return -1.0;
98-
};
99-
auto theta_grad_f = [](const auto& theta) {
100-
return Eigen::VectorXd::Zero(theta.size());
101-
};
96+
auto obj_fun = [](const auto& /*a*/, const auto& /*theta*/) { return -1.0; };
97+
auto theta_grad_f
98+
= [](const auto& theta) { return Eigen::VectorXd::Zero(theta.size()); };
10299
internal::NewtonState state(1, obj_fun, theta_grad_f, covariance, theta0);
103100
laplace_options_base options;
104101
options.hessian_block_size = 1;
@@ -115,14 +112,12 @@ TEST(LaplaceMarginalDensityEstimator,
115112
eval_in.alpha() = 0.5 * min_alpha;
116113
return false;
117114
};
118-
auto unused_ll = [](const auto& /*theta*/, std::ostream* /*msgs*/) {
119-
return 0.0;
120-
};
115+
auto unused_ll
116+
= [](const auto& /*theta*/, std::ostream* /*msgs*/) { return 0.0; };
121117

122-
const double result
123-
= internal::run_newton_loop(solver, state, options, step_iter, unused_ll,
124-
std::tuple<>{}, covariance, failing_update,
125-
nullptr);
118+
const double result = internal::run_newton_loop(
119+
solver, state, options, step_iter, unused_ll, std::tuple<>{}, covariance,
120+
failing_update, nullptr);
126121

127122
EXPECT_DOUBLE_EQ(result, 0.0);
128123
EXPECT_FALSE(state.wolfe_status.accept_);

test/unit/math/laplace/wolfe_line_search_test.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -805,30 +805,30 @@ TEST(WolfeLineSearch, ZoomPreservesCaseTwoLowUpdate) {
805805
opt.scale_up = 2.0;
806806
opt.max_alpha = 1.0;
807807

808-
auto scripted_update = [](auto& proposal, auto&&, auto&&, Eval& eval,
809-
auto&&) {
810-
proposal.a()(0) = eval.alpha();
811-
proposal.theta()(0) = eval.alpha();
812-
proposal.theta_grad()(0) = 0.0;
813-
const double alpha = eval.alpha();
814-
if (std::abs(alpha - 0.5) < 1e-12) {
815-
eval.obj() = 0.5;
816-
eval.dir() = -2.0;
817-
} else if (std::abs(alpha - 0.25) < 1e-12) {
818-
eval.obj() = 0.75;
819-
eval.dir() = 1.0;
820-
} else if (std::abs(alpha - 0.375) < 1e-12) {
821-
eval.obj() = 0.95;
822-
eval.dir() = 0.0;
823-
} else if (std::abs(alpha - 0.125) < 1e-12) {
824-
eval.obj() = 0.6;
825-
eval.dir() = 0.0;
826-
} else {
827-
ADD_FAILURE() << "Unexpected alpha " << alpha;
828-
eval.obj() = -1.0;
829-
eval.dir() = -2.0;
830-
}
831-
};
808+
auto scripted_update
809+
= [](auto& proposal, auto&&, auto&&, Eval& eval, auto&&) {
810+
proposal.a()(0) = eval.alpha();
811+
proposal.theta()(0) = eval.alpha();
812+
proposal.theta_grad()(0) = 0.0;
813+
const double alpha = eval.alpha();
814+
if (std::abs(alpha - 0.5) < 1e-12) {
815+
eval.obj() = 0.5;
816+
eval.dir() = -2.0;
817+
} else if (std::abs(alpha - 0.25) < 1e-12) {
818+
eval.obj() = 0.75;
819+
eval.dir() = 1.0;
820+
} else if (std::abs(alpha - 0.375) < 1e-12) {
821+
eval.obj() = 0.95;
822+
eval.dir() = 0.0;
823+
} else if (std::abs(alpha - 0.125) < 1e-12) {
824+
eval.obj() = 0.6;
825+
eval.dir() = 0.0;
826+
} else {
827+
ADD_FAILURE() << "Unexpected alpha " << alpha;
828+
eval.obj() = -1.0;
829+
eval.dir() = -2.0;
830+
}
831+
};
832832

833833
auto status = wolfe_line_search(info, scripted_update, opt,
834834
static_cast<std::ostream*>(nullptr));

0 commit comments

Comments
 (0)