1#ifndef STAN_MATH_PRIM_FUN_FACTOR_COV_MATRIX_HPP
2#define STAN_MATH_PRIM_FUN_FACTOR_COV_MATRIX_HPP
24template <
typename T_Sigma,
typename T_CPCs,
typename T_sds,
25 require_eigen_t<T_Sigma>* =
nullptr,
26 require_all_eigen_vector_t<T_CPCs, T_sds>* =
nullptr,
27 require_all_vt_same<T_Sigma, T_CPCs, T_sds>* =
nullptr>
30 size_t K = sds.rows();
31 const Eigen::Ref<const plain_type_t<T_Sigma>>& Sigma_ref = Sigma;
32 sds = Sigma_ref.diagonal().array();
33 if ((sds <= 0.0).
any()) {
38 Eigen::DiagonalMatrix<T_scalar, Eigen::Dynamic> D(K);
39 D.diagonal() = sds.inverse();
42 Eigen::Matrix<T_scalar, Eigen::Dynamic, Eigen::Dynamic> R = D * Sigma_ref * D;
44 R.diagonal().setOnes();
45 Eigen::LDLT<Eigen::Matrix<T_scalar, Eigen::Dynamic, Eigen::Dynamic>> ldlt;
47 if (!ldlt.isPositive()) {
50 Eigen::Matrix<T_scalar, Eigen::Dynamic, Eigen::Dynamic> U = ldlt.matrixU();
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
constexpr bool any(T x)
Return true if any values in the input are true.
void factor_U(const T_U &U, T_CPCs &&CPCs)
This function is intended to make starting values, given a unit upper-triangular matrix U such that U...
bool factor_cov_matrix(const T_Sigma &Sigma, T_CPCs &&CPCs, T_sds &&sds)
This function is intended to make starting values, given a covariance matrix Sigma.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...