1#ifndef STAN_MATH_PRIM_CONSTRAINT_CHOLESKY_FACTOR_CONSTRAIN_HPP
2#define STAN_MATH_PRIM_CONSTRAINT_CHOLESKY_FACTOR_CONSTRAIN_HPP
28template <
typename T, require_eigen_col_vector_t<T>* =
nullptr>
29inline Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, Eigen::Dynamic>
34 "num rows (must be greater or equal to num cols)", M,
37 "((N * (N + 1)) / 2 + (M - N) * N)",
38 ((N * (N + 1)) / 2 + (M - N) * N));
39 Eigen::Matrix<T_scalar, Eigen::Dynamic, Eigen::Dynamic> y(M, N);
42 const auto& x_ref =
to_ref(x);
43 for (
int m = 0; m < N; ++m) {
44 y.row(m).head(m) = x_ref.segment(pos, m);
46 y.coeffRef(m, m) =
exp(x_ref.coeff(pos++));
47 y.row(m).tail(N - m - 1).setZero();
50 for (
int m = N; m < M; ++m) {
51 y.row(m) = x_ref.segment(pos, N);
73template <
typename T,
typename Lp, require_eigen_vector_t<T>* =
nullptr,
74 require_convertible_t<return_type_t<T>, Lp>* =
nullptr>
75inline Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, Eigen::Dynamic>
78 "((N * (N + 1)) / 2 + (M - N) * N)",
79 ((N * (N + 1)) / 2 + (M - N) * N));
81 const auto& x_ref =
to_ref(x);
82 for (
int n = 0; n < N; ++n) {
84 lp += x_ref.coeff(pos++);
103template <
typename T, require_std_vector_t<T>* =
nullptr>
126template <
typename T,
typename Lp, require_std_vector_t<T>* =
nullptr,
127 require_convertible_t<return_type_t<T>, Lp>* =
nullptr>
156template <
bool Jacobian,
typename T,
typename Lp,
159 if constexpr (Jacobian) {
require_t< std::is_convertible< std::decay_t< T >, std::decay_t< S > > > require_convertible_t
Require types T and S satisfies std::is_convertible.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
void check_greater_or_equal(const char *function, const char *name, const T_y &y, const T_low &low, Idxs... idxs)
Throw an exception if y is not greater or equal than low.
Eigen::Matrix< value_type_t< T >, Eigen::Dynamic, Eigen::Dynamic > cholesky_factor_constrain(const T &x, int M, int N)
Return the Cholesky factor of the specified size read from the specified vector.
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 ...