Eigen::SelfAdjointEigenSolver< MatrixType_ > Class Template Reference

Computes eigenvalues and eigenvectors of selfadjoint matrices. More...

#include <SelfAdjointEigenSolver.h>

+ Inheritance diagram for Eigen::SelfAdjointEigenSolver< MatrixType_ >:

Public Types

enum  { Size = MatrixType::RowsAtCompileTime , ColsAtCompileTime = MatrixType::ColsAtCompileTime , Options = internal::traits<MatrixType>::Options , MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime }
 
typedef MatrixType_ MatrixType
 
typedef MatrixType::Scalar Scalar
 Scalar type for matrices of type MatrixType_. More...
 
typedef Eigen::Index Index
 
typedef Matrix< Scalar, Size, Size, ColMajor, MaxColsAtCompileTime, MaxColsAtCompileTimeEigenvectorsType
 
typedef NumTraits< Scalar >::Real RealScalar
 Real scalar type for MatrixType_. More...
 
typedef internal::plain_col_type< MatrixType, Scalar >::type VectorType
 Type for vector of eigenvalues as returned by eigenvalues(). More...
 
typedef internal::plain_col_type< MatrixType, RealScalar >::type RealVectorType
 
typedef Tridiagonalization< MatrixTypeTridiagonalizationType
 
typedef TridiagonalizationType::SubDiagonalType SubDiagonalType
 

Public Member Functions

EIGEN_DEVICE_FUNC SelfAdjointEigenSolver ()
 Default constructor for fixed-size matrices. More...
 
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver (Index size)
 Constructor, pre-allocates memory for dynamic-size matrices. More...
 
template<typename InputType >
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver (const EigenBase< InputType > &matrix, int options=ComputeEigenvectors)
 Constructor; computes eigendecomposition of given matrix. More...
 
template<typename InputType >
EIGEN_DEVICE_FUNC SelfAdjointEigenSolvercompute (const EigenBase< InputType > &matrix, int options=ComputeEigenvectors)
 Computes eigendecomposition of given matrix. More...
 
EIGEN_DEVICE_FUNC SelfAdjointEigenSolvercomputeDirect (const MatrixType &matrix, int options=ComputeEigenvectors)
 Computes eigendecomposition of given matrix using a closed-form algorithm. More...
 
SelfAdjointEigenSolvercomputeFromTridiagonal (const RealVectorType &diag, const SubDiagonalType &subdiag, int options=ComputeEigenvectors)
 Computes the eigen decomposition from a tridiagonal symmetric matrix. More...
 
EIGEN_DEVICE_FUNC const EigenvectorsTypeeigenvectors () const
 Returns the eigenvectors of given matrix. More...
 
EIGEN_DEVICE_FUNC const RealVectorTypeeigenvalues () const
 Returns the eigenvalues of given matrix. More...
 
EIGEN_DEVICE_FUNC MatrixType operatorSqrt () const
 Computes the positive-definite square root of the matrix. More...
 
EIGEN_DEVICE_FUNC MatrixType operatorInverseSqrt () const
 Computes the inverse square root of the matrix. More...
 
EIGEN_DEVICE_FUNC ComputationInfo info () const
 Reports whether previous computation was successful. More...
 
template<typename InputType >
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver< MatrixType > & compute (const EigenBase< InputType > &a_matrix, int options)
 

Static Public Attributes

static const int m_maxIterations = 30
 Maximum number of iterations. More...
 

Protected Attributes

EigenvectorsType m_eivec
 
VectorType m_workspace
 
RealVectorType m_eivalues
 
TridiagonalizationType::SubDiagonalType m_subdiag
 
TridiagonalizationType::CoeffVectorType m_hcoeffs
 
ComputationInfo m_info
 
bool m_isInitialized
 
bool m_eigenvectorsOk
 

Friends

struct internal::direct_selfadjoint_eigenvalues< SelfAdjointEigenSolver, Size, NumTraits< Scalar >::IsComplex >
 

Detailed Description

template<typename MatrixType_>
class Eigen::SelfAdjointEigenSolver< MatrixType_ >

