1 #ifndef STAN_MATH_PRIM_FUN_LOG_DETERMINANT_HPP
2 #define STAN_MATH_PRIM_FUN_LOG_DETERMINANT_HPP
3 
4 #include <stan/math/prim/meta.hpp>
5 #include <stan/math/prim/err.hpp>
6 #include <stan/math/prim/fun/Eigen.hpp>
7 
8 namespace stan {
9 namespace math {
10 
11 /**
12  * Returns the log absolute determinant of the specified square matrix.
13  *
14  * @tparam EigMat type of the matrix
15  *
16  * @param m Specified matrix.
17  * @return log absolute determinant of the matrix.
18  * @throw std::domain_error if matrix is not square.
19  */
20 template <typename EigMat,
21           require_eigen_vt<std::is_arithmetic, EigMat>* = nullptr>
log_determinant(const EigMat & m)22 inline value_type_t<EigMat> log_determinant(const EigMat& m) {
23   if (m.size() == 0) {
24     return 0;
25   }
26   check_square("log_determinant", "m", m);
27   return m.colPivHouseholderQr().logAbsDeterminant();
28 }
29 
30 }  // namespace math
31 }  // namespace stan
32 
33 #endif
34