7 #ifndef TRIDIAG_EIGEN_H
8 #define TRIDIAG_EIGEN_H
12 #include "LapackWrapperExtra.h"
24 template <
typename Scalar =
double>
28 typedef arma::Mat<Scalar> Matrix;
29 typedef arma::Col<Scalar> Vector;
57 n(mat.n_rows), computed(false)
73 throw std::invalid_argument(
"TridiagEigen: matrix must be square");
76 main_diag = mat.diag();
77 sub_diag = mat.diag(-1);
88 arma::lapack::stedc(&compz, &n, main_diag.memptr(), sub_diag.memptr(),
89 evecs.memptr(), &n, &lwork_opt, &lwork, &liwork_opt, &liwork, &info);
93 lwork = (int) lwork_opt;
96 lwork = 1 + 4 * n + n * n;
100 Scalar *work =
new Scalar[lwork];
101 int *iwork =
new int[liwork];
103 arma::lapack::stedc(&compz, &n, main_diag.memptr(), sub_diag.memptr(),
104 evecs.memptr(), &n, work, &lwork, iwork, &liwork, &info);
110 throw std::invalid_argument(
"Lapack stedc: illegal value");
112 throw std::logic_error(
"Lapack stedc: failed to compute all the eigenvalues");
126 throw std::logic_error(
"TridiagEigen: need to call compute() first");
141 throw std::logic_error(
"TridiagEigen: need to call compute() first");
149 #endif // TRIDIAG_EIGEN_H
void compute(const Matrix &mat)
TridiagEigen(const Matrix &mat)