Automatic Differentiation
 
Loading...
Searching...
No Matches
eigenvectors.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_EIGENVECTORS_HPP
2#define STAN_MATH_PRIM_FUN_EIGENVECTORS_HPP
3
6
7namespace stan {
8namespace math {
9
19template <typename EigMat, require_eigen_matrix_dynamic_t<EigMat>* = nullptr,
20 require_not_vt_complex<EigMat>* = nullptr>
21inline Eigen::Matrix<complex_return_t<value_type_t<EigMat>>, -1, -1>
22eigenvectors(EigMat&& m) {
23 if (unlikely(m.size() == 0)) {
24 return Eigen::Matrix<complex_return_t<value_type_t<EigMat>>, -1, -1>(0, 0);
25 }
26 check_square("eigenvectors", "m", m);
27 using PlainMat = plain_type_t<EigMat>;
28 decltype(auto) m_ref = to_ref(std::forward<EigMat>(m));
29
30 Eigen::EigenSolver<PlainMat> solver(m_ref);
31 return solver.eigenvectors();
32}
33
43template <typename EigCplxMat,
45inline Eigen::Matrix<complex_return_t<value_type_t<EigCplxMat>>, -1, -1>
46eigenvectors(EigCplxMat&& m) {
47 if (unlikely(m.size() == 0)) {
48 return Eigen::Matrix<complex_return_t<value_type_t<EigCplxMat>>, -1, -1>(0,
49 0);
50 }
51 check_square("eigenvectors", "m", m);
52 using PlainMat = Eigen::Matrix<scalar_type_t<EigCplxMat>, -1, -1>;
53 decltype(auto) m_ref = to_ref(std::forward<EigCplxMat>(m));
54 Eigen::ComplexEigenSolver<PlainMat> solver(
55 std::forward<decltype(m_ref)>(m_ref));
56 return solver.eigenvectors();
57}
58
59} // namespace math
60} // namespace stan
61#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.
void check_square(const char *function, const char *name, const T_y &y)
Check if the specified matrix is square.
Eigen::Matrix< complex_return_t< value_type_t< EigMat > >, -1, -1 > eigenvectors(EigMat &&m)
Return the eigenvectors of a (real-valued) matrix.
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 ...