Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LDLT_alloc.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__MATRIX__LDLT_ALLOC_HPP
2 #define STAN__AGRAD__REV__MATRIX__LDLT_ALLOC_HPP
3 
5 #include <stan/agrad/rev/var.hpp>
6 
7 namespace stan {
8  namespace agrad {
19  template<int R, int C>
20  class LDLT_alloc : public chainable_alloc {
21  public:
22  LDLT_alloc() : N_(0) {}
23  LDLT_alloc(const Eigen::Matrix<var,R,C> &A) : N_(0) {
24  compute(A);
25  }
26 
32  inline void compute(const Eigen::Matrix<var,R,C> &A) {
33  Eigen::Matrix<double,R,C> Ad(A.rows(),A.cols());
34 
35  N_ = A.rows();
36  _variA.resize(A.rows(),A.cols());
37 
38  for (size_t j = 0; j < N_; j++) {
39  for (size_t i = 0; i < N_; i++) {
40  Ad(i,j) = A(i,j).val();
41  _variA(i,j) = A(i,j).vi_;
42  }
43  }
44 
45  _ldlt.compute(Ad);
46  }
47 
49  inline double log_abs_det() const {
50  return _ldlt.vectorD().array().log().sum();
51  }
52 
53  size_t N_;
54  Eigen::LDLT<Eigen::Matrix<double,R,C> > _ldlt;
55  Eigen::Matrix<vari*,R,C> _variA;
56  };
57  }
58 }
59 #endif
double log_abs_det() const
Compute the log(abs(det(A))). This is just a convenience function.
Definition: LDLT_alloc.hpp:49
This object stores the actual (double typed) LDLT factorization of an Eigen::Matrix<var> along with poi...
Definition: LDLT_alloc.hpp:20
Eigen::Matrix< vari *, R, C > _variA
Definition: LDLT_alloc.hpp:55
LDLT_alloc(const Eigen::Matrix< var, R, C > &A)
Definition: LDLT_alloc.hpp:23
A chainable_alloc is an object which is constructed and destructed normally but the memory lifespan i...
Definition: var_stack.hpp:31
void compute(const Eigen::Matrix< var, R, C > &A)
Compute the LDLT factorization and store pointers to the vari's of the matrix entries to be used when...
Definition: LDLT_alloc.hpp:32
Eigen::LDLT< Eigen::Matrix< double, R, C > > _ldlt
Definition: LDLT_alloc.hpp:54

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