Computes eigenvalues and eigenvectors of selfadjoint matrices.

\eigenvalues_module

Template Parameters
MatrixType_the type of the matrix of which we are computing the eigendecomposition; this is expected to be an instantiation of the Matrix class template.

A matrix \( A \) is selfadjoint if it equals its adjoint. For real matrices, this means that the matrix is symmetric: it equals its transpose. This class computes the eigenvalues and eigenvectors of a selfadjoint matrix. These are the scalars \( \lambda \) and vectors \( v \) such that \( Av = \lambda v \). The eigenvalues of a selfadjoint matrix are always real. If \( D \) is a diagonal matrix with the eigenvalues on the diagonal, and \( V \) is a matrix with the eigenvectors as its columns, then \( A = V D V^{-1} \). This is called the eigendecomposition.

For a selfadjoint matrix, \( V \) is unitary, meaning its inverse is equal to its adjoint, \( V^{-1} = V^{\dagger} \). If \( A \) is real, then \( V \) is also real and therefore orthogonal, meaning its inverse is equal to its transpose, \( V^{-1} = V^T \).

The algorithm exploits the fact that the matrix is selfadjoint, making it faster and more accurate than the general purpose eigenvalue algorithms implemented in EigenSolver and ComplexEigenSolver.

Only the lower triangular part of the input matrix is referenced.

Call the function compute() to compute the eigenvalues and eigenvectors of a given matrix. Alternatively, you can use the SelfAdjointEigenSolver(const MatrixType&, int) constructor which computes the eigenvalues and eigenvectors at construction time. Once the eigenvalue and eigenvectors are computed, they can be retrieved with the eigenvalues() and eigenvectors() functions.

The documentation for SelfAdjointEigenSolver(const MatrixType&, int) contains an example of the typical use of this class.

To solve the generalized eigenvalue problem \( Av = \lambda Bv \) and the likes, see the class GeneralizedSelfAdjointEigenSolver.

See also
MatrixBase::eigenvalues(), class EigenSolver, class ComplexEigenSolver

Member Typedef Documentation

◆ EigenvectorsType

◆ Index

template<typename MatrixType_ >
typedef Eigen::Index Eigen::SelfAdjointEigenSolver< MatrixType_ >::Index
Deprecated:
since Eigen 3.3

◆ MatrixType

template<typename MatrixType_ >
typedef MatrixType_ Eigen::SelfAdjointEigenSolver< MatrixType_ >::MatrixType

◆ RealScalar

template<typename MatrixType_ >
typedef NumTraits<Scalar>::Real Eigen::SelfAdjointEigenSolver< MatrixType_ >::RealScalar

Real scalar type for MatrixType_.

This is just Scalar if Scalar is real (e.g., float or double), and the type of the real part of Scalar if Scalar is complex.

◆ RealVectorType

template<typename MatrixType_ >
typedef internal::plain_col_type<MatrixType, RealScalar>::type Eigen::SelfAdjointEigenSolver< MatrixType_ >::RealVectorType

◆ Scalar

template<typename MatrixType_ >
typedef MatrixType::Scalar Eigen::SelfAdjointEigenSolver< MatrixType_ >::Scalar

Scalar type for matrices of type MatrixType_.

◆ SubDiagonalType

template<typename MatrixType_ >
typedef TridiagonalizationType::SubDiagonalType Eigen::SelfAdjointEigenSolver< MatrixType_ >::SubDiagonalType

◆ TridiagonalizationType

template<typename MatrixType_ >
typedef Tridiagonalization<MatrixType> Eigen::SelfAdjointEigenSolver< MatrixType_ >::TridiagonalizationType

◆ VectorType

template<typename MatrixType_ >
typedef internal::plain_col_type<MatrixType, Scalar>::type Eigen::SelfAdjointEigenSolver< MatrixType_ >::VectorType

Type for vector of eigenvalues as returned by eigenvalues().

This is a column vector with entries of type RealScalar. The length of the vector is the size of MatrixType_.

Member Enumeration Documentation

◆ anonymous enum

