Public Member Functions | Private Types | List of all members
Spectra::GenEigsSolver< Scalar, SelectionRule, OpType > Class Template Reference

#include <GenEigsSolver.h>

Inheritance diagram for Spectra::GenEigsSolver< Scalar, SelectionRule, OpType >:
Inheritance graph
[legend]

Public Member Functions

 GenEigsSolver (OpType *op, Index nev, Index ncv)
 
- Public Member Functions inherited from Spectra::GenEigsBase< double, LARGEST_MAGN, DenseGenMatProd< double >, IdentityBOp >
Index compute (Index maxit=1000, double tol=1e-10, int sort_rule=LARGEST_MAGN)
 
ComplexVector eigenvalues () const
 
ComplexMatrix eigenvectors () const
 
ComplexMatrix eigenvectors (Index nvec) const
 
int info () const
 
void init ()
 
void init (const double *init_resid)
 
Index num_iterations () const
 
Index num_operations () const
 

Private Types

typedef Eigen::Index Index
 

Additional Inherited Members

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

Detailed Description

template<typename Scalar = double, int SelectionRule = LARGEST_MAGN, typename OpType = DenseGenMatProd<double>>
class Spectra::GenEigsSolver< Scalar, SelectionRule, OpType >

This class implements the eigen solver for general real matrices, i.e., to solve $Ax=\lambda x$ for a possibly non-symmetric $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
ScalarThe element type of the matrix. Currently supported types are float, double and long double.
SelectionRuleAn 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.
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 all the public member functions as in DenseGenMatProd.

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

#include <Eigen/Core>
// <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();
// Retrieve results
Eigen::VectorXcd evalues;
if(eigs.info() == 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 <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;
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();
// Retrieve results
Eigen::VectorXcd evalues;
if(eigs.info() == SUCCESSFUL)
evalues = eigs.eigenvalues();
std::cout << "Eigenvalues found:\n" << evalues << std::endl;
return 0;
}

Definition at line 128 of file GenEigsSolver.h.

Member Typedef Documentation

◆ Index

template<typename Scalar = double, int SelectionRule = LARGEST_MAGN, typename OpType = DenseGenMatProd<double>>
typedef Eigen::Index Spectra::GenEigsSolver< Scalar, SelectionRule, OpType >::Index
private

Definition at line 131 of file GenEigsSolver.h.

Constructor & Destructor Documentation

◆ GenEigsSolver()

template<typename Scalar = double, int SelectionRule = LARGEST_MAGN, typename OpType = DenseGenMatProd<double>>
Spectra::GenEigsSolver< Scalar, SelectionRule, OpType >::GenEigsSolver ( OpType *  op,
Index  nev,
Index  ncv 
)
inline

Constructor to create a solver object.

Parameters
opPointer to the matrix operation object, which should implement 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 member functions 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$.

Definition at line 151 of file GenEigsSolver.h.


The documentation for this class was generated from the following file:
Eigen::SparseMatrix< double >
SparseGenMatProd.h
main
int main(int argc, char **argv)
Definition: cmake/example_cmake_find_gtsam/main.cpp:63
n
int n
Definition: BiCGSTAB_simple.cpp:1
GenEigsSolver.h
Spectra::GenEigsSolver
Definition: GenEigsSolver.h:128
Spectra::SparseGenMatProd
Definition: SparseGenMatProd.h:24
Spectra
Definition: LOBPCGSolver.h:19
Spectra::SUCCESSFUL
@ SUCCESSFUL
Computation was successful.
Definition: CompInfo.h:19
Spectra::DenseGenMatProd< double >
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
M
Matrix< RealScalar, Dynamic, Dynamic > M
Definition: bench_gemm.cpp:51


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:16:52