1#ifndef STAN_MATH_PRIM_FUN_READ_CORR_L_HPP
2#define STAN_MATH_PRIM_FUN_READ_CORR_L_HPP
36template <
typename T, require_eigen_vector_t<T>* =
nullptr>
37Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, Eigen::Dynamic>
read_corr_L(
45 return Eigen::Matrix<T_scalar, Eigen::Dynamic, Eigen::Dynamic>::Identity(1,
50 Eigen::Array<T_scalar, Eigen::Dynamic, 1> temp;
51 Eigen::Array<T_scalar, Eigen::Dynamic, 1> acc(K - 1);
54 Eigen::Matrix<T_scalar, Eigen::Dynamic, Eigen::Dynamic> L(K, K);
61 L.col(0).tail(pull) = temp = CPCs.head(pull);
62 acc.tail(pull) = T_scalar(1.0) - temp.square();
63 for (
size_t i = 1; i < (K - 1); i++) {
66 temp = CPCs.segment(position, pull);
67 L(i, i) =
sqrt(acc(i - 1));
68 L.col(i).tail(pull) = temp * acc.tail(pull).sqrt();
69 acc.tail(pull) *= T_scalar(1.0) - temp.square();
71 L(K - 1, K - 1) =
sqrt(acc(K - 2));
100template <
typename T, require_eigen_vector_t<T>* =
nullptr>
101Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, Eigen::Dynamic>
read_corr_L(
108 return Eigen::Matrix<T_scalar, Eigen::Dynamic, Eigen::Dynamic>::Identity(1,
112 const Eigen::Ref<const plain_type_t<T>>& CPCs_ref = CPCs;
118 for (
size_t k = 1; k <= (K - 2); k++) {
119 for (
size_t i = k + 1; i <= K; i++) {
125 log_prob += 0.5 * acc;
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
fvar< T > sqrt(const fvar< T > &x)
fvar< T > log1m(const fvar< T > &x)
Eigen::Matrix< value_type_t< T >, Eigen::Dynamic, Eigen::Dynamic > read_corr_L(const T &CPCs, size_t K)
Return the Cholesky factor of the correlation matrix of the specified dimensionality corresponding to...
fvar< T > square(const fvar< T > &x)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...