Stan Math Library  2.10.0
reverse mode automatic differentiation
log_determinant_spd.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_LOG_DETERMINANT_SPD_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_LOG_DETERMINANT_SPD_HPP
3 
6 #include <cmath>
7 
8 namespace stan {
9  namespace math {
10 
18  template <typename T, int R, int C>
19  inline T log_determinant_spd(const Eigen::Matrix<T, R, C>& m) {
20  using std::log;
21  stan::math::check_square("log_determinant_spd", "m", m);
22  // Eigen::TriangularView< Eigen::Matrix<T, R, C>, Eigen::Lower >
23  // L(m.llt().matrixL());
24  // T ret(0.0);
25  // for (size_t i = 0; i < L.rows(); i++)
26  // ret += log(L(i, i));
27  // return 2*ret;
28  return m.ldlt().vectorD().array().log().sum();
29  }
30 
31  }
32 }
33 #endif
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
bool check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is square.
T log_determinant_spd(const Eigen::Matrix< T, R, C > &m)
Returns the log absolute determinant of the specified square matrix.

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