template<typename MatrixType_ >
anonymous enum
Enumerator
Size 
ColsAtCompileTime 
Options 
MaxColsAtCompileTime 
85  {
86  Size = MatrixType::RowsAtCompileTime,
87  ColsAtCompileTime = MatrixType::ColsAtCompileTime,
88  Options = internal::traits<MatrixType>::Options,
89  MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
90  };
@ ColsAtCompileTime
Definition: SelfAdjointEigenSolver.h:87
@ Options
Definition: SelfAdjointEigenSolver.h:88
@ MaxColsAtCompileTime
Definition: SelfAdjointEigenSolver.h:89
@ Size
Definition: SelfAdjointEigenSolver.h:86

Constructor & Destructor Documentation

◆ SelfAdjointEigenSolver() [1/3]

template<typename MatrixType_ >
EIGEN_DEVICE_FUNC Eigen::SelfAdjointEigenSolver< MatrixType_ >::SelfAdjointEigenSolver ( )
inline

Default constructor for fixed-size matrices.

The default constructor is useful in cases in which the user intends to perform decompositions via compute(). This constructor can only be used if MatrixType_ is a fixed-size matrix; use SelfAdjointEigenSolver(Index) for dynamic-size matrices.

Example:

SelfAdjointEigenSolver<Matrix4f> es;
Matrix4f X = Matrix4f::Random(4, 4);
Matrix4f A = X + X.transpose();
es.compute(A);
cout << "The eigenvalues of A are: " << es.eigenvalues().transpose() << endl;
es.compute(A + Matrix4f::Identity(4, 4)); // re-use es to compute eigenvalues of A+I
cout << "The eigenvalues of A+I are: " << es.eigenvalues().transpose() << endl;
EigenSolver< MatrixXf > es
Definition: EigenSolver_compute.cpp:1
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
#define X
Definition: icosphere.cpp:20

Output:

 
129  : m_eivec(),
130  m_workspace(),
131  m_eivalues(),
132  m_subdiag(),
133  m_hcoeffs(),
135  m_isInitialized(false),
136  m_eigenvectorsOk(false) {}
TridiagonalizationType::CoeffVectorType m_hcoeffs
Definition: SelfAdjointEigenSolver.h:375
VectorType m_workspace
Definition: SelfAdjointEigenSolver.h:372
TridiagonalizationType::SubDiagonalType m_subdiag
Definition: SelfAdjointEigenSolver.h:374
RealVectorType m_eivalues
Definition: SelfAdjointEigenSolver.h:373
ComputationInfo m_info
Definition: SelfAdjointEigenSolver.h:376
bool m_eigenvectorsOk
Definition: SelfAdjointEigenSolver.h:378
bool m_isInitialized
Definition: SelfAdjointEigenSolver.h:377
EigenvectorsType m_eivec
Definition: SelfAdjointEigenSolver.h:371
@ InvalidInput
Definition: Constants.h:447

◆ SelfAdjointEigenSolver() [2/3]

template<typename MatrixType_ >
EIGEN_DEVICE_FUNC Eigen::SelfAdjointEigenSolver< MatrixType_ >::SelfAdjointEigenSolver ( Index  size)
inlineexplicit

Constructor, pre-allocates memory for dynamic-size matrices.

Parameters
[in]sizePositive integer, size of the matrix whose eigenvalues and eigenvectors will be computed.

This constructor is useful for dynamic-size matrices, when the user intends to perform decompositions via compute(). The size parameter is only used as a hint. It is not an error to give a wrong size, but it may impair performance.

See also
compute() for an example
151  : m_eivec(size, size),
152  m_workspace(size),
153  m_eivalues(size),
154  m_subdiag(size > 1 ? size - 1 : 1),
155  m_hcoeffs(size > 1 ? size - 1 : 1),
156  m_isInitialized(false),
157  m_eigenvectorsOk(false) {}
Scalar Scalar int size
Definition: benchVecAdd.cpp:17

◆ SelfAdjointEigenSolver() [3/3]

