Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
log_determinant_ldlt.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__MATRIX__LOG_DETERMINANT_LDLT_HPP
2 #define STAN__AGRAD__REV__MATRIX__LOG_DETERMINANT_LDLT_HPP
3 
5 #include <stan/agrad/rev/var.hpp>
8 
9 namespace stan {
10  namespace agrad {
11  namespace {
12 
22  template<int R,int C>
23  class log_det_ldlt_vari : public vari {
24  public:
25  log_det_ldlt_vari(const stan::math::LDLT_factor<var,R,C> &A)
26  : vari(A._alloc->log_abs_det()), _alloc_ldlt(A._alloc)
27  { }
28 
29  virtual void chain() {
30  Eigen::Matrix<double,R,C> invA;
31 
32  // If we start computing Jacobians, this may be a bit inefficient
33  invA.setIdentity(_alloc_ldlt->N_, _alloc_ldlt->N_);
34  _alloc_ldlt->_ldlt.solveInPlace(invA);
35 
36  for (size_t j = 0; j < _alloc_ldlt->N_; j++) {
37  for (size_t i = 0; i < _alloc_ldlt->N_; i++) {
38  _alloc_ldlt->_variA(i,j)->adj_ += adj_ * invA(i,j);
39  }
40  }
41  }
42 
43  const LDLT_alloc<R,C> *_alloc_ldlt;
44  };
45  }
46 
47  template<int R, int C>
49  return var(new log_det_ldlt_vari<R,C>(A));
50  }
51  }
52 }
53 #endif
log_determinant_spd_alloc< R, C > * _alloc
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:27
var log_determinant_ldlt(stan::math::LDLT_factor< var, R, C > &A)
const LDLT_alloc< R, C > * _alloc_ldlt

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