Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Eigen::ComplexEigenSolver< _MatrixType > Class Template Reference

Computes eigenvalues and eigenvectors of general complex matrices. More...

#include <src/eigen/Eigen/src/Eigenvalues/ComplexEigenSolver.h>

+ Collaboration diagram for Eigen::ComplexEigenSolver< _MatrixType >:

Public Types

enum  {
  RowsAtCompileTime = MatrixType::RowsAtCompileTime , ColsAtCompileTime = MatrixType::ColsAtCompileTime , Options = MatrixType::Options , MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime ,
  MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
}
 
typedef _MatrixType MatrixType
 Synonym for the template parameter _MatrixType.
 
typedef MatrixType::Scalar Scalar
 Scalar type for matrices of type MatrixType.
 
typedef NumTraits< Scalar >::Real RealScalar
 
typedef Eigen::Index Index
 
typedef std::complex< RealScalarComplexScalar
 Complex scalar type for MatrixType.
 
typedef Matrix< ComplexScalar, ColsAtCompileTime, 1, Options &(~RowMajor), MaxColsAtCompileTime, 1 > EigenvalueType
 Type for vector of eigenvalues as returned by eigenvalues().
 
typedef Matrix< ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTimeEigenvectorType
 Type for matrix of eigenvectors as returned by eigenvectors().
 

Public Member Functions

 ComplexEigenSolver ()
 Default constructor.
 
 ComplexEigenSolver (Index size)
 Default Constructor with memory preallocation.
 
template<typename InputType >
 ComplexEigenSolver (const EigenBase< InputType > &matrix, bool computeEigenvectors=true)
 Constructor; computes eigendecomposition of given matrix.
 
const EigenvectorTypeeigenvectors () const
 Returns the eigenvectors of given matrix.
 
const EigenvalueTypeeigenvalues () const
 Returns the eigenvalues of given matrix.
 
template<typename InputType >
ComplexEigenSolvercompute (const EigenBase< InputType > &matrix, bool computeEigenvectors=true)
 Computes eigendecomposition of given matrix.
 
ComputationInfo info () const
 Reports whether previous computation was successful.
 
ComplexEigenSolversetMaxIterations (Index maxIters)
 Sets the maximum number of iterations allowed.
 
Index getMaxIterations ()
 Returns the maximum number of iterations.
 
template<typename InputType >
ComplexEigenSolver< MatrixType > & compute (const EigenBase< InputType > &matrix, bool computeEigenvectors)
 

Static Protected Member Functions

static void check_template_parameters ()
 

Protected Attributes

EigenvectorType m_eivec
 
EigenvalueType m_eivalues
 
ComplexSchur< MatrixTypem_schur
 
bool m_isInitialized
 
bool m_eigenvectorsOk
 
EigenvectorType m_matX
 

Private Member Functions

void doComputeEigenvectors (RealScalar matrixnorm)
 
void sortEigenvalues (bool computeEigenvectors)
 

Detailed Description

template<typename _MatrixType>
class Eigen::ComplexEigenSolver< _MatrixType >

Computes eigenvalues and eigenvectors of general complex matrices.

\eigenvalues_module

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.

The eigenvalues and eigenvectors of a matrix $ A $ are scalars $ \lambda $ and vectors $ v $ such that $ Av = \lambda v
$. 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 = V D $. The matrix $ V $ is almost always invertible, in which case we have $ A = V D V^{-1}
$. This is called the eigendecomposition.

The main function in this class is compute(), which computes the eigenvalues and eigenvectors of a given function. The documentation for that function contains an example showing the main features of the class.

See also
class EigenSolver, class SelfAdjointEigenSolver

Member Typedef Documentation

◆ ComplexScalar

template<typename _MatrixType >
typedef std::complex<RealScalar> Eigen::ComplexEigenSolver< _MatrixType >::ComplexScalar

Complex scalar type for MatrixType.

This is std::complex<Scalar> if Scalar is real (e.g., float or double) and just Scalar if Scalar is complex.

◆ EigenvalueType

template<typename _MatrixType >
typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options&(~RowMajor), MaxColsAtCompileTime, 1> Eigen::ComplexEigenSolver< _MatrixType >::EigenvalueType

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