template<typename MatrixType_ >
template<typename InputType >
EIGEN_DEVICE_FUNC Eigen::SelfAdjointEigenSolver< MatrixType_ >::SelfAdjointEigenSolver ( const EigenBase< InputType > &  matrix,
int  options = ComputeEigenvectors 
)
inlineexplicit

Constructor; computes eigendecomposition of given matrix.

Parameters
[in]matrixSelfadjoint matrix whose eigendecomposition is to be computed. Only the lower triangular part of the matrix is referenced.
[in]optionsCan be ComputeEigenvectors (default) or EigenvaluesOnly.

This constructor calls compute(const MatrixType&, int) to compute the eigenvalues of the matrix matrix. The eigenvectors are computed if options equals ComputeEigenvectors.

Example:

MatrixXd X = MatrixXd::Random(5, 5);
MatrixXd A = X + X.transpose();
cout << "Here is a random symmetric 5x5 matrix, A:" << endl << A << endl << endl;
SelfAdjointEigenSolver<MatrixXd> es(A);
cout << "The eigenvalues of A are:" << endl << es.eigenvalues() << endl;
cout << "The matrix of eigenvectors, V, is:" << endl << es.eigenvectors() << endl << endl;
double lambda = es.eigenvalues()[0];
cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
VectorXd v = es.eigenvectors().col(0);
cout << "If v is the corresponding eigenvector, then lambda * v = " << endl << lambda * v << endl;
cout << "... and A * v = " << endl << A * v << endl << endl;
MatrixXd D = es.eigenvalues().asDiagonal();
MatrixXd V = es.eigenvectors();
cout << "Finally, V * D * V^(-1) = " << endl << V * D * V.inverse() << endl;
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
cout<< "The eigenvalues of A are:"<< endl<< ces.eigenvalues()<< endl;cout<< "The matrix of eigenvectors, V, is:"<< endl<< ces.eigenvectors()<< endl<< endl;complex< float > lambda
Definition: ComplexEigenSolver_compute.cpp:9
dominoes D
Definition: Domino.cpp:55
MatrixXcd V
Definition: EigenSolver_EigenSolver_MatrixType.cpp:15

Output:

See also
compute(const MatrixType&, int)
177  : m_eivec(matrix.rows(), matrix.cols()),
178  m_workspace(matrix.cols()),
179  m_eivalues(matrix.cols()),
180  m_subdiag(matrix.rows() > 1 ? matrix.rows() - 1 : 1),
181  m_hcoeffs(matrix.cols() > 1 ? matrix.cols() - 1 : 1),
182  m_isInitialized(false),
183  m_eigenvectorsOk(false) {
184  compute(matrix.derived(), options);
185  }
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver & compute(const EigenBase< InputType > &matrix, int options=ComputeEigenvectors)
Computes eigendecomposition of given matrix.
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85

References Eigen::SelfAdjointEigenSolver< MatrixType_ >::compute(), and matrix().

Member Function Documentation

◆ compute() [1/2]

