Stan Math Library  2.15.0
reverse mode automatic differentiation
log_determinant_ldlt.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_MAT_FUN_LOG_DETERMINANT_LDLT_HPP
2 #define STAN_MATH_REV_MAT_FUN_LOG_DETERMINANT_LDLT_HPP
3 
5 #include <stan/math/rev/core.hpp>
8 
9 namespace stan {
10  namespace math {
11  namespace {
12 
22  template<int R, int C>
23  class log_det_ldlt_vari : public vari {
24  public:
25  explicit log_det_ldlt_vari(const 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 }
54 #endif
A template specialization of src/stan/math/matrix/LDLT_factor.hpp for var which can be used with all ...
Definition: LDLT_factor.hpp:46
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:30
mdivide_left_ldlt_alloc< R1, C1, R2, C2 > * alloc_
const LDLT_alloc< R, C > * alloc_ldlt_
T log_determinant_ldlt(LDLT_factor< T, R, C > &A)

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