LDLT_factor.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_FUN_LDLT_FACTOR_HPP
#define STAN_MATH_PRIM_MAT_FUN_LDLT_FACTOR_HPP
#include <stan/math/prim/mat/err/check_square.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/scal/fun/is_nan.hpp>
#include <boost/shared_ptr.hpp>
namespace stan {
namespace math {
template <typename T, int R, int C>
class LDLT_factor;
template <int R, int C, typename T>
class LDLT_factor<T, R, C> {
public:
LDLT_factor()
: N_(0), ldltP_(new Eigen::LDLT<Eigen::Matrix<T, R, C> >()) {}
explicit LDLT_factor(const Eigen::Matrix<T, R, C>& A)
: N_(0), ldltP_(new Eigen::LDLT<Eigen::Matrix<T, R, C> >()) {
compute(A);
}
inline void compute(const Eigen::Matrix<T, R, C>& A) {
check_square("LDLT_factor", "A", A);
N_ = A.rows();
ldltP_->compute(A);
}
inline bool success() const {
if (ldltP_->info() != Eigen::Success)
return false;
if (!(ldltP_->isPositive()))
return false;
Eigen::Matrix<T, Eigen::Dynamic, 1> ldltP_diag(ldltP_->vectorD());
for (int i = 0; i < ldltP_diag.size(); ++i)
if (ldltP_diag(i) <= 0 || is_nan(ldltP_diag(i)))
return false;
return true;
}
inline T log_abs_det() const {
return ldltP_->vectorD().array().log().sum();
}
inline void inverse(Eigen::Matrix<T, R, C>& invA) const {
invA.setIdentity(N_);
ldltP_->solveInPlace(invA);
}
#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
template <typename Rhs>
inline const
Eigen::Solve<Eigen::LDLT<Eigen::Matrix<T, R, C> >, Rhs>
solve(const Eigen::MatrixBase<Rhs>& b) const {
return ldltP_->solve(b);
}
#else
template <typename Rhs>
inline const
Eigen::internal::solve_retval<Eigen::LDLT< Eigen::Matrix<T, R, C> >, Rhs>
solve(const Eigen::MatrixBase<Rhs>& b) const {
return ldltP_->solve(b);
}
#endif
inline Eigen::Matrix<T, R, C>
solveRight(const Eigen::Matrix<T, R, C>& B) const {
return ldltP_->solve(B.transpose()).transpose();
}
inline Eigen::Matrix<T, Eigen::Dynamic, 1> vectorD() const {
return ldltP_->vectorD();
}
inline Eigen::LDLT<Eigen::Matrix<T, R, C> > matrixLDLT() const {
return ldltP_->matrixLDLT();
}
inline size_t rows() const { return N_; }
inline size_t cols() const { return N_; }
typedef size_t size_type;
typedef double value_type;
size_t N_;
boost::shared_ptr<Eigen::LDLT<Eigen::Matrix<T, R, C> > > ldltP_;
};
}
}
#endif
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>.
Definition: mdivide_left_ldlt.hpp:23
stan::math::LDLT_factor< T, R, C >::value_type
double value_type
Definition: LDLT_factor.hpp:126
is_nan.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::LDLT_factor< T, R, C >::rows
size_t rows() const
Definition: LDLT_factor.hpp:122
stan::math::LDLT_factor< T, R, C >::LDLT_factor
LDLT_factor()
Definition: LDLT_factor.hpp:58
stan::math::LDLT_factor< T, R, C >::LDLT_factor
LDLT_factor(const Eigen::Matrix< T, R, C > &A)
Definition: LDLT_factor.hpp:61
Eigen
(Expert) Numerical traits for algorithmic differentiation variables.
Definition: Eigen_NumTraits.hpp:9
stan::math::LDLT_factor< T, R, C >::log_abs_det
T log_abs_det() const
Definition: LDLT_factor.hpp:84
stan::math::LDLT_factor< T, R, C >::solve
const Eigen::internal::solve_retval< Eigen::LDLT< Eigen::Matrix< T, R, C > >, Rhs > solve(const Eigen::MatrixBase< Rhs > &b) const
Definition: LDLT_factor.hpp:104
stan::math::LDLT_factor
Definition: LDLT_factor.hpp:13
stan::math::LDLT_factor< T, R, C >::inverse
void inverse(Eigen::Matrix< T, R, C > &invA) const
Definition: LDLT_factor.hpp:88
stan::math::LDLT_factor< T, R, C >::matrixLDLT
Eigen::LDLT< Eigen::Matrix< T, R, C > > matrixLDLT() const
Definition: LDLT_factor.hpp:118
stan::math::LDLT_factor< T, R, C >::solveRight
Eigen::Matrix< T, R, C > solveRight(const Eigen::Matrix< T, R, C > &B) const
Definition: LDLT_factor.hpp:110
stan::math::LDLT_factor< T, R, C >::success
bool success() const
Definition: LDLT_factor.hpp:72
stan::math::LDLT_factor< T, R, C >::N_
size_t N_
Definition: LDLT_factor.hpp:128
Eigen.hpp
stan::math::check_square
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.
Definition: check_square.hpp:27
stan::math::LDLT_factor< T, R, C >::cols
size_t cols() const
Definition: LDLT_factor.hpp:123
stan::math::LDLT_factor< T, R, C >::size_type
size_t size_type
Definition: LDLT_factor.hpp:125
stan::math::LDLT_factor< T, R, C >::ldltP_
boost::shared_ptr< Eigen::LDLT< Eigen::Matrix< T, R, C > > > ldltP_
Definition: LDLT_factor.hpp:129
stan::math::LDLT_factor< T, R, C >::vectorD
Eigen::Matrix< T, Eigen::Dynamic, 1 > vectorD() const
Definition: LDLT_factor.hpp:114
stan::math::LDLT_factor< T, R, C >::compute
void compute(const Eigen::Matrix< T, R, C > &A)
Definition: LDLT_factor.hpp:66
stan::math::is_nan
int is_nan(const fvar< T > &x)
Returns 1 if the input&#39;s value is NaN and 0 otherwise.
Definition: is_nan.hpp:21
stan::math::transpose
Eigen::Matrix< T, C, R > transpose(const Eigen::Matrix< T, R, C > &m)
Definition: transpose.hpp:12
N_
int N_
Definition: mdivide_left.hpp:20
check_square.hpp

[ Stan Home Page ] © 2011–2016, Stan Development Team.