This is a column vector with entries of type ComplexScalar. The length of the vector is the size of MatrixType.

◆ EigenvectorType

template<typename _MatrixType >
typedef Matrix<ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime> Eigen::ComplexEigenSolver< _MatrixType >::EigenvectorType

Type for matrix of eigenvectors as returned by eigenvectors().

This is a square matrix with entries of type ComplexScalar. The size is the same as the size of MatrixType.

◆ Index

template<typename _MatrixType >
typedef Eigen::Index Eigen::ComplexEigenSolver< _MatrixType >::Index

◆ MatrixType

template<typename _MatrixType >
typedef _MatrixType Eigen::ComplexEigenSolver< _MatrixType >::MatrixType

Synonym for the template parameter _MatrixType.

◆ RealScalar

template<typename _MatrixType >
typedef NumTraits<Scalar>::Real Eigen::ComplexEigenSolver< _MatrixType >::RealScalar

◆ Scalar

template<typename _MatrixType >
typedef MatrixType::Scalar Eigen::ComplexEigenSolver< _MatrixType >::Scalar

Scalar type for matrices of type MatrixType.

Member Enumeration Documentation

◆ anonymous enum

template<typename _MatrixType >
anonymous enum
Enumerator
RowsAtCompileTime 
ColsAtCompileTime 
Options 
MaxRowsAtCompileTime 
MaxColsAtCompileTime 
52 {
53 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
54 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
55 Options = MatrixType::Options,
56 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
57 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
58 };
@ MaxColsAtCompileTime
Definition ComplexEigenSolver.h:57
@ Options
Definition ComplexEigenSolver.h:55
@ RowsAtCompileTime
Definition ComplexEigenSolver.h:53
@ ColsAtCompileTime
Definition ComplexEigenSolver.h:54
@ MaxRowsAtCompileTime
Definition ComplexEigenSolver.h:56

Constructor & Destructor Documentation

◆ ComplexEigenSolver() [1/3]

template<typename _MatrixType >
Eigen::ComplexEigenSolver< _MatrixType >::ComplexEigenSolver ( )
inline

Default constructor.

The default constructor is useful in cases in which the user intends to perform decompositions via compute().

93 : m_eivec(),
94 m_eivalues(),
95 m_schur(),
96 m_isInitialized(false),
97 m_eigenvectorsOk(false),
98 m_matX()
99 {}
EigenvectorType m_eivec
Definition ComplexEigenSolver.h:245
EigenvalueType m_eivalues
Definition ComplexEigenSolver.h:246
bool m_isInitialized
Definition ComplexEigenSolver.h:248
EigenvectorType m_matX
Definition ComplexEigenSolver.h:250
bool m_eigenvectorsOk
Definition ComplexEigenSolver.h:249
ComplexSchur< MatrixType > m_schur
Definition ComplexEigenSolver.h:247

◆ ComplexEigenSolver() [2/3]

template<typename _MatrixType >
Eigen::ComplexEigenSolver< _MatrixType >::ComplexEigenSolver ( Index  size)
inlineexplicit

Default Constructor with memory preallocation.

Like the default constructor but with preallocation of the internal data according to the specified problem size.

See also
ComplexEigenSolver()
108 : m_eivec(size, size),
109 m_eivalues(size),
110 m_schur(size),
111 m_isInitialized(false),
112 m_eigenvectorsOk(false),
113 m_matX(size, size)
114 {}

◆ ComplexEigenSolver() [3/3]

template<typename _MatrixType >
template<typename InputType >
Eigen::ComplexEigenSolver< _MatrixType >::ComplexEigenSolver ( const EigenBase< InputType > &  matrix,
bool  computeEigenvectors = true 
)
inlineexplicit

Constructor; computes eigendecomposition of given matrix.

Parameters
[in]matrixSquare matrix whose eigendecomposition is to be computed.
[in]computeEigenvectorsIf true, both the eigenvectors and the eigenvalues are computed; if false, only the eigenvalues are computed.

This constructor calls compute() to compute the eigendecomposition.

