Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LDLT_factor.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__MATRIX__LDLT_FACTOR_HPP
2 #define STAN__AGRAD__REV__MATRIX__LDLT_FACTOR_HPP
3 
4 #include <stan/agrad/rev/var.hpp>
8 
9 namespace stan {
10  namespace math {
44  template<int R, int C>
45  class LDLT_factor<stan::agrad::var,R,C> {
46  public:
52  LDLT_factor() : _alloc(new stan::agrad::LDLT_alloc<R,C>()) {}
53 
54  LDLT_factor(const Eigen::Matrix<stan::agrad::var,R,C> &A)
55  : _alloc(new stan::agrad::LDLT_alloc<R,C>()) {
56  compute(A);
57  }
58 
67  inline void compute(const Eigen::Matrix<stan::agrad::var,R,C> &A) {
68  stan::math::check_square("comute(%1%)",A,"A",(double*)0);
69  _alloc->compute(A);
70  }
71 
83  template<typename Rhs>
84  inline const Eigen::internal::solve_retval<Eigen::LDLT< Eigen::Matrix<double,R,C> >, Rhs>
85  solve(const Eigen::MatrixBase<Rhs>& b) const {
86  return _alloc->_ldlt.solve(b);
87  }
88 
94  inline bool success() const {
95  bool ret;
96  ret = _alloc->N_ != 0;
97  ret = ret && _alloc->_ldlt.info() == Eigen::Success;
98  ret = ret && _alloc->_ldlt.isPositive();
99  ret = ret && (_alloc->_ldlt.vectorD().array() > 0).all();
100  return ret;
101  }
102 
110  inline Eigen::VectorXd vectorD() const {
111  return _alloc->_ldlt.vectorD();
112  }
113 
114  inline size_t rows() const { return _alloc->N_; }
115  inline size_t cols() const { return _alloc->N_; }
116 
117  typedef size_t size_type;
119 
129  };
130  }
131 }
132 #endif
Eigen::VectorXd vectorD() const
The entries of the diagonal matrix D.
log_determinant_spd_alloc< R, C > * _alloc
This object stores the actual (double typed) LDLT factorization of an Eigen::Matrix<var> along with poi...
Definition: LDLT_alloc.hpp:20
bool success() const
Determine whether the most recent factorization succeeded.
Definition: LDLT_factor.hpp:94
stan::agrad::LDLT_alloc< R, C > * _alloc
The LDLT_alloc object actually contains the factorization but is derived from the chainable_alloc cla...
void compute(const Eigen::Matrix< stan::agrad::var, R, C > &A)
Use the LDLT_factor object to factorize a new matrix.
Definition: LDLT_factor.hpp:67
const Eigen::internal::solve_retval< Eigen::LDLT< Eigen::Matrix< double, R, C > >, Rhs > solve(const Eigen::MatrixBase< Rhs > &b) const
Compute the actual numerical result of inv(A)*b.
Definition: LDLT_factor.hpp:85
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:27
LDLT_factor(const Eigen::Matrix< stan::agrad::var, R, C > &A)
Definition: LDLT_factor.hpp:54
bool check_square(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name, T_result *result)
Return true if the specified matrix is square.

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