Skip to content

Commit 586613a

Browse files
committed
update
1 parent 8234959 commit 586613a

6 files changed

Lines changed: 34 additions & 30 deletions

File tree

stan/math/mix/prob.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
#include <stan/math/mix/prob/laplace_latent_bernoulli_logit_rng.hpp>
55
#include <stan/math/mix/prob/laplace_latent_poisson_log_rng.hpp>
6-
#include <stan/math/mix/prob/laplace_latent_poisson_log_exposure_rng.hpp>
6+
#include <stan/math/mix/prob/laplace_latent_poisson_log_2_rng.hpp>
77
#include <stan/math/mix/prob/laplace_latent_neg_binomial_2_log_rng.hpp>
88
#include <stan/math/mix/prob/laplace_latent_rng.hpp>
99
#include <stan/math/mix/prob/laplace_marginal.hpp>
1010
#include <stan/math/mix/prob/laplace_marginal_neg_binomial_2_log_lpmf.hpp>
1111
#include <stan/math/mix/prob/laplace_marginal_bernoulli_logit_lpmf.hpp>
12-
#include <stan/math/mix/prob/laplace_marginal_poisson_log_exposure_lpmf.hpp>
12+
#include <stan/math/mix/prob/laplace_marginal_poisson_log_2_lpmf.hpp>
1313
#include <stan/math/mix/prob/laplace_marginal_poisson_log_lpmf.hpp>
1414

1515
#endif

stan/math/mix/prob/laplace_latent_poisson_log_exposure_rng.hpp renamed to stan/math/mix/prob/laplace_latent_poisson_log_2_rng.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#ifndef STAN_MATH_MIX_PROB_LAPLACE_LATENT_POISSON_LOG_EXPOSURE_RNG_HPP
2-
#define STAN_MATH_MIX_PROB_LAPLACE_LATENT_POISSON_LOG_EXPOSURE_RNG_HPP
1+
#ifndef STAN_MATH_MIX_PROB_LAPLACE_LATENT_POISSON_LOG_2_RNG_HPP
2+
#define STAN_MATH_MIX_PROB_LAPLACE_LATENT_POISSON_LOG_2_RNG_HPP
33

44
#include <stan/math/mix/functor/laplace_base_rng.hpp>
55
#include <stan/math/mix/functor/laplace_likelihood.hpp>
6-
#include <stan/math/mix/prob/laplace_marginal_poisson_log_exposure_lpmf.hpp>
6+
#include <stan/math/mix/prob/laplace_marginal_poisson_log_2_lpmf.hpp>
77