127 : m_eivec(matrix.rows(),matrix.cols()),
128 m_eivalues(matrix.cols()),
129 m_schur(matrix.rows()),
130 m_isInitialized(false),
131 m_eigenvectorsOk(false),
132 m_matX(matrix.rows(),matrix.cols())
133 {
134 compute(matrix.derived(), computeEigenvectors);
135 }
ComplexEigenSolver & compute(const EigenBase< InputType > &matrix, bool computeEigenvectors=true)
Computes eigendecomposition of given matrix.

References Eigen::ComplexEigenSolver< _MatrixType >::compute(), and Eigen::EigenBase< Derived >::derived().

+ Here is the call graph for this function:

Member Function Documentation

◆ check_template_parameters()

template<typename _MatrixType >
static void Eigen::ComplexEigenSolver< _MatrixType >::check_template_parameters ( )
inlinestaticprotected
241 {
243 }
#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE)
Definition StaticAssert.h:184
MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.
Definition ComplexEigenSolver.h:61

References EIGEN_STATIC_ASSERT_NON_INTEGER.

◆ compute() [1/2]

template<typename _MatrixType >
template<typename InputType >
ComplexEigenSolver< MatrixType > & Eigen::ComplexEigenSolver< _MatrixType >::compute ( const EigenBase< InputType > &  matrix,
bool  computeEigenvectors 
)
262{
264
265 // this code is inspired from Jampack
266 eigen_assert(matrix.cols() == matrix.rows());
267
268 // Do a complex Schur decomposition, A = U T U^*
269 // The eigenvalues are on the diagonal of T.
270 m_schur.compute(matrix.derived(), computeEigenvectors);
271
272 if(m_schur.info() == Success)
273 {
274 m_eivalues = m_schur.matrixT().diagonal();
275 if(computeEigenvectors)
277 sortEigenvalues(computeEigenvectors);
278 }
279
280 m_isInitialized = true;
281 m_eigenvectorsOk = computeEigenvectors;
282 return *this;
283}
#define eigen_assert(x)
Definition Macros.h:579
void sortEigenvalues(bool computeEigenvectors)
Definition ComplexEigenSolver.h:327
static void check_template_parameters()
Definition ComplexEigenSolver.h:240
void doComputeEigenvectors(RealScalar matrixnorm)
Definition ComplexEigenSolver.h:287
const ComplexMatrixType & matrixT() const
Returns the triangular matrix in the Schur decomposition.
Definition ComplexSchur.h:162
ComputationInfo info() const
Reports whether previous computation was successful.
Definition ComplexSchur.h:217
ComplexSchur & compute(const EigenBase< InputType > &matrix, bool computeU=true)
Computes Schur decomposition of given matrix.
@ Success
Definition Constants.h:432

References Eigen::EigenBase< Derived >::cols(), Eigen::EigenBase< Derived >::derived(), eigen_assert, Eigen::EigenBase< Derived >::rows(), and Eigen::Success.

+ Here is the call graph for this function:

◆ compute() [2/2]

template<typename _MatrixType >
template<typename InputType >
ComplexEigenSolver & Eigen::ComplexEigenSolver< _MatrixType >::compute ( const EigenBase< InputType > &  matrix,
bool  computeEigenvectors = true 
)

Computes eigendecomposition of given matrix.

Parameters
[in]matrixSquare matrix whose eigendecomposition is to be computed.
[in]computeEigenvectorsIf true, both the eigenvectors and the eigenvalues are computed; if false, only the eigenvalues are computed.
Returns
Reference to *this

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

The matrix is first reduced to Schur form using the ComplexSchur class. The Schur decomposition is then used to compute the eigenvalues and eigenvectors.

The cost of the computation is dominated by the cost of the Schur decomposition, which is $ O(n^3) $ where $ n $ is the size of the matrix.

Example:

Output:

 

Referenced by Eigen::ComplexEigenSolver< _MatrixType >::ComplexEigenSolver().

+ Here is the caller graph for this function:

◆ doComputeEigenvectors()

