template<typename Scalar, int SelectionRule, typename OpType, typename BOpType>
class Spectra::SymGEigsSolver< Scalar, SelectionRule, OpType, BOpType, GEIGS_CHOLESKY >
This class implements the generalized eigen solver for real symmetric matrices using Cholesky decomposition, i.e., to solve where is symmetric and is positive definite with the Cholesky decomposition .
This solver requires two matrix operation objects: one for that implements the matrix multiplication , and one for that implements the lower and upper triangular solving and .
If and are stored as Eigen matrices, then the first operation can be created using the DenseSymMatProd or SparseSymMatProd classes, and the second operation can be created using the DenseCholesky or SparseCholesky classes. If the users need to define their own operation classes, then they should implement all the public member functions as in those built-in classes.
- Template Parameters
-
Scalar | The element type of the matrix. Currently supported types are float , double and long double . |
SelectionRule | An enumeration value indicating the selection rule of the requested eigenvalues, for example LARGEST_MAGN to retrieve eigenvalues with the largest magnitude. The full list of enumeration values can be found in Enumerations. |
OpType | The name of the matrix operation class for . Users could either use the wrapper classes such as DenseSymMatProd and SparseSymMatProd, or define their own that implements all the public member functions as in DenseSymMatProd. |
BOpType | The name of the matrix operation class for . Users could either use the wrapper classes such as DenseCholesky and SparseCholesky, or define their own that implements all the public member functions as in DenseCholesky. |
GEigsMode | Mode of the generalized eigen solver. In this solver it is Spectra::GEIGS_CHOLESKY. |
Below is an example that demonstrates the usage of this class.
#include <Eigen/Core>
#include <Eigen/SparseCore>
#include <Eigen/Eigenvalues>
#include <iostream>
{
const int n = 100;
Eigen::MatrixXd M = Eigen::MatrixXd::Random(n, n);
Eigen::MatrixXd A = M + M.transpose();
B.reserve(Eigen::VectorXi::Constant(n, 3));
for(
int i = 0;
i <
n;
i++)
{
B.insert(
i - 1,
i) = 1.0;
B.insert(
i + 1,
i) = 1.0;
}
geigs(&op, &Bop, 3, 6);
geigs.init();
int nconv = geigs.compute();
Eigen::VectorXd evalues;
Eigen::MatrixXd evecs;
{
evalues = geigs.eigenvalues();
evecs = geigs.eigenvectors();
}
std::cout << "Generalized eigenvalues found:\n" << evalues << std::endl;
std::cout << "Generalized eigenvectors found:\n" << evecs.topRows(10) << std::endl;
Eigen::MatrixXd Bdense =
B;
std::cout <<
"Generalized eigenvalues:\n" <<
es.eigenvalues().tail(3) << std::endl;
std::cout <<
"Generalized eigenvectors:\n" <<
es.eigenvectors().rightCols(3).topRows(10) << std::endl;
return 0;
}
Definition at line 164 of file SymGEigsSolver.h.