Stan Math Library: stan/math/prim/mat/fun/log_determinant_spd.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/mat/err/check_square.hpp>
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
stan
Definition: log_sum_exp.hpp:8
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
Eigen.hpp
stan::math::check_square
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.
Definition: check_square.hpp:28
stan::math::log_determinant_spd
T log_determinant_spd(const Eigen::Matrix< T, R, C > &m)
Returns the log absolute determinant of the specified square matrix.
Definition: log_determinant_spd.hpp:19
check_square.hpp

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