1 #ifndef STAN_MATH_PRIM_FUN_READ_COV_L_HPP
2 #define STAN_MATH_PRIM_FUN_READ_COV_L_HPP
3
4 #include <stan/math/prim/fun/Eigen.hpp>
5 #include <stan/math/prim/fun/log.hpp>
6 #include <stan/math/prim/fun/read_corr_L.hpp>
7 #include <stan/math/prim/fun/sum.hpp>
8 #include <stan/math/prim/fun/constants.hpp>
9
10 namespace stan {
11 namespace math {
12
13 /**
14 * This is the function that should be called prior to evaluating
15 * the density of any elliptical distribution
16 *
17 * @tparam T_CPCs type of \c T_CPCs vector (must be derived from \c
18 * Eigen::ArrayBase and have one compile-time dimension equal to 1)
19 * @tparam T_sds type of \c sds vector (must be derived from \c Eigen::ArrayBase
20 * and have one compile-time dimension equal to 1)
21 * @param CPCs on (-1, 1)
22 * @param sds on (0, inf)
23 * @param log_prob the log probability value to increment with the Jacobian
24 * @return Cholesky factor of covariance matrix for specified
25 * partial correlations.
26 */
27 template <typename T_CPCs, typename T_sds,
28 require_all_eigen_vector_t<T_CPCs, T_sds>* = nullptr,
29 require_vt_same<T_CPCs, T_sds>* = nullptr>
read_cov_L(const T_CPCs & CPCs,const T_sds & sds,value_type_t<T_CPCs> & log_prob)30 Eigen::Matrix<value_type_t<T_CPCs>, Eigen::Dynamic, Eigen::Dynamic> read_cov_L(
31 const T_CPCs& CPCs, const T_sds& sds, value_type_t<T_CPCs>& log_prob) {
32 size_t K = sds.rows();
33 // adjust due to transformation from correlations to covariances
34 log_prob += (sum(log(sds)) + LOG_TWO) * K;
35 return make_holder(
36 [](const auto& b, const auto& sds) {
37 return sds.matrix().asDiagonal() * b;
38 },
39 read_corr_L(CPCs, K, log_prob), to_ref(sds));
40 }
41
42 } // namespace math
43 } // namespace stan
44
45 #endif
46