template<typename MatrixType_ >
template<typename InputType >
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver<MatrixType>& Eigen::SelfAdjointEigenSolver< MatrixType_ >::compute ( const EigenBase< InputType > &  a_matrix,
int  options 
)
410  {
411  const InputType& matrix(a_matrix.derived());
412 
414  eigen_assert(matrix.cols() == matrix.rows());
415  eigen_assert((options & ~(EigVecMask | GenEigMask)) == 0 && (options & EigVecMask) != EigVecMask &&
416  "invalid option parameter");
417  bool computeEigenvectors = (options & ComputeEigenvectors) == ComputeEigenvectors;
418  Index n = matrix.cols();
419  m_eivalues.resize(n, 1);
420 
421  if (n == 1) {
422  m_eivec = matrix;
423  m_eivalues.coeffRef(0, 0) = numext::real(m_eivec.coeff(0, 0));
424  if (computeEigenvectors) m_eivec.setOnes(n, n);
425  m_info = Success;
426  m_isInitialized = true;
427  m_eigenvectorsOk = computeEigenvectors;
428  return *this;
429  }
430 
431  // declare some aliases
434 
435  // map the matrix coefficients to [-1:1] to avoid over- and underflow.
436  mat = matrix.template triangularView<Lower>();
437  RealScalar scale = mat.cwiseAbs().maxCoeff();
438  if (numext::is_exactly_zero(scale)) scale = RealScalar(1);
439  mat.template triangularView<Lower>() /= scale;
440  m_subdiag.resize(n - 1);
441  m_hcoeffs.resize(n - 1);
443 
445 
446  // scale back the eigen values
447  m_eivalues *= scale;
448 
449  m_isInitialized = true;
450  m_eigenvectorsOk = computeEigenvectors;
451  return *this;
452 }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
#define EIGEN_USING_STD(FUNC)
Definition: Macros.h:1090
#define eigen_assert(x)
Definition: Macros.h:910
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
EIGEN_DEVICE_FUNC Derived & setOnes(Index size)
Definition: CwiseNullaryOp.h:708
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const Scalar & coeff(Index rowId, Index colId) const
Definition: PlainObjectBase.h:198
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:294
internal::plain_col_type< MatrixType, RealScalar >::type RealVectorType
Definition: SelfAdjointEigenSolver.h:114
NumTraits< Scalar >::Real RealScalar
Real scalar type for MatrixType_.
Definition: SelfAdjointEigenSolver.h:104
Eigen::Index Index
Definition: SelfAdjointEigenSolver.h:94
Matrix< Scalar, Size, Size, ColMajor, MaxColsAtCompileTime, MaxColsAtCompileTime > EigenvectorsType
Definition: SelfAdjointEigenSolver.h:96
static const int m_maxIterations
Maximum number of iterations.
Definition: SelfAdjointEigenSolver.h:366
float real
Definition: datatypes.h:10
@ Success
Definition: Constants.h:440
@ GenEigMask
Definition: Constants.h:414
@ EigVecMask
Definition: Constants.h:403
@ ComputeEigenvectors
Definition: Constants.h:401
const char const char const char * diag
Definition: level2_impl.h:86
EIGEN_DEVICE_FUNC void tridiagonalization_inplace(MatrixType &matA, CoeffVectorType &hCoeffs)
Definition: Tridiagonalization.h:332
EIGEN_DEVICE_FUNC ComputationInfo computeFromTridiagonal_impl(DiagType &diag, SubDiagType &subdiag, const Index maxIterations, bool computeEigenvectors, MatrixType &eivec)
Compute the eigendecomposition from a tridiagonal matrix.
Definition: SelfAdjointEigenSolver.h:485
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool is_exactly_zero(const X &x)
Definition: Meta.h:592

References abs(), Eigen::PlainObjectBase< Derived >::coeff(), Eigen::ComputeEigenvectors, Eigen::internal::computeFromTridiagonal_impl(), Eigen::EigenBase< Derived >::derived(), diag, eigen_assert, EIGEN_USING_STD, Eigen::EigVecMask, Eigen::GenEigMask, Eigen::numext::is_exactly_zero(), Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eigenvectorsOk, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eivalues, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eivec, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_hcoeffs, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_info, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_isInitialized, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_maxIterations, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_subdiag, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_workspace, matrix(), n, Eigen::PlainObjectBase< Derived >::resize(), Eigen::PlainObjectBase< Derived >::setOnes(), Eigen::Success, and Eigen::internal::tridiagonalization_inplace().

◆ compute() [2/2]

template<typename MatrixType_ >
template<typename InputType >
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver& Eigen::SelfAdjointEigenSolver< MatrixType_ >::compute ( const EigenBase< InputType > &  matrix,
int  options = ComputeEigenvectors 
)

Computes eigendecomposition of given matrix.

Parameters
[in]matrixSelfadjoint matrix whose eigendecomposition is to be computed. Only the lower triangular part of the matrix is referenced.
[in]optionsCan be ComputeEigenvectors (default) or EigenvaluesOnly.
Returns
Reference to *this

This function computes the eigenvalues of matrix. The eigenvalues() function can be used to retrieve them. If options equals ComputeEigenvectors, then the eigenvectors are also computed and can be retrieved by calling eigenvectors().

