numerics 0.1.0
Loading...
Searching...
No Matches
jacobi_eig.cpp
Go to the documentation of this file.
1/// @file linalg/eigen/backends/lapack/jacobi_eig.cpp
2/// @brief LAPACK symmetric eigensolver via LAPACKE_dsyevd (divide-and-conquer).
3#include "impl.hpp"
4#include "../seq/impl.hpp"
5#include <stdexcept>
6#include <string>
7
8#if defined(NUMERICS_HAS_LAPACK)
9 #include <lapacke.h>
10#endif
11
12namespace num::backends::lapack {
13
15#if defined(NUMERICS_HAS_LAPACK)
16 if (A.rows() != A.cols())
17 throw std::invalid_argument("eig_sym: matrix must be square");
18 idx n = A.rows();
19 Matrix Aw = A; // dsyevd overwrites A with eigenvectors
20 Vector w(n);
21 int info = LAPACKE_dsyevd(LAPACK_ROW_MAJOR,
22 'V',
23 'U',
24 static_cast<lapack_int>(n),
25 Aw.data(),
26 static_cast<lapack_int>(n),
27 w.data());
28 if (info != 0)
29 throw std::runtime_error("eig_sym (lapack): dsyevd failed, info="
30 + std::to_string(info));
31 // dsyevd returns eigenvalues ascending; eigenvectors in columns of Aw
32 return {w, Aw, 0, true};
33#else
34 return seq::eig_sym(A, 1e-12, 100);
35#endif
36}
37
38} // namespace num::backends::lapack
Dense row-major matrix with optional GPU storage.
Definition matrix.hpp:12
real * data()
Definition matrix.hpp:28
constexpr idx rows() const noexcept
Definition matrix.hpp:24
constexpr idx cols() const noexcept
Definition matrix.hpp:25
EigenResult eig_sym(const Matrix &A)
EigenResult eig_sym(const Matrix &A, real tol, idx max_sweeps)
std::size_t idx
Definition types.hpp:11
constexpr real e
Definition math.hpp:43
std::experimental::simd butterfly for FFT.
Full eigendecomposition result: A = V * diag(values) * V^T.