1 #ifndef STAN_MATH_PRIM_MAT_FUN_CHOLESKY_FACTOR_CONSTRAIN_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_CHOLESKY_FACTOR_CONSTRAIN_HPP
28 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
35 "num rows must be >= num cols");
36 if (x.size() != ((N * (N + 1)) / 2 + (M - N) * N))
38 " be (N * (N + 1)) / 2 + (M - N) * N");
39 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> y(M, N);
43 for (
int m = 0; m < N; ++m) {
44 for (
int n = 0; n < m; ++n)
46 y(m, m) =
exp(x(pos++));
47 for (
int n = m + 1; n < N; ++n)
51 for (
int m = N; m < M; ++m)
52 for (
int n = 0; n < N; ++n)
72 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
80 if (x.size() != ((N * (N + 1)) / 2 + (M - N) * N))
82 "must be (k choose 2) + k");
84 std::vector<T> log_jacobians(N);
85 for (
int n = 0; n < N; ++n) {
87 log_jacobians[n] = x(pos++);
89 lp +=
sum(log_jacobians);
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > cholesky_factor_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, int M, int N)
Return the Cholesky factor of the specified size read from the specified vector.
fvar< T > exp(const fvar< T > &x)
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.