Automatic Differentiation
 
Loading...
Searching...
No Matches
eigendecompose_sym.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_EIGENDECOMPOSE_SYM_HPP
2#define STAN_MATH_PRIM_FUN_EIGENDECOMPOSE_SYM_HPP
3
7
8namespace stan {
9namespace math {
10
21template <typename EigMat, require_eigen_t<EigMat>* = nullptr,
22 require_not_st_var<EigMat>* = nullptr>
23std::tuple<Eigen::Matrix<value_type_t<EigMat>, -1, -1>,
24 Eigen::Matrix<value_type_t<EigMat>, -1, 1>>
25eigendecompose_sym(const EigMat& m) {
26 if (unlikely(m.size() == 0)) {
27 return std::make_tuple(Eigen::Matrix<value_type_t<EigMat>, -1, -1>(0, 0),
28 Eigen::Matrix<value_type_t<EigMat>, -1, 1>(0, 1));
29 }
30 using PlainMat = plain_type_t<EigMat>;
31 const PlainMat& m_eval = m;
32 check_symmetric("eigendecompose_sym", "m", m_eval);
33
34 Eigen::SelfAdjointEigenSolver<PlainMat> solver(m_eval);
35 return std::make_tuple(std::move(solver.eigenvectors()),
36 std::move(solver.eigenvalues()));
37}
38
39} // namespace math
40} // namespace stan
41#endif
#define unlikely(x)
void check_symmetric(const char *function, const char *name, const matrix_cl< T > &y)
Check if the matrix_cl is symmetric.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
std::tuple< Eigen::Matrix< value_type_t< EigMat >, -1, -1 >, Eigen::Matrix< value_type_t< EigMat >, -1, 1 > > eigendecompose_sym(const EigMat &m)
Return the eigendecomposition of the specified symmetric matrix.
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...