Loading [MathJax]/extensions/tex2jax.js
WPILibC++ 2023.4.3
Eigen::SelfAdjointEigenSolver< _MatrixType > Class Template Reference

\eigenvalues_module More...

#include </home/runner/work/allwpilib/allwpilib/wpimath/src/main/native/thirdparty/eigen/include/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h>

Inheritance diagram for Eigen::SelfAdjointEigenSolver< _MatrixType >:
Eigen::GeneralizedSelfAdjointEigenSolver< _MatrixType >

Public Types

enum  { Size = MatrixType::RowsAtCompileTime , ColsAtCompileTime = MatrixType::ColsAtCompileTime , Options = 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, RealScalar >::type RealVectorType
 Type for vector of eigenvalues as returned by eigenvalues(). More...
 
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...
 

Static Protected Member Functions

static EIGEN_DEVICE_FUNC void check_template_parameters ()
 

Protected Attributes

EigenvectorsType m_eivec
 
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 >

\eigenvalues_module

Computes eigenvalues and eigenvectors of selfadjoint matrices

Template Parameters
_MatrixTypethe 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

template<typename _MatrixType >
typedef Matrix<Scalar,Size,Size,ColMajor,MaxColsAtCompileTime,MaxColsAtCompileTime> Eigen::SelfAdjointEigenSolver< _MatrixType >::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

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.

◆ 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

Member Enumeration Documentation

◆ anonymous enum

template<typename _MatrixType >
anonymous enum
Enumerator
Size 
ColsAtCompileTime 
Options 
MaxColsAtCompileTime 

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:

Output:

 

◆ 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

◆ 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:

Output:

See also
compute(const MatrixType&, int)

Member Function Documentation

◆ check_template_parameters()

template<typename _MatrixType >
static EIGEN_DEVICE_FUNC void Eigen::SelfAdjointEigenSolver< _MatrixType >::check_template_parameters ( )
inlinestaticprotected

◆ 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 
)

◆ 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:

Output:

See also
SelfAdjointEigenSolver(const MatrixType&, int)

◆ 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)

◆ 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

◆ 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:

Output:

See also
eigenvectors(), MatrixBase::eigenvalues()

◆ 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:

Output:

See also
eigenvalues()

◆ 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.

◆ 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:

Output:

See also
operatorSqrt(), MatrixBase::inverse(), MatrixFunctions Module

◆ 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:

Output:

See also
operatorInverseSqrt(), MatrixFunctions Module

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

template<typename _MatrixType >
bool Eigen::SelfAdjointEigenSolver< _MatrixType >::m_eigenvectorsOk
protected

◆ m_eivalues

template<typename _MatrixType >
RealVectorType Eigen::SelfAdjointEigenSolver< _MatrixType >::m_eivalues
protected

◆ m_eivec

template<typename _MatrixType >
EigenvectorsType Eigen::SelfAdjointEigenSolver< _MatrixType >::m_eivec
protected

◆ m_hcoeffs

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

◆ m_info

template<typename _MatrixType >
ComputationInfo Eigen::SelfAdjointEigenSolver< _MatrixType >::m_info
protected

◆ m_isInitialized

template<typename _MatrixType >
bool Eigen::SelfAdjointEigenSolver< _MatrixType >::m_isInitialized
protected

◆ 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).

◆ m_subdiag

template<typename _MatrixType >
TridiagonalizationType::SubDiagonalType Eigen::SelfAdjointEigenSolver< _MatrixType >::m_subdiag
protected

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