This implementation uses a symmetric QR algorithm. The matrix is first reduced to tridiagonal form using the Tridiagonalization class. The tridiagonal matrix is then brought to diagonal form with implicit symmetric QR steps with Wilkinson shift. Details can be found in Section 8.3 of Golub & Van Loan, Matrix Computations.

The cost of the computation is about \( 9n^3 \) if the eigenvectors are required and \( 4n^3/3 \) if they are not required.

This method reuses the memory in the SelfAdjointEigenSolver object that was allocated when the object was constructed, if the size of the matrix does not change.

Example:

SelfAdjointEigenSolver<MatrixXf> es(4);
MatrixXf X = MatrixXf::Random(4, 4);
MatrixXf A = X + X.transpose();
es.compute(A);
cout << "The eigenvalues of A are: " << es.eigenvalues().transpose() << endl;
es.compute(A + MatrixXf::Identity(4, 4)); // re-use es to compute eigenvalues of A+I
cout << "The eigenvalues of A+I are: " << es.eigenvalues().transpose() << endl;

Output:

See also
SelfAdjointEigenSolver(const MatrixType&, int)

Referenced by __attribute__(), ctms_decompositions(), main(), Eigen::SelfAdjointEigenSolver< MatrixType_ >::SelfAdjointEigenSolver(), and selfadjointeigensolver().

◆ computeDirect()

template<typename MatrixType >
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver< MatrixType > & Eigen::SelfAdjointEigenSolver< MatrixType >::computeDirect ( const MatrixType matrix,
int  options = ComputeEigenvectors 
)

Computes eigendecomposition of given matrix using a closed-form algorithm.

This is a variant of compute(const MatrixType&, int options) which directly solves the underlying polynomial equation.

Currently only 2x2 and 3x3 matrices for which the sizes are known at compile time are supported (e.g., Matrix3d).

This method is usually significantly faster than the QR iterative algorithm but it might also be less accurate. It is also worth noting that for 3x3 matrices it involves trigonometric operations which are not necessarily available for all scalar types.

For the 3x3 case, we observed the following worst case relative error regarding the eigenvalues:

  • double: 1e-8
  • float: 1e-3
See also
compute(const MatrixType&, int options)
778  {
780  *this, matrix, options);
781  return *this;
782 }
@ IsComplex
Definition: common.h:73
auto run(Kernel kernel, Args &&... args) -> decltype(kernel(args...))
Definition: gpu_test_helper.h:414

References matrix(), and Eigen::run().

Referenced by main(), selfadjointeigensolver_essential_check(), and test_eigenvalues_direct().

◆ computeFromTridiagonal()

template<typename MatrixType >
SelfAdjointEigenSolver< MatrixType > & Eigen::SelfAdjointEigenSolver< MatrixType >::computeFromTridiagonal ( const RealVectorType diag,
const SubDiagonalType subdiag,
int  options = ComputeEigenvectors 
)

Computes the eigen decomposition from a tridiagonal symmetric matrix.

Parameters
[in]diagThe vector containing the diagonal of the matrix.
[in]subdiagThe subdiagonal of the matrix.
[in]optionsCan be ComputeEigenvectors (default) or EigenvaluesOnly.
Returns
Reference to *this

This function assumes that the matrix has been reduced to tridiagonal form.

See also
compute(const MatrixType&, int) for more information
456  {
457  // TODO : Add an option to scale the values beforehand
458  bool computeEigenvectors = (options & ComputeEigenvectors) == ComputeEigenvectors;
459 
460  m_eivalues = diag;
461  m_subdiag = subdiag;
462  if (computeEigenvectors) {
463  m_eivec.setIdentity(diag.size(), diag.size());
464  }
466 
467  m_isInitialized = true;
468  m_eigenvectorsOk = computeEigenvectors;
469  return *this;
470 }

References Eigen::ComputeEigenvectors, Eigen::internal::computeFromTridiagonal_impl(), diag, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eigenvectorsOk, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eivalues, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eivec, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_info, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_isInitialized, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_maxIterations, and Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_subdiag.

Referenced by selfadjointeigensolver().

◆ eigenvalues()

