Skip to content

Commit 1df65b1

Browse files
committed
update with tests for generate_laplace_options
1 parent 57aab3d commit 1df65b1

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <stan/math/mix/functor/laplace_marginal_density_estimator.hpp>
2+
#include <gtest/gtest.h>
3+
4+
namespace stan::math::test {
5+
6+
TEST(LaplaceMarginalDensityEstimator, GenerateLaplaceOptionsFromSizeDefaults) {
7+
constexpr int theta_0_size = 4;
8+
const auto defaults = laplace_options_default{};
9+
10+
const auto options = stan::math::generate_laplace_options(theta_0_size);
11+
const auto& theta_0 = std::get<0>(options);
12+
13+
EXPECT_EQ(theta_0_size, theta_0.size());
14+
EXPECT_TRUE(theta_0.isApprox(Eigen::VectorXd::Zero(theta_0_size)));
15+
EXPECT_DOUBLE_EQ(defaults.tolerance, std::get<1>(options));
16+
EXPECT_EQ(defaults.max_num_steps, std::get<2>(options));
17+
EXPECT_EQ(defaults.solver, std::get<3>(options));
18+
EXPECT_EQ(defaults.line_search.max_iterations, std::get<4>(options));
19+
EXPECT_EQ(static_cast<int>(defaults.allow_fallthrough), std::get<5>(options));
20+
}
21+
22+
TEST(LaplaceMarginalDensityEstimator, GenerateLaplaceOptionsFromSizeZero) {
23+
const auto options = stan::math::generate_laplace_options(0);
24+
const auto& theta_0 = std::get<0>(options);
25+
26+
EXPECT_EQ(0, theta_0.size());
27+
}
28+
29+
TEST(LaplaceMarginalDensityEstimator, GenerateLaplaceOptionsFromThetaDefaults) {
30+
Eigen::VectorXd theta_0(3);
31+
theta_0 << -1.2, 0.5, 2.3;
32+
const auto defaults = laplace_options_default{};
33+
34+
const auto options = stan::math::generate_laplace_options(theta_0);
35+
36+
EXPECT_TRUE(theta_0.isApprox(std::get<0>(options)));
37+
EXPECT_DOUBLE_EQ(defaults.tolerance, std::get<1>(options));
38+
EXPECT_EQ(defaults.max_num_steps, std::get<2>(options));
39+
EXPECT_EQ(defaults.solver, std::get<3>(options));
40+
EXPECT_EQ(defaults.line_search.max_iterations, std::get<4>(options));
41+
EXPECT_EQ(static_cast<int>(defaults.allow_fallthrough), std::get<5>(options));
42+
}
43+
44+
} // namespace stan::math::test

0 commit comments

Comments
 (0)