Stan Math Library  2.15.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 {
11 
45  template <int R, int C>
46  class LDLT_factor<var, R, C> {
47  public:
53  LDLT_factor() : alloc_(new LDLT_alloc<R, C>()) {}
54 
55  explicit LDLT_factor(const Eigen::Matrix<var, R, C> &A)
56  : alloc_(new LDLT_alloc<R, C>()) {
57  compute(A);
58  }
59 
68  inline void compute(const Eigen::Matrix<var, R, C> &A) {
69  check_square("comute", "A", A);
70  alloc_->compute(A);
71  }
72 
84 #if EIGEN_VERSION_AT_LEAST(3, 3, 0)
85  template <typename Rhs>
86  inline const
87  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
94  Eigen::internal::solve_retval<Eigen::LDLT<Eigen::Matrix<double, R, C> >,
95  Rhs>
96  solve(const Eigen::MatrixBase<Rhs>& b) const {
97  return alloc_->ldlt_.solve(b);
98  }
99 #endif
100 
106  inline bool success() const {
107  bool ret;
108  ret = alloc_->N_ != 0;
109  ret = ret && alloc_->ldlt_.info() == Eigen::Success;
110  ret = ret && alloc_->ldlt_.isPositive();
111  ret = ret && (alloc_->ldlt_.vectorD().array() > 0).all();
112  return ret;
113  }
114 
122  inline Eigen::VectorXd vectorD() const {
123  return alloc_->ldlt_.vectorD();
124  }
125 
126  inline size_t rows() const { return alloc_->N_; }
127  inline size_t cols() const { return alloc_->N_; }
128 
129  typedef size_t size_type;
130  typedef var value_type;
131 
141  };
142 
143  }
144 }
145 #endif
LDLT_factor(const Eigen::Matrix< var, R, C > &A)
Definition: LDLT_factor.hpp:55
void compute(const Eigen::Matrix< var, R, C > &A)
Use the LDLT_factor object to factorize a new matrix.
Definition: LDLT_factor.hpp:68
This object stores the actual (double typed) LDLT factorization of an Eigen::Matrix<var> along with p...
Definition: LDLT_alloc.hpp:20
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:30
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
mdivide_left_ldlt_alloc< R1, C1, R2, C2 > * alloc_
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.
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:96
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:53

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