Stan Math Library  2.9.0
reverse mode automatic differentiation
LDLT_factor.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_MAT_FUN_LDLT_FACTOR_HPP
2 #define STAN_MATH_REV_MAT_FUN_LDLT_FACTOR_HPP
3 
4 #include <stan/math/rev/core.hpp>
8 
9 namespace stan {
10  namespace math {
44  template<int R, int C>
45  class LDLT_factor<stan::math::var, R, C> {
46  public:
52  LDLT_factor() : _alloc(new stan::math::LDLT_alloc<R, C>()) {}
53 
54  explicit LDLT_factor(const Eigen::Matrix<stan::math::var, R, C> &A)
55  : _alloc(new stan::math::LDLT_alloc<R, C>()) {
56  compute(A);
57  }
58 
67  inline void compute(const Eigen::Matrix<stan::math::var, R, C> &A) {
68  stan::math::check_square("comute", "A", A);
69  _alloc->compute(A);
70  }
71 
83  template<typename Rhs>
84  inline const
85  Eigen::internal::solve_retval<Eigen::LDLT<Eigen::Matrix<double, R, C> >,
86  Rhs>
87  solve(const Eigen::MatrixBase<Rhs>& b) const {
88  return _alloc->_ldlt.solve(b);
89  }
90 
96  inline bool success() const {
97  bool ret;
98  ret = _alloc->N_ != 0;
99  ret = ret && _alloc->_ldlt.info() == Eigen::Success;
100  ret = ret && _alloc->_ldlt.isPositive();
101  ret = ret && (_alloc->_ldlt.vectorD().array() > 0).all();
102  return ret;
103  }
104 
112  inline Eigen::VectorXd vectorD() const {
113  return _alloc->_ldlt.vectorD();
114  }
115 
116  inline size_t rows() const { return _alloc->N_; }
117  inline size_t cols() const { return _alloc->N_; }
118 
119  typedef size_t size_type;
121 
131  };
132  }
133 }
134 #endif
LDLT_factor(const Eigen::Matrix< stan::math::var, R, C > &A)
Definition: LDLT_factor.hpp:54
void compute(const Eigen::Matrix< stan::math::var, R, C > &A)
Use the LDLT_factor object to factorize a new matrix.
Definition: LDLT_factor.hpp:67
stan::math::LDLT_alloc< R, C > * _alloc
The LDLT_alloc object actually contains the factorization but is derived from the chainable_alloc cla...
This object stores the actual (double typed) LDLT factorization of an Eigen::Matrix along with p...
Definition: LDLT_alloc.hpp:20
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:31
mdivide_left_ldlt_alloc< R1, C1, R2, C2 > * _alloc
Eigen::VectorXd vectorD() const
The entries of the diagonal matrix D.
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:87
bool success() const
Determine whether the most recent factorization succeeded.
Definition: LDLT_factor.hpp:96
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.

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