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(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 decltype(auto) m_ref = to_ref(std::forward<EigMat>(m));
32 check_symmetric("eigendecompose_sym", "m", m_ref);
33
34 Eigen::SelfAdjointEigenSolver<PlainMat> solver(
35 std::forward<decltype(m_ref)>(m_ref));
36 return std::make_tuple(std::move(solver.eigenvectors()),
37 std::move(solver.eigenvalues()));
38}
39
40} // namespace math
41} // namespace stan
42#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(EigMat &&m)
Return the eigendecomposition of the specified symmetric 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 ...