1 #ifndef STAN_MATH_PRIM_MAT_FUN_LDLT_FACTOR_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_LDLT_FACTOR_HPP
5 #include <boost/shared_ptr.hpp>
17 template<
typename T,
int R,
int C>
57 template<
int R,
int C,
typename T>
68 inline void compute(
const Eigen::Matrix<T, R, C> &A) {
82 if (
_ldltP->info() != Eigen::Success)
84 if (!(
_ldltP->isPositive()))
86 Eigen::Matrix<T, Eigen::Dynamic, 1> ldltP_diag(
_ldltP->vectorD());
87 for (
int i = 0; i < ldltP_diag.size(); ++i)
88 if (ldltP_diag(i) <= 0 ||
is_nan(ldltP_diag(i)))
94 return _ldltP->vectorD().array().log().sum();
97 inline void inverse(Eigen::Matrix<T, R, C> &invA)
const {
99 _ldltP->solveInPlace(invA);
102 template<
typename Rhs>
104 Eigen::internal::solve_retval<Eigen::LDLT< Eigen::Matrix<T, R, C> >, Rhs>
105 solve(
const Eigen::MatrixBase<Rhs>& b)
const {
109 inline Eigen::Matrix<T, R, C>
114 inline Eigen::Matrix<T, Eigen::Dynamic, 1>
vectorD()
const {
118 inline Eigen::LDLT<Eigen::Matrix<T, R, C> >
matrixLDLT()
const {
119 return _ldltP->matrixLDLT();
122 inline size_t rows()
const {
return N_; }
123 inline size_t cols()
const {
return N_; }
129 boost::shared_ptr< Eigen::LDLT< Eigen::Matrix<T, R, C> > >
_ldltP;
void inverse(Eigen::Matrix< T, R, C > &invA) const
const Eigen::internal::solve_retval< Eigen::LDLT< Eigen::Matrix< T, R, C > >, Rhs > solve(const Eigen::MatrixBase< Rhs > &b) const
boost::shared_ptr< Eigen::LDLT< Eigen::Matrix< T, R, C > > > _ldltP
LDLT_factor(const Eigen::Matrix< T, R, C > &A)
Eigen::Matrix< T, R, C > solveRight(const Eigen::Matrix< T, R, C > &B) const
(Expert) Numerical traits for algorithmic differentiation variables.
Eigen::LDLT< Eigen::Matrix< T, R, C > > matrixLDLT() const
boost::shared_ptr< Eigen::LDLT< Eigen::Matrix< double, R1, C1 > > > _ldltP
This share_ptr is used to prevent copying the LDLT factorizations for mdivide_left_ldlt(ldltA, b) when ldltA is a LDLT_factor.
Eigen::Matrix< T, Eigen::Dynamic, 1 > vectorD() const
void compute(const Eigen::Matrix< T, R, C > &A)
int is_nan(const fvar< T > &x)
Returns 1 if the input's value is NaN and 0 otherwise.
Eigen::Matrix< T, C, R > transpose(const Eigen::Matrix< T, R, C > &m)
bool check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is square.