Automatic Differentiation
 
Loading...
Searching...
No Matches
eigenvalues.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_EIGENVALUES_HPP
2#define STAN_MATH_PRIM_FUN_EIGENVALUES_HPP
3
6
7namespace stan {
8namespace math {
9
18template <typename EigMat, require_eigen_matrix_dynamic_t<EigMat>* = nullptr,
19 require_not_vt_complex<EigMat>* = nullptr>
20inline Eigen::Matrix<complex_return_t<value_type_t<EigMat>>, -1, 1> eigenvalues(
21 EigMat&& m) {
22 if (unlikely(m.size() == 0)) {
23 return Eigen::Matrix<complex_return_t<value_type_t<EigMat>>, -1, 1>(0, 1);
24 }
25 check_square("eigenvalues", "m", m);
26 using PlainMat = plain_type_t<EigMat>;
27 decltype(auto) m_ref = to_ref(std::forward<EigMat>(m));
28
29 Eigen::EigenSolver<PlainMat> solver(m_ref, false);
30 return solver.eigenvalues();
31}
32
41template <typename EigCplxMat,
43inline Eigen::Matrix<complex_return_t<value_type_t<EigCplxMat>>, -1, 1>
44eigenvalues(EigCplxMat&& m) {
45 if (unlikely(m.size() == 0)) {
46 return Eigen::Matrix<complex_return_t<value_type_t<EigCplxMat>>, -1, 1>(0,
47 1);
48 }
49 check_square("eigenvalues", "m", m);
50 decltype(auto) m_ref = to_ref(std::forward<EigCplxMat>(m));
51 using PlainMat = Eigen::Matrix<scalar_type_t<EigCplxMat>, -1, -1>;
52 Eigen::ComplexEigenSolver<PlainMat> solver(m_ref, false);
53
54 return solver.eigenvalues();
55}
56
57} // namespace math
58} // namespace stan
59#endif
#define unlikely(x)
require_t< container_type_check_base< is_eigen_matrix_dynamic, value_type_t, TypeCheck, Check... > > require_eigen_matrix_dynamic_vt
Require type satisfies is_eigen_matrix_dynamic.
Eigen::Matrix< complex_return_t< value_type_t< EigMat > >, -1, 1 > eigenvalues(EigMat &&m)
Return the eigenvalues of a (real-valued) matrix.
void check_square(const char *function, const char *name, const T_y &y)
Check if the specified matrix is square.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:18
typename plain_type< std::decay_t< T > >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...