Spectra::GenEigsSolver< OpType > Class Template Reference

Description

template<typename OpType = DenseGenMatProd<double>>
class Spectra::GenEigsSolver< OpType >

This class implements the eigen solver for general matrices, i.e., to solve \(Ax=\lambda x\) for a possibly non-symmetric (for real-valued matrices) or non-Hermitian (for complex-valued matrices) \(A\) matrix.

Most of the background information documented in the SymEigsSolver class also applies to the GenEigsSolver class here, except that the eigenvalues and eigenvectors of a general matrix can now be complex-valued.

Template Parameters
OpTypeThe name of the matrix operation class. Users could either use the wrapper classes such as DenseGenMatProd and SparseGenMatProd, or define their own that implements the type definition Scalar and all the public member functions as in DenseGenMatProd.

An example that illustrates the usage of GenEigsSolver is give below:

#include <Eigen/Core>
#include <Spectra/GenEigsSolver.h>
// <Spectra/MatOp/DenseGenMatProd.h> is implicitly included
#include <iostream>
using namespace Spectra;
int main()
{
// We are going to calculate the eigenvalues of M
Eigen::MatrixXd M = Eigen::MatrixXd::Random(10, 10);
// Construct matrix operation object using the wrapper class
// Construct eigen solver object, requesting the largest
// (in magnitude, or norm) three eigenvalues
// Initialize and compute
eigs.init();
int nconv = eigs.compute(SortRule::LargestMagn);
// Retrieve results
Eigen::VectorXcd evalues;
if (eigs.info() == CompInfo::Successful)
evalues = eigs.eigenvalues();
std::cout << "Eigenvalues found:\n" << evalues << std::endl;
return 0;
}

And also an example for sparse matrices:

#include <Eigen/Core>
#include <Eigen/SparseCore>
#include <Spectra/GenEigsSolver.h>
#include <Spectra/MatOp/SparseGenMatProd.h>
#include <iostream>
using namespace Spectra;
int main()
{
// A band matrix with 1 on the main diagonal, 2 on the below-main subdiagonal,
// and 3 on the above-main subdiagonal
const int n = 10;
Eigen::SparseMatrix<double> M(n, n);
M.reserve(Eigen::VectorXi::Constant(n, 3));
for (int i = 0; i < n; i++)
{
M.insert(i, i) = 1.0;
if (i > 0)
M.insert(i - 1, i) = 3.0;
if (i < n - 1)
M.insert(i + 1, i) = 2.0;
}
// Construct matrix operation object using the wrapper class SparseGenMatProd
// Construct eigen solver object, requesting the largest three eigenvalues
// Initialize and compute
eigs.init();
int nconv = eigs.compute(SortRule::LargestMagn);
// Retrieve results
Eigen::VectorXcd evalues;
if (eigs.info() == CompInfo::Successful)
evalues = eigs.eigenvalues();
std::cout << "Eigenvalues found:\n" << evalues << std::endl;
return 0;
}

GenEigsSolver also supports complex-valued matrices:

#include <Eigen/Core>
#include <Spectra/GenEigsSolver.h>
// <Spectra/MatOp/DenseGenMatProd.h> is implicitly included
#include <iostream>
using namespace Spectra;
int main()
{
// We are going to calculate the eigenvalues of M
Eigen::MatrixXcd M = Eigen::MatrixXcd::Random(10, 10);
// Construct matrix operation object using the wrapper class
OpType op(M);
// Construct eigen solver object, requesting the largest
// (in magnitude, or norm) three eigenvalues
GenEigsSolver<OpType> eigs(op, 3, 6);
// Initialize and compute
eigs.init();
int nconv = eigs.compute(SortRule::LargestMagn);
// Retrieve results
Eigen::VectorXcd evalues;
if (eigs.info() == CompInfo::Successful)
evalues = eigs.eigenvalues();
std::cout << "Eigenvalues found:\n" << evalues << std::endl;
return 0;
}

#include <GenEigsSolver.h>

Inheritance diagram for Spectra::GenEigsSolver< OpType >:
Collaboration diagram for Spectra::GenEigsSolver< OpType >:

Public Member Functions

 GenEigsSolver (OpType &op, Index nev, Index ncv)
 Constructor to create a solver object. More...
 
- Public Member Functions inherited from Spectra::GenEigsBase< DenseGenMatProd< double >, IdentityBOp >
void init (const Scalar *init_resid)
 Initializes the solver by providing an initial residual vector. More...
 
void init ()
 Initializes the solver by providing a random initial residual vector. More...
 
Index compute (SortRule selection=SortRule::LargestMagn, Index maxit=1000, RealScalar tol=1e-10, SortRule sorting=SortRule::LargestMagn)
 Conducts the major computation procedure. More...
 
CompInfo info () const
 Returns the status of the computation. More...
 
Index num_iterations () const
 Returns the number of iterations used in the computation.
 
Index num_operations () const
 Returns the number of matrix operations used in the computation.
 
ComplexVector eigenvalues () const
 Returns the converged eigenvalues. More...
 
ComplexMatrix eigenvectors (Index nvec) const
 Returns the eigenvectors associated with the converged eigenvalues. More...
 
ComplexMatrix eigenvectors () const
 Returns all converged eigenvectors.
 

Additional Inherited Members

- Protected Member Functions inherited from Spectra::GenEigsBase< DenseGenMatProd< double >, IdentityBOp >
virtual void sort_ritzpair (SortRule sort_rule)
 
- Protected Attributes inherited from Spectra::GenEigsBase< DenseGenMatProd< double >, IdentityBOp >
DenseGenMatProd< double > & m_op
 
const Index m_n
 
const Index m_nev
 
const Index m_ncv
 
Index m_nmatop
 
Index m_niter
 
ArnoldiFac m_fac
 
ComplexVector m_ritz_val
 
ComplexMatrix m_ritz_vec
 
ComplexVector m_ritz_est
 

Constructor & Destructor Documentation

◆ GenEigsSolver()

template<typename OpType = DenseGenMatProd<double>>
Spectra::GenEigsSolver< OpType >::GenEigsSolver ( OpType &  op,
Index  nev,
Index  ncv 
)
inline

Constructor to create a solver object.

Parameters
opThe matrix operation object that implements the matrix-vector multiplication operation of \(A\): calculating \(Av\) for any vector \(v\). Users could either create the object from the wrapper class such as DenseGenMatProd, or define their own that implements all the public members as in DenseGenMatProd.
nevNumber of eigenvalues requested. This should satisfy \(1\le nev \le n-2\), where \(n\) is the size of matrix.
ncvParameter that controls the convergence speed of the algorithm. Typically a larger ncv means faster convergence, but it may also result in greater memory use and more matrix operations in each iteration. This parameter must satisfy \(nev+2 \le ncv \le n\), and is advised to take \(ncv \ge 2\cdot nev + 1\).

The documentation for this class was generated from the following file:
  • /builds/uwsbel/chrono/src/chrono_thirdparty/spectra/Spectra/GenEigsSolver.h
@ Successful
Computation was successful.
Definition: SparseGenMatProd.h:30
Definition: GenEigsSolver.h:159
@ LargestMagn
Select eigenvalues with largest magnitude.