Skip to content

Commit e4431fd

Browse files
authored
Merge pull request #3330 from stan-dev/fix/tuple_to_laplace_options-forwarding
Fix typo in tuple_to_laplace_options forwarding function
2 parents 58feca3 + 7233ad0 commit e4431fd

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

stan/math/mix/functor/laplace_marginal_density_estimator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ inline constexpr auto tuple_to_laplace_options(Options&& ops) {
154154
}
155155
auto defaults = laplace_options_default{};
156156
return laplace_options_user_supplied{
157-
value_of(std::get<0>(std::forward<Ops>(ops))),
157+
value_of(std::get<0>(std::forward<Options>(ops))),
158158
std::get<1>(ops),
159159
std::get<2>(ops),
160160
defaults.hessian_block_size,
@@ -163,7 +163,7 @@ inline constexpr auto tuple_to_laplace_options(Options&& ops) {
163163
(std::get<5>(ops) > 0) ? true : false,
164164
};
165165
} else {
166-
return std::forward<Ops>(ops);
166+
return std::forward<Options>(ops);
167167
}
168168
}
169169

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <test/unit/math/test_ad.hpp>
2+
#include <test/unit/math/laplace/laplace_utility.hpp>
3+
4+
TEST(laplace_utils, tuple_to_laplace_options) {
5+
using stan::math::laplace_options_user_supplied;
6+
using stan::math::internal::tuple_to_laplace_options;
7+
8+
auto ops = std::make_tuple(Eigen::VectorXd::Zero(3), 1e-6, 100, 1, 2, 0);
9+
auto laplace_opts = tuple_to_laplace_options(ops);
10+
EXPECT_EQ(laplace_opts.hessian_block_size, 1);
11+
EXPECT_EQ(laplace_opts.solver, 1);
12+
EXPECT_EQ(laplace_opts.tolerance, 1e-6);
13+
EXPECT_EQ(laplace_opts.max_num_steps, 100);
14+
EXPECT_EQ(laplace_opts.line_search.max_iterations, 2);
15+
EXPECT_EQ(laplace_opts.allow_fallthrough, false);
16+
EXPECT_EQ(laplace_opts.theta_0, Eigen::VectorXd::Zero(3));
17+
static_assert(
18+
std::is_same_v<decltype(laplace_opts), laplace_options_user_supplied>);
19+
}
20+
21+
TEST(laplace_utils, tuple_to_laplace_options_move) {
22+
using stan::math::laplace_options_user_supplied;
23+
using stan::math::internal::tuple_to_laplace_options;
24+
25+
auto ops = std::make_tuple(Eigen::VectorXd::Zero(3), 1e-6, 100, 1, 2, 1);
26+
auto laplace_opts = tuple_to_laplace_options(std::move(ops));
27+
EXPECT_EQ(laplace_opts.hessian_block_size, 1);
28+
EXPECT_EQ(laplace_opts.solver, 1);
29+
EXPECT_EQ(laplace_opts.tolerance, 1e-6);
30+
EXPECT_EQ(laplace_opts.max_num_steps, 100);
31+
EXPECT_EQ(laplace_opts.line_search.max_iterations, 2);
32+
EXPECT_EQ(laplace_opts.allow_fallthrough, true);
33+
EXPECT_EQ(laplace_opts.theta_0, Eigen::VectorXd::Zero(3));
34+
static_assert(
35+
std::is_same_v<decltype(laplace_opts), laplace_options_user_supplied>);
36+
}

0 commit comments

Comments
 (0)