Skip to content

Commit 817f4f3

Browse files
committed
fix laplace for expr tests
1 parent e881e77 commit 817f4f3

2 files changed

Lines changed: 20 additions & 37 deletions

File tree

stan/math/mix/functor/laplace_marginal_density.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ inline auto laplace_marginal_density(LLFun&& ll_fun, LLTupleArgs&& ll_args,
6565
},
6666
std::forward<CovarArgs>(covar_args));
6767
return internal::laplace_marginal_density_est(
68-
std::forward<LLFun>(ll_fun), std::forward<LLTupleArgs>(ll_args),
68+
std::forward<LLFun>(ll_fun), to_ref(std::forward<LLTupleArgs>(ll_args)),
6969
std::move(covariance), options, msgs)
7070
.lmd;
7171
}

test/unit/math/laplace/laplace_types_test.cpp

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,12 @@ TEST_P(laplace_types, poisson_log_phi_dim_2_tuple_extended) {
118118
using stan::math::var;
119119
// logger->current_test_name_ = "poisson_log_phi_dim_2";
120120
constexpr int dim_phi = 2;
121-
Eigen::Matrix<double, Eigen::Dynamic, 1> phi_dbl(dim_phi);
122-
phi_dbl << 1.6, 0.45;
121+
Eigen::Matrix<double, Eigen::Dynamic, 1> phi_dbl{{1.6, 0.45}};
123122

124123
int dim_theta = 2;
125-
Eigen::VectorXd theta_0(dim_theta);
126-
theta_0 << 0, 0;
127-
128-
std::vector<Eigen::VectorXd> x(dim_theta);
129-
Eigen::VectorXd x_0{{0.05100797, 0.16086164}};
130-
Eigen::VectorXd x_1{{-0.59823393, 0.98701425}};
131-
x[0] = x_0;
132-
x[1] = x_1;
124+
Eigen::VectorXd theta_0{{0, 0}};
133125

134-
Eigen::VectorXd y_dummy;
126+
std::vector<Eigen::VectorXd> x{Eigen::VectorXd{{0.05100797, 0.16086164}}, Eigen::VectorXd{{-0.59823393, 0.98701425}}};
135127

136128
std::vector<int> n_samples = {1, 1};
137129
std::vector<int> sums = {1, 0};
@@ -150,25 +142,29 @@ TEST_P(laplace_types, poisson_log_phi_dim_2_tuple_extended) {
150142
stan::test::ad_gradient_tols{1e-8, 1e-2}};
151143
// stan::test::ad_tolerances tols;
152144
// tols.gradient_grad_ = 1e-1;
153-
auto f_ll = [&](auto&& eta1, auto&& eta2, auto&& eta3) {
145+
auto f_ll = [&](auto&& phi, auto&& eta1, auto&& eta2) {
146+
auto phi_ref = stan::math::eval(stan::math::to_ref(phi));
154147
try {
155-
auto eta1_tuple = std::make_tuple(eta1(0), eta1(1));
148+
auto phi_tuple = std::make_tuple(phi_ref(0), phi_ref(1));
156149
return laplace_marginal_tol<false>(
157150
poisson_log_likelihood_tuple_expanded{},
158-
std::forward_as_tuple(sums, eta1_tuple, eta2, eta3),
151+
std::forward_as_tuple(sums, phi_tuple, eta1, eta2),
159152
hessian_block_size, stan::math::test::squared_kernel_functor{},
160-
std::forward_as_tuple(x, std::make_tuple(phi_dbl(0), phi_dbl(1))),
153+
std::forward_as_tuple(x, std::make_tuple(phi_ref(0), phi_ref(1))),
161154
std::make_tuple(theta_0, tolerance, max_num_steps, solver_num,
162155
max_steps_line_search, true),
163156
&output_stream);
164157
} catch (const std::exception& e) {
165158
std::stringstream fail_msg;
166159
using stan::math::test::test_type_name;
167-
fail_msg << "Exception thrown with eta1("
168-
<< test_type_name<decltype(eta1)>() << ")=" << eta1[0]
169-
<< ", eta2(" << test_type_name<decltype(eta2)>()
170-
<< ")=" << eta2[0] << ", eta3("
171-
<< test_type_name<decltype(eta3)>() << ")=" << eta3[0] << ". ";
160+
auto eta1_ref = stan::math::eval(stan::math::to_ref(eta1));
161+
auto eta2_ref = stan::math::eval(stan::math::to_ref(eta2));
162+
fail_msg << "Exception thrown with phi("
163+
<< test_type_name<decltype(phi_ref)>() << ")=" << phi_ref[0]
164+
<< ", phi(" << test_type_name<decltype(phi_ref)>() << ")="
165+
<< phi_ref[0] << ", eta1(" << test_type_name<decltype(eta1_ref)>() << ")="
166+
<< eta1_ref[0] << ", eta2(" << test_type_name<decltype(eta2_ref)>() << ")="
167+
<< eta2_ref[0] << ". ";
172168
ADD_FAILURE() << fail_msg.str() << "\n Error message: " << e.what();
173169
throw;
174170
}
@@ -199,8 +195,6 @@ TEST_P(laplace_types, poisson_log_phi_dim_2_tuple) {
199195
x[0] = x_0;
200196
x[1] = x_1;
201197

202-
Eigen::VectorXd y_dummy;
203-
204198
std::vector<int> n_samples = {1, 1};
205199
std::vector<int> sums = {1, 0};
206200
const auto test_params = GetParam();
@@ -283,21 +277,10 @@ TEST_P(laplace_types, poisson_log_phi_dim_2_array_tuple) {
283277
using stan::math::var;
284278
// logger->current_test_name_ = "poisson_log_phi_dim_2";
285279
constexpr int dim_phi = 2;
286-
Eigen::Matrix<double, Eigen::Dynamic, 1> phi_dbl(dim_phi);
287-
phi_dbl << 1.6, 0.45;
288-
280+
Eigen::Matrix<double, Eigen::Dynamic, 1> phi_dbl{{1.6, 0.45}};
289281
constexpr int dim_theta = 2;
290-
Eigen::VectorXd theta_0(dim_theta);
291-
theta_0 << 0, 0;
292-
293-
std::vector<Eigen::VectorXd> x(dim_theta);
294-
Eigen::VectorXd x_0{{0.05100797, 0.16086164}};
295-
Eigen::VectorXd x_1{{-0.59823393, 0.98701425}};
296-
x[0] = x_0;
297-
x[1] = x_1;
298-
299-
Eigen::VectorXd y_dummy;
300-
282+
Eigen::VectorXd theta_0{{0, 0}};
283+
std::vector<Eigen::VectorXd> x{Eigen::VectorXd{{0.05100797, 0.16086164}}, Eigen::VectorXd{{-0.59823393, 0.98701425}}};
301284
std::vector<int> n_samples = {1, 1};
302285
std::vector<int> sums = {1, 0};
303286
const auto test_params = GetParam();

0 commit comments

Comments
 (0)