Skip to content

Commit 62432fb

Browse files
committed
Merge commit '3a196d410415ee2cc56c0e51ec73a2e1970a08a4' into HEAD
2 parents 9ca0e0a + 3a196d4 commit 62432fb

21 files changed

+413
-261
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ If this is a **feature request**, show what you expect to happen if the feature
2525

2626

2727
#### Current Version:
28-
v5.0.0
28+
v5.1.0

doxygen/doxygen.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PROJECT_NAME = "Stan Math Library"
4848
# could be handy for archiving the generated documentation or if some version
4949
# control system is used.
5050

51-
PROJECT_NUMBER = 5.0.0
51+
PROJECT_NUMBER = 5.1.0
5252

5353
# Using the PROJECT_BRIEF tag one can provide an optional one line description
5454
# for a project that appears at the top of each page and should give viewer a

stan/math/mix/functor/laplace_likelihood.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ inline auto compute_s2(F&& f, Theta&& theta, AMat&& A,
226226
Matrix<fvar<fvar<var>>, Dynamic, 1> theta_ffvar(theta_size);
227227
auto shallow_copy_args
228228
= shallow_copy_vargs<fvar<fvar<var>>>(std::forward_as_tuple(args...));
229-
// build a “row” index 0,1,2,…,total-1
230-
Eigen::Index total = n_blocks * hessian_block_size;
231229
for (Eigen::Index i = 0; i < hessian_block_size; ++i) {
232230
nested_rev_autodiff nested;
233231
v.setZero();

stan/math/mix/functor/laplace_marginal_density.hpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define STAN_MATH_MIX_FUNCTOR_LAPLACE_MARGINAL_DENSITY_HPP
33
#include <stan/math/prim/fun/Eigen.hpp>
44
#include <stan/math/mix/functor/laplace_likelihood.hpp>
5-
#include <test/unit/pretty_print_types.hpp>
65
#include <stan/math/rev/meta.hpp>
76
#include <stan/math/rev/core.hpp>
87
#include <stan/math/rev/fun.hpp>
@@ -315,7 +314,9 @@ inline void set_zero_adjoint(Output&& output) {
315314
static_assert(
316315
sizeof(std::decay_t<output_i_t>*) == 0,
317316
"INTERNAL ERROR:(laplace_marginal_lpdf) set_zero_adjoints was "
318-
"not able to deduce the actions needed for the given type.");
317+
"not able to deduce the actions needed for the given type. "
318+
"This is an internal error, please report it: "
319+
"https://github.com/stan-dev/math/issues");
319320
}
320321
},
321322
std::forward<Output>(output));
@@ -360,7 +361,9 @@ inline void collect_adjoints(Output& output, Input&& input) {
360361
static_assert(
361362
sizeof(std::decay_t<output_i_t>*) == 0,
362363
"INTERNAL ERROR:(laplace_marginal_lpdf) set_zero_adjoints was "
363-
"not able to deduce the actions needed for the given type.");
364+
"not able to deduce the actions needed for the given type. "
365+
"This is an internal error, please report it: "
366+
"https://github.com/stan-dev/math/issues");
364367
}
365368
},
366369
std::forward<Output>(output), std::forward<Input>(input));
@@ -497,7 +500,7 @@ inline auto laplace_marginal_density_est(LLFun&& ll_fun, LLTupleArgs&& ll_args,
497500
};
498501
auto ll_args_vals = value_of(ll_args);
499502
const Eigen::Index theta_size = theta_0.size();
500-
std::decay_t<ThetaVec> theta = theta_0;
503+
Eigen::VectorXd theta = std::forward<ThetaVec>(theta_0);
501504
double objective_old = std::numeric_limits<double>::lowest();
502505
double objective_new = std::numeric_limits<double>::lowest() + 1;
503506
Eigen::VectorXd a_prev = Eigen::VectorXd::Zero(theta_size);
@@ -814,7 +817,9 @@ inline void collect_adjoints(Output&& output, Input&& input) {
814817
static_assert(
815818
sizeof(std::decay_t<output_i_t>*) == 0,
816819
"INTERNAL ERROR:(laplace_marginal_lpdf) set_zero_adjoints was "
817-
"not able to deduce the actions needed for the given type.");
820+
"not able to deduce the actions needed for the given type. "
821+
"This is an internal error, please report it: "
822+
"https://github.com/stan-dev/math/issues");
818823
}
819824
},
820825
std::forward<Output>(output), std::forward<Input>(input));
@@ -864,7 +869,9 @@ inline void copy_compute_s2(Output&& output, Input&& input) {
864869
static_assert(
865870
sizeof(std::decay_t<output_i_t>*) == 0,
866871
"INTERNAL ERROR:(laplace_marginal_lpdf) set_zero_adjoints was "
867-
"not able to deduce the actions needed for the given type.");
872+
"not able to deduce the actions needed for the given type. "
873+
"This is an internal error, please report it: "
874+
"https://github.com/stan-dev/math/issues");
868875
}
869876
},
870877
std::forward<Output>(output), std::forward<Input>(input));
@@ -921,11 +928,11 @@ template <typename Output, typename Input>
921928
inline void collect_adjoints(Output&& output, const vari* ret, Input&& input) {
922929
if constexpr (is_tuple_v<Output>) {
923930
static_assert(sizeof(std::decay_t<Output>*) == 0,
924-
"INTERNAL ERROR:(laplace_marginal_lpdf)"
931+
"INTERNAL ERROR:(laplace_marginal_lpdf) "
925932
"Accumulate Adjoints called on a tuple, but tuples cannot be "
926-
"on the reverse mode stack!"
927-
"This is an internal error, please report it to the stan "
928-
"github as an issue.");
933+
"on the reverse mode stack! "
934+
"This is an internal error, please report it: "
935+
"https://github.com/stan-dev/math/issues");
929936
} else if constexpr (is_std_vector_v<Output>) {
930937
if constexpr (!is_var_v<value_type_t<Output>>) {
931938
const auto output_size = output.size();
@@ -1032,7 +1039,7 @@ inline auto laplace_marginal_density(const LLFun& ll_fun, LLTupleArgs&& ll_args,
10321039
// Solver 3
10331040
arena_t<Eigen::MatrixXd> LU_solve_covariance;
10341041
// Solver 1, 2, 3
1035-
arena_t<promote_scalar_t<double, std::decay_t<ThetaVec>>> s2(
1042+
arena_t<promote_scalar_t<double, plain_type_t<std::decay_t<ThetaVec>>>> s2(
10361043
theta_0.size());
10371044
// Make one hard copy here
10381045
using laplace_likelihood::internal::conditional_copy_and_promote;

stan/math/prim/fun/cholesky_decompose.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,11 @@ namespace math {
2828
*/
2929
template <typename EigMat, require_eigen_t<EigMat>* = nullptr,
3030
require_not_eigen_vt<is_var, EigMat>* = nullptr>
31-
inline Eigen::Matrix<value_type_t<EigMat>, EigMat::RowsAtCompileTime,
32-
EigMat::ColsAtCompileTime>
33-
cholesky_decompose(const EigMat& m) {
34-
const eval_return_type_t<EigMat>& m_eval = m.eval();
31+
inline plain_type_t<EigMat> cholesky_decompose(const EigMat& m) {
32+
auto&& m_eval = to_ref(m);
3533
check_symmetric("cholesky_decompose", "m", m_eval);
3634
check_not_nan("cholesky_decompose", "m", m_eval);
37-
Eigen::LLT<Eigen::Matrix<value_type_t<EigMat>, EigMat::RowsAtCompileTime,
38-
EigMat::ColsAtCompileTime>>
39-
llt = m_eval.llt();
35+
Eigen::LLT<plain_type_t<EigMat>> llt = m_eval.llt();
4036
check_pos_definite("cholesky_decompose", "m", llt);
4137
return llt.matrixL();
4238
}

stan/math/prim/fun/promote_scalar.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include <stan/math/prim/fun/Eigen.hpp>
55
#include <stan/math/prim/functor/apply.hpp>
6-
#include <test/unit/pretty_print_types.hpp>
76
#include <stan/math/prim/meta.hpp>
87
#include <vector>
98
#include <tuple>
@@ -45,9 +44,11 @@ inline constexpr auto promote_scalar(UnPromotedTypes&& x) {
4544
} else if constexpr (is_stan_scalar_v<UnPromotedTypes>) {
4645
return PromotionScalars(std::forward<UnPromotedTypes>(x));
4746
} else {
48-
throw std::domain_error(
49-
"promote_scalar: "
50-
"Unrecognized type for promotion");
47+
static_assert(sizeof(std::decay_t<UnPromotedTypes>*) == 0,
48+
"INTERNAL ERROR:(promote_scalar) "
49+
"Unrecognized type for promotion. "
50+
"This is an internal error, please report it: "
51+
"https://github.com/stan-dev/math/issues");
5152
}
5253
}
5354

stan/math/prim/meta/forward_as.hpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,38 @@ inline T_actual&& forward_as(T_actual&& a) { // NOLINT
5454
* @return nothing, this always throws
5555
* @throw always throws std::runtime_error
5656
*/
57+
template <
58+
typename T_desired, typename T_actual,
59+
require_any_not_eigen_t<T_desired, T_actual>* = nullptr,
60+
typename = std::enable_if_t<
61+
!std::is_same<std::decay<T_actual>, std::decay<T_desired>>::value
62+
&& !(std::is_floating_point_v<std::decay_t<
63+
T_desired>> && std::is_integral_v<std::decay_t<T_actual>>)>>
64+
inline T_desired forward_as(const T_actual& a) {
65+
throw std::runtime_error("Wrong type assumed! Please file a bug report.");
66+
}
67+
68+
/** \ingroup type_trait
69+
* Assume which type we get. If actual type is not convertible to assumed type
70+
* or in case of eigen types compile time rows and columns are not the same and
71+
* desired sizes are not dynamic this has return type of \c T_desired, but it
72+
* only throws. This version should only be used where it is optimized away so
73+
* the throw should never happen.
74+
*
75+
* This handles the edge case where both types are simple arithmetic types
76+
* and we would like to just convert one to another.
77+
*
78+
* @tparam T_desired type of output we need to avoid compile time errors
79+
* @tparam T_actual actual type of the argument
80+
* @param a input value
81+
* @return a
82+
*/
5783
template <typename T_desired, typename T_actual,
5884
typename = std::enable_if_t<
59-
!std::is_same<std::decay<T_actual>, std::decay<T_desired>>::value
60-
&& (!is_eigen<T_desired>::value || !is_eigen<T_actual>::value)>>
85+
std::is_floating_point_v<std::decay_t<
86+
T_desired>> && std::is_integral_v<std::decay_t<T_actual>>>>
6187
inline T_desired forward_as(const T_actual& a) {
62-
throw std::runtime_error("Wrong type assumed! Please file a bug report.");
88+
return static_cast<T_desired>(a);
6389
}
6490

6591
/** \ingroup type_trait

stan/math/version.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#endif
1313

1414
#define STAN_MATH_MAJOR 5
15-
#define STAN_MATH_MINOR 0
15+
#define STAN_MATH_MINOR 1
1616
#define STAN_MATH_PATCH 0
1717

1818
namespace stan {

0 commit comments

Comments
 (0)