From 0abf5d54e0f5e7d8ab13eff42aa4483534cd6306 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Thu, 12 Dec 2024 15:07:55 -0500 Subject: [PATCH] Changes per review --- src/stan/services/optimize/laplace_sample.hpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/stan/services/optimize/laplace_sample.hpp b/src/stan/services/optimize/laplace_sample.hpp index 423c8c8ea4..85d3127403 100644 --- a/src/stan/services/optimize/laplace_sample.hpp +++ b/src/stan/services/optimize/laplace_sample.hpp @@ -54,12 +54,10 @@ void laplace_sample(const Model& model, const Eigen::VectorXd& theta_hat, // create log density functor for vars and vals std::stringstream log_density_msgs; - auto log_density_fun - = [&](const Eigen::Matrix& theta) { - return model.template log_prob( - const_cast&>(theta), - &log_density_msgs); - }; + auto log_density_fun = [&](auto&& theta) { + return model.template log_prob( + theta, &log_density_msgs); + }; // calculate inverse negative Hessian's Cholesky factor if (refresh > 0) { @@ -123,7 +121,8 @@ void laplace_sample(const Model& model, const Eigen::VectorXd& theta_hat, if (calculate_lp) { // clean up created vars after scope exit stan::math::nested_rev_autodiff stack; - log_p = log_density_fun(unc_draw).val(); + auto theta = unc_draw.cast().eval(); + log_p = log_density_fun(theta).val(); } else { log_p = std::numeric_limits::quiet_NaN(); }