Stan Math Library  2.20.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/meta.hpp>
5 #include <stan/math/rev/core.hpp>
9 
10 namespace stan {
11 namespace math {
12 
46 template <int R, int C>
47 class LDLT_factor<var, R, C> {
48  public:
54  LDLT_factor() : alloc_(new LDLT_alloc<R, C>()) {}
55 
56  explicit LDLT_factor(const Eigen::Matrix<var, R, C> &A)
57  : alloc_(new LDLT_alloc<R, C>()) {
58  compute(A);
59  }
60 
69  inline void compute(const Eigen::Matrix<var, R, C> &A) {
70  check_square("comute", "A", A);
71  alloc_->compute(A);
72  }
73 
85 #if EIGEN_VERSION_AT_LEAST(3, 3, 0)
86  template <typename Rhs>
87  inline const Eigen::Solve<Eigen::LDLT<Eigen::Matrix<double, R, C> >, Rhs>
88  solve(const Eigen::MatrixBase<Rhs> &b) const {
89  return alloc_->ldlt_.solve(b);
90  }
91 #else
92  template <typename Rhs>
93  inline const Eigen::internal::solve_retval<
94  Eigen::LDLT<Eigen::Matrix<double, R, C> >, Rhs>
95  solve(const Eigen::MatrixBase<Rhs> &b) const {
96  return alloc_->ldlt_.solve(b);
97  }
98 #endif
99 
105  inline bool success() const {
106  bool ret;
107  ret = alloc_->N_ != 0;
108  ret = ret && alloc_->ldlt_.info() == Eigen::Success;
109  ret = ret && alloc_->ldlt_.isPositive();
110  ret = ret && (alloc_->ldlt_.vectorD().array() > 0).all();
111  return ret;
112  }
113 
121  inline Eigen::VectorXd vectorD() const { return alloc_->ldlt_.vectorD(); }
122 
123  inline size_t rows() const { return alloc_->N_; }
124  inline size_t cols() const { return alloc_->N_; }
125 
126  typedef size_t size_type;
127  typedef var value_type;
128 
138 };
139 
140 } // namespace math
141 } // namespace stan
142 #endif
LDLT_factor(const Eigen::Matrix< var, R, C > &A)
Definition: LDLT_factor.hpp:56
void compute(const Eigen::Matrix< var, R, C > &A)
Use the LDLT_factor object to factorize a new matrix.
Definition: LDLT_factor.hpp:69
void check_square(const char *function, const char *name, const matrix_cl &y)
Check if the matrix_cl is square.
This object stores the actual (double typed) LDLT factorization of an Eigen::Matrix<var> along with p...
Definition: LDLT_alloc.hpp:21
const Eigen::internal::solve_retval< ldlt_t, Rhs > solve(const Eigen::MatrixBase< Rhs > &b) const
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:33
void compute(const matrix_t &A)
Definition: LDLT_factor.hpp:77
bool success() const
Determine whether the most recent factorization succeeded.
LDLT_factor is a thin wrapper on Eigen::LDLT to allow for reusing factorizations and efficient autodi...
Definition: LDLT_factor.hpp:63
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:95
LDLT_alloc< R, C > * alloc_
The LDLT_alloc object actually contains the factorization but is derived from the chainable_alloc cla...
Eigen::VectorXd vectorD() const
The entries of the diagonal matrix D.
LDLT_factor()
Default constructor.
Definition: LDLT_factor.hpp:54

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