template<typename MatrixType_ >
EIGEN_DEVICE_FUNC const RealVectorType& Eigen::SelfAdjointEigenSolver< MatrixType_ >::eigenvalues ( ) const
inline

Returns the eigenvalues of given matrix.

Returns
A const reference to the column vector containing the eigenvalues.
Precondition
The eigenvalues have been computed before.

The eigenvalues are repeated according to their algebraic multiplicity, so there are as many eigenvalues as rows in the matrix. The eigenvalues are sorted in increasing order.

Example:

MatrixXd ones = MatrixXd::Ones(3, 3);
SelfAdjointEigenSolver<MatrixXd> es(ones);
cout << "The eigenvalues of the 3x3 matrix of ones are:" << endl << es.eigenvalues() << endl;
MatrixXcf ones
Definition: ComplexEigenSolver_eigenvalues.cpp:1

Output:

See also
eigenvectors(), MatrixBase::eigenvalues()
300  {
301  eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
302  return m_eivalues;
303  }

References eigen_assert, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eivalues, and Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_isInitialized.

Referenced by bug_1225(), EIGEN_DECLARE_TEST(), Eigen::SelfAdjointView< MatrixType_, UpLo >::eigenvalues(), generalized_eigensolver_real(), selfadjointeigensolver(), selfadjointeigensolver_essential_check(), and test_eigenvalues_direct().

◆ eigenvectors()

template<typename MatrixType_ >
EIGEN_DEVICE_FUNC const EigenvectorsType& Eigen::SelfAdjointEigenSolver< MatrixType_ >::eigenvectors ( ) const
inline

Returns the eigenvectors of given matrix.

Returns
A const reference to the matrix whose columns are the eigenvectors.
Precondition
The eigenvectors have been computed before.

Column \( k \) of the returned matrix is an eigenvector corresponding to eigenvalue number \( k \) as returned by eigenvalues(). The eigenvectors are normalized to have (Euclidean) norm equal to one. If this object was used to solve the eigenproblem for the selfadjoint matrix \( A \), then the matrix returned by this function is the matrix \( V \) in the eigendecomposition \( A = V D V^{-1} \).

For a selfadjoint matrix, \( V \) is unitary, meaning its inverse is equal to its adjoint, \( V^{-1} = V^{\dagger} \). If \( A \) is real, then \( V \) is also real and therefore orthogonal, meaning its inverse is equal to its transpose, \( V^{-1} = V^T \).

Example:

MatrixXd ones = MatrixXd::Ones(3, 3);
SelfAdjointEigenSolver<MatrixXd> es(ones);
cout << "The first eigenvector of the 3x3 matrix of ones is:" << endl << es.eigenvectors().col(0) << endl;

Output:

See also
eigenvalues()
279  {
280  eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
281  eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues.");
282  return m_eivec;
283  }

References eigen_assert, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eigenvectorsOk, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eivec, and Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_isInitialized.

Referenced by __attribute__(), EIGEN_DECLARE_TEST(), selfadjointeigensolver(), and selfadjointeigensolver_essential_check().

◆ info()

template<typename MatrixType_ >
EIGEN_DEVICE_FUNC ComputationInfo Eigen::SelfAdjointEigenSolver< MatrixType_ >::info ( ) const
inline

Reports whether previous computation was successful.

Returns
Success if computation was successful, NoConvergence otherwise.
356  {
357  eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
358  return m_info;
359  }

References eigen_assert, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_info, and Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_isInitialized.

Referenced by Eigen::internal::computeFromTridiagonal_impl(), EIGEN_DECLARE_TEST(), selfadjointeigensolver(), and selfadjointeigensolver_essential_check().

◆ operatorInverseSqrt()

template<typename MatrixType_ >
EIGEN_DEVICE_FUNC MatrixType Eigen::SelfAdjointEigenSolver< MatrixType_ >::operatorInverseSqrt ( ) const
inline

Computes the inverse square root of the matrix.

Returns
the inverse positive-definite square root of the matrix
Precondition
The eigenvalues and eigenvectors of a positive-definite matrix have been computed before.

