All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
log_determinant_ldlt.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_REV_MAT_FUN_LOG_DETERMINANT_LDLT_HPP
#define STAN_MATH_REV_MAT_FUN_LOG_DETERMINANT_LDLT_HPP
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/rev/core.hpp>
#include <stan/math/rev/mat/fun/LDLT_alloc.hpp>
#include <stan/math/rev/mat/fun/LDLT_factor.hpp>
namespace stan {
namespace math {
namespace {
template<int R, int C>
class log_det_ldlt_vari : public vari {
public:
explicit log_det_ldlt_vari(const stan::math::LDLT_factor<var, R, C> &A)
: vari(A._alloc->log_abs_det()), _alloc_ldlt(A._alloc)
{ }
virtual void chain() {
Eigen::Matrix<double, R, C> invA;
// If we start computing Jacobians, this may be a bit inefficient
invA.setIdentity(_alloc_ldlt->N_, _alloc_ldlt->N_);
_alloc_ldlt->_ldlt.solveInPlace(invA);
for (size_t j = 0; j < _alloc_ldlt->N_; j++) {
for (size_t i = 0; i < _alloc_ldlt->N_; i++) {
_alloc_ldlt->_variA(i, j)->adj_ += adj_ * invA(i, j);
}
}
}
const LDLT_alloc<R, C> *_alloc_ldlt;
};
}
template<int R, int C>
var log_determinant_ldlt(stan::math::LDLT_factor<var, R, C> &A) {
return var(new log_det_ldlt_vari<R, C>(A));
}
}
}
#endif
core.hpp
LDLT_alloc.hpp
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
_alloc
mdivide_left_ldlt_alloc< R1, C1, R2, C2 > * _alloc
Definition: mdivide_left_ldlt.hpp:44
stan::math::LDLT_factor
Definition: LDLT_factor.hpp:18
LDLT_factor.hpp
Eigen.hpp
_alloc_ldlt
const LDLT_alloc< R, C > * _alloc_ldlt
Definition: log_determinant_ldlt.hpp:43
stan::math::log_determinant_ldlt
T log_determinant_ldlt(stan::math::LDLT_factor< T, R, C > &A)
Definition: log_determinant_ldlt.hpp:12

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