1 #ifndef STAN_MATH_PRIM_MAT_FUN_LDLT_FACTOR_HPP 2 #define STAN_MATH_PRIM_MAT_FUN_LDLT_FACTOR_HPP 7 #include <boost/shared_ptr.hpp> 12 template <
typename T,
int R,
int C>
55 template <
int R,
int C,
typename T>
66 inline void compute(
const Eigen::Matrix<T, R, C>& A) {
73 if (
ldltP_->info() != Eigen::Success)
75 if (!(
ldltP_->isPositive()))
77 Eigen::Matrix<T, Eigen::Dynamic, 1> ldltP_diag(
ldltP_->vectorD());
78 for (
int i = 0; i < ldltP_diag.size(); ++i)
79 if (ldltP_diag(i) <= 0 ||
is_nan(ldltP_diag(i)))
85 return ldltP_->vectorD().array().log().sum();
88 inline void inverse(Eigen::Matrix<T, R, C>& invA)
const {
90 ldltP_->solveInPlace(invA);
93 #if EIGEN_VERSION_AT_LEAST(3, 3, 0) 94 template <
typename Rhs>
96 Eigen::Solve<Eigen::LDLT<Eigen::Matrix<T, R, C> >, Rhs>
97 solve(
const Eigen::MatrixBase<Rhs>& b)
const {
101 template <
typename Rhs>
103 Eigen::internal::solve_retval<Eigen::LDLT< Eigen::Matrix<T, R, C> >, Rhs>
104 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_;
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<double>.
LDLT_factor(const Eigen::Matrix< T, R, C > &A)
(Expert) Numerical traits for algorithmic differentiation variables.
const Eigen::internal::solve_retval< Eigen::LDLT< Eigen::Matrix< T, R, C > >, Rhs > solve(const Eigen::MatrixBase< Rhs > &b) const
void inverse(Eigen::Matrix< T, R, C > &invA) const
Eigen::LDLT< Eigen::Matrix< T, R, C > > matrixLDLT() const
Eigen::Matrix< T, R, C > solveRight(const Eigen::Matrix< T, R, C > &B) const
void check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Check if the specified matrix is square.
boost::shared_ptr< Eigen::LDLT< Eigen::Matrix< T, R, C > > > ldltP_
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)