1#ifndef STAN_MATH_REV_CONSTRAINT_COV_MATRIX_CONSTRAIN_HPP
2#define STAN_MATH_REV_CONSTRAINT_COV_MATRIX_CONSTRAIN_HPP
31template <
typename T, require_var_vector_t<T>* =
nullptr>
36 "K + (K choose 2)", (K * (K + 1)) / 2);
39 for (Eigen::Index m = 0; m < K; ++m) {
40 L_val.row(m).head(m) = x.val().segment(i, m);
42 L_val.coeffRef(m, m) =
exp(x.val().coeff(i));
49 Eigen::Index K = L.rows();
51 for (
int m = K - 1; m >= 0; --m) {
53 x.adj().coeffRef(i) += L.adj().coeff(m, m) * L.val().coeff(m, m);
55 x.adj().segment(i, m) += L.adj().row(m).head(m);
76template <
typename T, require_var_vector_t<T>* =
nullptr>
83 "K + (K choose 2)", (K * (K + 1)) / 2);
86 for (Eigen::Index m = 0; m < K; ++m) {
87 L_val.row(m).head(m) = x.val().segment(pos, m);
89 L_val.coeffRef(m, m) =
exp(x.val().coeff(pos));
95 for (Eigen::Index k = 0; k < K; ++k) {
97 lp_val += (K - k + 1) *
log(L_val.coeff(k, k));
105 Eigen::Index K = L.rows();
106 for (Eigen::Index k = 0; k < K; ++k) {
107 L.adj().coeffRef(k, k) += (K - k + 1) * lp.adj() / L.val().coeff(k, k);
110 for (
int m = K - 1; m >= 0; --m) {
112 x.adj().coeffRef(pos) += L.adj().coeff(m, m) * L.val().coeff(m, m);
114 x.adj().segment(pos, m) += L.adj().row(m).head(m);
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...
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
fvar< T > log(const fvar< T > &x)
static constexpr double LOG_TWO
The natural logarithm of 2, .
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)
typename scalar_type< T >::type scalar_type_t
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...