88
namespace stan {
99
namespace math {
@@ -38,7 +38,7 @@ inline auto laplace_latent_tol_poisson_2_log_rng(
3838
const int max_steps_line_search, RNG& rng, std::ostream* msgs) {
3939
laplace_options ops{hessian_block_size, solver, max_steps_line_search,
4040
tolerance, max_num_steps};
41-
return laplace_base_rng(poisson_log_exposure_likelihood{},
41+
return laplace_base_rng(poisson_log_2_likelihood{},
4242
std::forward_as_tuple(y, y_index, ye),
4343
std::forward<ThetaVec>(theta_0),
4444
std::forward<CovarFun>(covariance_function),
@@ -71,7 +71,7 @@ inline auto laplace_latent_poisson_2_log_rng(
7171
ThetaVec&& theta_0, CovarFun&& covariance_function, CovarArgs&& covar_args,
7272
RNG& rng, std::ostream* msgs) {
7373
constexpr laplace_options ops{1, 1, 0, 1e-6, 100};
74-
return laplace_base_rng(poisson_log_exposure_likelihood{},
74+
return laplace_base_rng(poisson_log_2_likelihood{},
7575
std::forward_as_tuple(y, y_index, ye),
7676
std::forward<ThetaVec>(theta_0),
7777
std::forward<CovarFun>(covariance_function),

stan/math/mix/prob/laplace_marginal_poisson_log_exposure_lpmf.hpp renamed to stan/math/mix/prob/laplace_marginal_poisson_log_2_lpmf.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef STAN_MATH_MIX_PROB_LAPLACE_MARGINAL_POISSON_LOG_EXPOSURE_LPMF_HPP
2-
#define STAN_MATH_MIX_PROB_LAPLACE_MARGINAL_POISSON_LOG_EXPOSURE_LPMF_HPP
1+
#ifndef STAN_MATH_MIX_PROB_LAPLACE_MARGINAL_POISSON_LOG_2_LPMF_HPP
2+
#define STAN_MATH_MIX_PROB_LAPLACE_MARGINAL_POISSON_LOG_2_LPMF_HPP
33

44
#include <stan/math/mix/functor/laplace_marginal_density.hpp>
55
#include <stan/math/mix/functor/laplace_likelihood.hpp>
@@ -18,7 +18,7 @@
1818
namespace stan {
1919
namespace math {
2020

21-
struct poisson_log_exposure_likelihood {
21+
struct poisson_log_2_likelihood {
2222
/**
2323
* Returns the lpmf for a Poisson with a log link across
2424
* multiple groups. No need to compute the log normalizing constant.
@@ -81,7 +81,7 @@ inline auto laplace_marginal_tol_poisson_2_log_lpmf(
8181
laplace_options ops{hessian_block_size, solver, max_steps_line_search,
8282
tolerance, max_num_steps};
8383
return laplace_marginal_density(
84-
poisson_log_exposure_likelihood{}, std::forward_as_tuple(y, y_index, ye),
84+
poisson_log_2_likelihood{}, std::forward_as_tuple(y, y_index, ye),
8585
theta_0, std::forward<CovarFun>(covariance_function),
8686
std::forward<CovarArgs>(covar_args), ops, msgs);
8787
}
@@ -111,7 +111,7 @@ inline auto laplace_marginal_poisson_2_log_lpmf(
111111
CovarArgs&& covar_args, std::ostream* msgs) {
112112
constexpr laplace_options ops{1, 1, 0, 1e-6, 100};
113113
return laplace_marginal_density(
114-
poisson_log_exposure_likelihood{}, std::forward_as_tuple(y, y_index, ye),
114+
poisson_log_2_likelihood{}, std::forward_as_tuple(y, y_index, ye),
115115
theta_0, std::forward<CovarFun>(covariance_function),
116116
std::forward<CovarArgs>(covar_args), ops, msgs);
117117
}

stan/math/prim/fun/value_of.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ inline decltype(auto) value_of(T&& x) {
3434
return x;
3535
}
3636
} else {
37-
return make_holder([](auto&& m) { return m; }, std::forward<T>(x));
37+
return make_holder([](auto&& m) -> decltype(auto) {
38+
return std::forward<decltype(m)>(m);
39+
}, std::forward<T>(x));
3840
}
3941
} else {
4042
if constexpr (std::is_rvalue_reference_v<T&&>) {

stan/math/prim/meta/holder.hpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <memory>
88
#include <type_traits>
99
#include <utility>
10-
1110
/**
1211
* \defgroup eigen_expressions Eigen expressions
1312
*/
@@ -250,13 +249,17 @@ namespace math {
250249
*/
251250
template <typename T, typename... Ptrs,
252251
std::enable_if_t<sizeof...(Ptrs) >= 1>* = nullptr>
253-
Holder<T, Ptrs...> holder(T&& arg, Ptrs*... pointers) {
252+
inline Holder<T, Ptrs...> holder(T&& arg, Ptrs*... pointers) {
254253
return Holder<T, Ptrs...>(std::forward<T>(arg), pointers...);
255254
}
256255
// trivial case with no pointers constructs no holder object
257256
template <typename T>
258-
T holder(T&& arg) {
259-
return std::forward<T>(arg);
257+
inline decltype(auto) holder(T&& arg) {
258+
if constexpr (std::is_rvalue_reference<T&&>::value) {
259+
return std::decay_t<T>(std::forward<T>(arg));
260+
} else {
261+
return std::forward<T>(arg);
262+
}
260263
}
261264

262265
namespace internal {
@@ -271,14 +274,14 @@ namespace internal {
271274
* @return tuple of pointers allocated on heap (empty).
272275
*/
273276
template <typename T>
274-
auto holder_handle_element(T& a, T*& res) {
277+
inline auto holder_handle_element(T& a, T*& res) {
275278
res = &a;
276279
return std::make_tuple();
277280
}
278281
template <typename T,
279282
std::enable_if_t<!(Eigen::internal::traits<std::decay_t<T>>::Flags
280283
& Eigen::NestByRefBit)>* = nullptr>
281-
auto holder_handle_element(T&& a, std::remove_reference_t<T>*& res) {
284+
inline auto holder_handle_element(T&& a, std::remove_reference_t<T>*& res) {
282285
res = &a;
283286
return std::make_tuple();
284287
}
@@ -297,13 +300,13 @@ template <typename T, require_t<std::is_rvalue_reference<T&&>>* = nullptr,
297300
std::enable_if_t<
298301
static_cast<bool>(Eigen::internal::traits<std::decay_t<T>>::Flags&
299302
Eigen::NestByRefBit)>* = nullptr>
300-
auto holder_handle_element(T&& a, T*& res) {
303+
inline auto holder_handle_element(T&& a, T*& res) {
301304
res = new T(std::move(a));
302305
return std::make_tuple(res);
303306
}
304307
template <typename T, require_t<std::is_rvalue_reference<T&&>>* = nullptr,
305308
require_not_eigen_t<T>* = nullptr>
306-
auto holder_handle_element(T&& a, T*& res) {
309+
inline auto holder_handle_element(T&& a, T*& res) {
307310
res = new T(std::move(a));
308311
return std::make_tuple(res);
309312
}
@@ -320,7 +323,7 @@ auto holder_handle_element(T&& a, T*& res) {
320323
* @return `holder` referencing given expression
321324
*/
322325
template <typename T, std::size_t... Is, typename... Args>
323-
auto make_holder_impl_construct_object(T&& expr, std::index_sequence<Is...>,
326+
inline auto make_holder_impl_construct_object(T&& expr, std::index_sequence<Is...>,
324327
const std::tuple<Args*...>& ptrs) {
325328
return holder(std::forward<T>(expr), std::get<Is>(ptrs)...);
326329
}
@@ -335,13 +338,13 @@ auto make_holder_impl_construct_object(T&& expr, std::index_sequence<Is...>,
335338
* @return `holder` referencing expression constructed by given functor
336339
*/
337340
template <typename F, std::size_t... Is, typename... Args>
338-
auto make_holder_impl(const F& func, std::index_sequence<Is...>,
341+
inline auto make_holder_impl(F&& func, std::index_sequence<Is...>,
339342
Args&&... args) {
340343
std::tuple<std::remove_reference_t<Args>*...> res;
341344
auto ptrs = std::tuple_cat(
342345
holder_handle_element(std::forward<Args>(args), std::get<Is>(res))...);
343346
return make_holder_impl_construct_object(
344-
func(*std::get<Is>(res)...),
347+
std::forward<F>(func)(*std::get<Is>(res)...),
345348
std::make_index_sequence<std::tuple_size<decltype(ptrs)>::value>(), ptrs);
346349
}
347350

@@ -362,8 +365,8 @@ auto make_holder_impl(const F& func, std::index_sequence<Is...>,
362365
template <
363366
typename F, typename... Args,
364367
require_not_plain_type_t<std::invoke_result_t<F, Args&&...>>* = nullptr>
365-
auto make_holder(const F& func, Args&&... args) {
366-
return internal::make_holder_impl(func,
368+
inline auto make_holder(F&& func, Args&&... args) {
369+
return internal::make_holder_impl(std::forward<F>(func),
367370
std::make_index_sequence<sizeof...(Args)>(),
368371
std::forward<Args>(args)...);
369372
}
@@ -380,8 +383,8 @@ auto make_holder(const F& func, Args&&... args) {
380383
*/
381384
template <typename F, typename... Args,
382385
require_plain_type_t<std::invoke_result_t<F, Args&&...>>* = nullptr>
383-
auto make_holder(const F& func, Args&&... args) {
384-
return func(std::forward<Args>(args)...);
386+
inline auto make_holder(F&& func, Args&&... args) {
387+
return std::forward<F>(func)(std::forward<Args>(args)...);
385388
}
386389

387390
} // namespace math

test/unit/math/prim/fun/value_of_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ TEST(MathFunctions, value_of_return_type_short_circuit_matrix_xd) {
191191

192192
TEST(MathFunctions, value_of_return_type_short_circuit_expression) {
193193
const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> a(5, 4);
194-
195194
const auto& expr = 3 * a;
196-
197195
EXPECT_TRUE((std::is_same<decltype(stan::math::value_of(expr)),
198196
decltype(expr)>::value));
199197
}
@@ -206,3 +204,4 @@ TEST(MathFunctions, value_of_return_type_short_circuit_static_sized_matrix) {
206204
EXPECT_TRUE((std::is_same<decltype(stan::math::value_of(b)),
207205
const Eigen::Matrix<double, 5, 4>&>::value));
208206
}
207+

0 commit comments

Comments
 (0)