template<typename MatrixType >
void Eigen::ComplexEigenSolver< MatrixType >::doComputeEigenvectors ( RealScalar  matrixnorm)
private
288{
289 const Index n = m_eivalues.size();
290
291 matrixnorm = numext::maxi(matrixnorm,(std::numeric_limits<RealScalar>::min)());
292
293 // Compute X such that T = X D X^(-1), where D is the diagonal of T.
294 // The matrix X is unit triangular.
295 m_matX = EigenvectorType::Zero(n, n);
296 for(Index k=n-1 ; k>=0 ; k--)
297 {
298 m_matX.coeffRef(k,k) = ComplexScalar(1.0,0.0);
299 // Compute X(i,k) using the (i,k) entry of the equation X T = D X
300 for(Index i=k-1 ; i>=0 ; i--)
301 {
302 m_matX.coeffRef(i,k) = -m_schur.matrixT().coeff(i,k);
303 if(k-i-1>0)
304 m_matX.coeffRef(i,k) -= (m_schur.matrixT().row(i).segment(i+1,k-i-1) * m_matX.col(k).segment(i+1,k-i-1)).value();
306 if(z==ComplexScalar(0))
307 {
308 // If the i-th and k-th eigenvalue are equal, then z equals 0.
309 // Use a small value instead, to prevent division by zero.
310 numext::real_ref(z) = NumTraits<RealScalar>::epsilon() * matrixnorm;
311 }
312 m_matX.coeffRef(i,k) = m_matX.coeff(i,k) / z;
313 }
314 }
315
316 // Compute V as V = U X; now A = U T U^* = U X D X^(-1) U^* = V D V^(-1)
317 m_eivec.noalias() = m_schur.matrixU() * m_matX;
318 // .. and normalize the eigenvectors
319 for(Index k=0 ; k<n ; k++)
320 {
321 m_eivec.col(k).normalize();
322 }
323}
std::complex< RealScalar > ComplexScalar
Complex scalar type for MatrixType.
Definition ComplexEigenSolver.h:71
Eigen::Index Index
Definition ComplexEigenSolver.h:63
const ComplexMatrixType & matrixU() const
Returns the unitary matrix in the Schur decomposition.
Definition ComplexSchur.h:138
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
Definition PlainObjectBase.h:183
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & coeff(Index rowId, Index colId) const
Definition PlainObjectBase.h:160
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
Definition MathFunctions.h:823
EIGEN_DEVICE_FUNC internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar)>::type real_ref(const Scalar &x)
Definition MathFunctions.h:865

References Eigen::numext::maxi(), and Eigen::numext::real_ref().

+ Here is the call graph for this function:

◆ eigenvalues()

template<typename _MatrixType >
const EigenvalueType & Eigen::ComplexEigenSolver< _MatrixType >::eigenvalues ( ) const
inline

Returns the eigenvalues of given matrix.

Returns
A const reference to the column vector containing the eigenvalues.
Precondition
Either the constructor ComplexEigenSolver(const MatrixType& matrix, bool) or the member function compute(const MatrixType& matrix, bool) has been called before to compute the eigendecomposition of a matrix.

This function returns a column vector containing the eigenvalues. Eigenvalues are repeated according to their algebraic multiplicity, so there are as many eigenvalues as rows in the matrix. The eigenvalues are not sorted in any particular order.

Example:

Output:

 
183 {
184 eigen_assert(m_isInitialized && "ComplexEigenSolver is not initialized.");
185 return m_eivalues;
186 }

References eigen_assert, Eigen::ComplexEigenSolver< _MatrixType >::m_eivalues, and Eigen::ComplexEigenSolver< _MatrixType >::m_isInitialized.

Referenced by Eigen::internal::eigenvalues_selector< Derived, IsComplex >::run().

+ Here is the caller graph for this function:

◆ eigenvectors()

template<typename _MatrixType >
const EigenvectorType & Eigen::ComplexEigenSolver< _MatrixType >::eigenvectors ( ) const
inline

Returns the eigenvectors of given matrix.

Returns
A const reference to the matrix whose columns are the eigenvectors.
Precondition
Either the constructor ComplexEigenSolver(const MatrixType& matrix, bool) or the member function compute(const MatrixType& matrix, bool) has been called before to compute the eigendecomposition of a matrix, and computeEigenvectors was set to true (the default).