This function uses the eigendecomposition \( A = V D V^{-1} \) to compute the inverse square root as \( V D^{-1/2} V^{-1} \). This is cheaper than first computing the square root with operatorSqrt() and then its inverse with MatrixBase::inverse().

Example:

MatrixXd X = MatrixXd::Random(4, 4);
MatrixXd A = X * X.transpose();
cout << "Here is a random positive-definite matrix, A:" << endl << A << endl << endl;
SelfAdjointEigenSolver<MatrixXd> es(A);
cout << "The inverse square root of A is: " << endl;
cout << es.operatorInverseSqrt() << endl;
cout << "We can also compute it with operatorSqrt() and inverse(). That yields: " << endl;
cout << es.operatorSqrt().inverse() << endl;

Output:

See also
operatorSqrt(), MatrixBase::inverse(), MatrixFunctions Module
346  {
347  eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
348  eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues.");
349  return m_eivec * m_eivalues.cwiseInverse().cwiseSqrt().asDiagonal() * m_eivec.adjoint();
350  }

References eigen_assert, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eigenvectorsOk, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eivalues, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eivec, and Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_isInitialized.

Referenced by selfadjointeigensolver().

◆ operatorSqrt()

template<typename MatrixType_ >
EIGEN_DEVICE_FUNC MatrixType Eigen::SelfAdjointEigenSolver< MatrixType_ >::operatorSqrt ( ) const
inline

Computes the positive-definite square root of the matrix.

Returns
the positive-definite square root of the matrix
Precondition
The eigenvalues and eigenvectors of a positive-definite matrix have been computed before.

The square root of a positive-definite matrix \( A \) is the positive-definite matrix whose square equals \( A \). This function uses the eigendecomposition \( A = V D V^{-1} \) to compute the square root as \( A^{1/2} = V D^{1/2} V^{-1} \).

Example:

MatrixXd X = MatrixXd::Random(4, 4);
MatrixXd A = X * X.transpose();
cout << "Here is a random positive-definite matrix, A:" << endl << A << endl << endl;
SelfAdjointEigenSolver<MatrixXd> es(A);
MatrixXd sqrtA = es.operatorSqrt();
cout << "The square root of A is: " << endl << sqrtA << endl;
cout << "If we square this, we get: " << endl << sqrtA * sqrtA << endl;
MatrixXd sqrtA
Definition: SelfAdjointEigenSolver_operatorSqrt.cpp:6

Output:

See also
operatorInverseSqrt(), MatrixFunctions Module
322  {
323  eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
324  eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues.");
325  return m_eivec * m_eivalues.cwiseSqrt().asDiagonal() * m_eivec.adjoint();
326  }

References eigen_assert, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eigenvectorsOk, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eivalues, Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eivec, and Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_isInitialized.

Referenced by selfadjointeigensolver().

Friends And Related Function Documentation

◆ internal::direct_selfadjoint_eigenvalues< SelfAdjointEigenSolver, Size, NumTraits< Scalar >::IsComplex >

template<typename MatrixType_ >
friend struct internal::direct_selfadjoint_eigenvalues< SelfAdjointEigenSolver, Size, NumTraits< Scalar >::IsComplex >
friend

Member Data Documentation

◆ m_eigenvectorsOk

◆ m_eivalues

◆ m_eivec

◆ m_hcoeffs

template<typename MatrixType_ >
TridiagonalizationType::CoeffVectorType Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_hcoeffs
protected

◆ m_info

◆ m_isInitialized

◆ m_maxIterations

template<typename MatrixType_ >
const int Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_maxIterations = 30
static

Maximum number of iterations.

The algorithm terminates if it does not converge within m_maxIterations * n iterations, where n denotes the size of the matrix. This value is currently set to 30 (copied from LAPACK).

Referenced by Eigen::SelfAdjointEigenSolver< MatrixType_ >::compute(), and Eigen::SelfAdjointEigenSolver< MatrixType_ >::computeFromTridiagonal().

◆ m_subdiag

◆ m_workspace

template<typename MatrixType_ >
VectorType Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_workspace
protected

The documentation for this class was generated from the following file: