1#ifndef STAN_MATH_PRIM_CONSTRAINT_COV_MATRIX_CONSTRAIN_HPP
2#define STAN_MATH_PRIM_CONSTRAINT_COV_MATRIX_CONSTRAIN_HPP
30template <
typename T, require_eigen_col_vector_t<T>* =
nullptr>
31inline Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, Eigen::Dynamic>
37 Matrix<value_type_t<T>, Dynamic, Dynamic> L(K, K);
39 "K + (K choose 2)", (K * (K + 1)) / 2);
40 const auto& x_ref =
to_ref(x);
42 for (Eigen::Index m = 0; m < K; ++m) {
43 L.row(m).head(m) = x_ref.segment(i, m);
45 L.coeffRef(m, m) =
exp(x_ref.coeff(i++));
46 L.row(m).tail(K - m - 1).setZero();
63template <
typename T, require_eigen_col_vector_t<T>* =
nullptr>
64inline Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, Eigen::Dynamic>
71 "K + (K choose 2)", (K * (K + 1)) / 2);
72 Matrix<value_type_t<T>, Dynamic, Dynamic> L(K, K);
73 const auto& x_ref =
to_ref(x);
75 for (Eigen::Index m = 0; m < K; ++m) {
76 L.row(m).head(m) = x_ref.segment(i, m);
78 L.coeffRef(m, m) =
exp(x_ref.coeff(i++));
79 L.row(m).tail(K - m - 1).setZero();
83 for (Eigen::Index k = 0; k < K; ++k) {
84 lp += (K - k + 1) *
log(L.coeff(k, k));
107template <
bool Jacobian,
typename T, require_not_std_vector_t<T>* =
nullptr>
135template <
bool Jacobian,
typename T, require_std_vector_t<T>* =
nullptr>
138 return apply_vector_unary<T>::apply(x, [&lp, K](
auto&& v) {
139 return cov_matrix_constrain<Jacobian>(v, K, lp);
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
Eigen::Matrix< value_type_t< EigMat >, EigMat::RowsAtCompileTime, EigMat::RowsAtCompileTime > multiply_lower_tri_self_transpose(const EigMat &m)
Eigen::Matrix< value_type_t< T >, Eigen::Dynamic, Eigen::Dynamic > cov_matrix_constrain(const T &x, Eigen::Index K)
Return the symmetric, positive-definite matrix of dimensions K by K resulting from transforming the s...
fvar< T > log(const fvar< T > &x)
static constexpr double LOG_TWO
The natural logarithm of 2, .
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
fvar< T > exp(const fvar< T > &x)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...