This function returns a matrix whose columns are the eigenvectors. Column $ k $ is an eigenvector corresponding to eigenvalue number $ k
$ as returned by eigenvalues(). The eigenvectors are normalized to have (Euclidean) norm equal to one. The matrix returned by this function is the matrix $ V $ in the eigendecomposition $ A = V D
V^{-1} $, if it exists.

Example:

Output:

 
158 {
159 eigen_assert(m_isInitialized && "ComplexEigenSolver is not initialized.");
160 eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues.");
161 return m_eivec;
162 }

References eigen_assert, Eigen::ComplexEigenSolver< _MatrixType >::m_eigenvectorsOk, Eigen::ComplexEigenSolver< _MatrixType >::m_eivec, and Eigen::ComplexEigenSolver< _MatrixType >::m_isInitialized.

◆ getMaxIterations()

template<typename _MatrixType >
Index Eigen::ComplexEigenSolver< _MatrixType >::getMaxIterations ( )
inline

Returns the maximum number of iterations.

234 {
235 return m_schur.getMaxIterations();
236 }
Index getMaxIterations()
Returns the maximum number of iterations.
Definition ComplexSchur.h:235

References Eigen::ComplexSchur< _MatrixType >::getMaxIterations(), and Eigen::ComplexEigenSolver< _MatrixType >::m_schur.

+ Here is the call graph for this function:

◆ info()

template<typename _MatrixType >
ComputationInfo Eigen::ComplexEigenSolver< _MatrixType >::info ( ) const
inline

Reports whether previous computation was successful.

Returns
Success if computation was succesful, NoConvergence otherwise.
220 {
221 eigen_assert(m_isInitialized && "ComplexEigenSolver is not initialized.");
222 return m_schur.info();
223 }

References eigen_assert, Eigen::ComplexSchur< _MatrixType >::info(), Eigen::ComplexEigenSolver< _MatrixType >::m_isInitialized, and Eigen::ComplexEigenSolver< _MatrixType >::m_schur.

+ Here is the call graph for this function:

◆ setMaxIterations()

template<typename _MatrixType >
ComplexEigenSolver & Eigen::ComplexEigenSolver< _MatrixType >::setMaxIterations ( Index  maxIters)
inline

Sets the maximum number of iterations allowed.

227 {
228 m_schur.setMaxIterations(maxIters);
229 return *this;
230 }
ComplexSchur & setMaxIterations(Index maxIters)
Sets the maximum number of iterations allowed.
Definition ComplexSchur.h:228

References Eigen::ComplexEigenSolver< _MatrixType >::m_schur, and Eigen::ComplexSchur< _MatrixType >::setMaxIterations().

+ Here is the call graph for this function:

◆ sortEigenvalues()

template<typename MatrixType >
void Eigen::ComplexEigenSolver< MatrixType >::sortEigenvalues ( bool  computeEigenvectors)
private
328{
329 const Index n = m_eivalues.size();
330 for (Index i=0; i<n; i++)
331 {
332 Index k;
333 m_eivalues.cwiseAbs().tail(n-i).minCoeff(&k);
334 if (k != 0)
335 {
336 k += i;
337 std::swap(m_eivalues[k],m_eivalues[i]);
338 if(computeEigenvectors)
339 m_eivec.col(i).swap(m_eivec.col(k));
340 }
341 }
342}
EIGEN_DEVICE_FUNC void swap(DenseBase< OtherDerived > &other)
Definition PlainObjectBase.h:886

Member Data Documentation

◆ m_eigenvectorsOk

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

◆ m_eivalues

template<typename _MatrixType >
EigenvalueType Eigen::ComplexEigenSolver< _MatrixType >::m_eivalues
protected

◆ m_eivec

template<typename _MatrixType >
EigenvectorType Eigen::ComplexEigenSolver< _MatrixType >::m_eivec
protected

◆ m_isInitialized

◆ m_matX

template<typename _MatrixType >
EigenvectorType Eigen::ComplexEigenSolver< _MatrixType >::m_matX
protected

◆ m_schur


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