Automatic Differentiation
 
Loading...
Searching...
No Matches
determinant.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_DETERMINANT_HPP
2#define STAN_MATH_FWD_FUN_DETERMINANT_HPP
3
9
10namespace stan {
11namespace math {
12
13template <typename EigMat, require_eigen_vt<is_fvar, EigMat>* = nullptr>
14inline value_type_t<EigMat> determinant(const EigMat& m) {
15 check_square("determinant", "m", m);
16 const auto& m_ref = to_ref(m);
17
18 const typename value_type_t<EigMat>::Scalar vals = m_ref.val().determinant();
19 return {vals, vals * (m_ref.val().inverse() * m_ref.d()).trace()};
20}
21
22} // namespace math
23} // namespace stan
24#endif
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
void check_square(const char *function, const char *name, const T_y &y)
Check if the specified matrix is square.
value_type_t< EigMat > determinant(const EigMat &m)
value_type_t< T > trace(const T &m)
Calculates trace (sum of diagonal) of given kernel generator expression.
Definition trace.hpp:22
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...