12 #ifndef EIGEN_COMPLEX_EIGEN_SOLVER_H 13 #define EIGEN_COMPLEX_EIGEN_SOLVER_H 15 #include "./ComplexSchur.h" 53 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
54 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
55 Options = MatrixType::Options,
56 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
57 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
61 typedef typename MatrixType::Scalar
Scalar;
96 m_isInitialized(false),
97 m_eigenvectorsOk(false),
108 : m_eivec(size, size),
111 m_isInitialized(false),
112 m_eigenvectorsOk(false),
125 template<
typename InputType>
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())
159 eigen_assert(m_isInitialized &&
"ComplexEigenSolver is not initialized.");
160 eigen_assert(m_eigenvectorsOk &&
"The eigenvectors have not been computed together with the eigenvalues.");
184 eigen_assert(m_isInitialized &&
"ComplexEigenSolver is not initialized.");
212 template<
typename InputType>
221 eigen_assert(m_isInitialized &&
"ComplexEigenSolver is not initialized.");
222 return m_schur.
info();
240 static void check_template_parameters()
242 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
245 EigenvectorType m_eivec;
246 EigenvalueType m_eivalues;
248 bool m_isInitialized;
249 bool m_eigenvectorsOk;
250 EigenvectorType m_matX;
253 void doComputeEigenvectors(
const RealScalar& matrixnorm);
254 void sortEigenvalues(
bool computeEigenvectors);
258 template<
typename MatrixType>
259 template<
typename InputType>
263 check_template_parameters();
266 eigen_assert(matrix.
cols() == matrix.
rows());
274 m_eivalues = m_schur.
matrixT().diagonal();
275 if(computeEigenvectors)
276 doComputeEigenvectors(m_schur.
matrixT().norm());
277 sortEigenvalues(computeEigenvectors);
280 m_isInitialized =
true;
281 m_eigenvectorsOk = computeEigenvectors;
286 template<
typename MatrixType>
289 const Index n = m_eivalues.size();
293 m_matX = EigenvectorType::Zero(n, n);
294 for(
Index k=n-1 ; k>=0 ; k--)
298 for(
Index i=k-1 ; i>=0 ; i--)
302 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();
315 m_eivec.noalias() = m_schur.
matrixU() * m_matX;
317 for(
Index k=0 ; k<n ; k++)
319 m_eivec.col(k).normalize();
324 template<
typename MatrixType>
327 const Index n = m_eivalues.size();
328 for (
Index i=0; i<n; i++)
331 m_eivalues.cwiseAbs().tail(n-i).minCoeff(&k);
335 std::swap(m_eivalues[k],m_eivalues[i]);
336 if(computeEigenvectors)
337 m_eivec.col(i).swap(m_eivec.col(k));
344 #endif // EIGEN_COMPLEX_EIGEN_SOLVER_H EIGEN_DEVICE_FUNC Index rows() const
Definition: EigenBase.h:58
ComplexSchur & setMaxIterations(Index maxIters)
Sets the maximum number of iterations allowed.
Definition: ComplexSchur.h:228
ComplexEigenSolver(Index size)
Default Constructor with memory preallocation.
Definition: ComplexEigenSolver.h:107
ComplexEigenSolver & compute(const EigenBase< InputType > &matrix, bool computeEigenvectors=true)
Computes eigendecomposition of given matrix.
Matrix< ComplexScalar, ColsAtCompileTime, 1, Options &(~RowMajor), MaxColsAtCompileTime, 1 > EigenvalueType
Type for vector of eigenvalues as returned by eigenvalues().
Definition: ComplexEigenSolver.h:78
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Holds information about the various numeric (i.e.
Definition: NumTraits.h:150
MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.
Definition: ComplexEigenSolver.h:61
Eigen::Index Index
Definition: ComplexEigenSolver.h:63
ComplexSchur & compute(const EigenBase< InputType > &matrix, bool computeU=true)
Computes Schur decomposition of given matrix.
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: ComplexSchur.h:217
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:28
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
This is an overloaded version of DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index,Index) const provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.
Definition: PlainObjectBase.h:177
const EigenvalueType & eigenvalues() const
Returns the eigenvalues of given matrix.
Definition: ComplexEigenSolver.h:182
Matrix< ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime > EigenvectorType
Type for matrix of eigenvectors as returned by eigenvectors().
Definition: ComplexEigenSolver.h:85
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: ComplexEigenSolver.h:219
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & coeff(Index rowId, Index colId) const
This is an overloaded version of DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index,Index) const provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.
Definition: PlainObjectBase.h:154
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
ComplexEigenSolver(const EigenBase< InputType > &matrix, bool computeEigenvectors=true)
Constructor; computes eigendecomposition of given matrix.
Definition: ComplexEigenSolver.h:126
const EigenvectorType & eigenvectors() const
Returns the eigenvectors of given matrix.
Definition: ComplexEigenSolver.h:157
Index getMaxIterations()
Returns the maximum number of iterations.
Definition: ComplexSchur.h:235
Computation was successful.
Definition: Constants.h:432
_MatrixType MatrixType
Synonym for the template parameter _MatrixType.
Definition: ComplexEigenSolver.h:50
ComplexEigenSolver()
Default constructor.
Definition: ComplexEigenSolver.h:92
Index getMaxIterations()
Returns the maximum number of iterations.
Definition: ComplexEigenSolver.h:233
ComplexEigenSolver & setMaxIterations(Index maxIters)
Sets the maximum number of iterations allowed.
Definition: ComplexEigenSolver.h:226
const ComplexMatrixType & matrixU() const
Returns the unitary matrix in the Schur decomposition.
Definition: ComplexSchur.h:138
EIGEN_DEVICE_FUNC Index cols() const
Definition: EigenBase.h:61
std::complex< RealScalar > ComplexScalar
Complex scalar type for MatrixType.
Definition: ComplexEigenSolver.h:71
Definition: ComplexEigenSolver.h:45
ComputationInfo
Enum for reporting the status of a computation.
Definition: Constants.h:430
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:44
const ComplexMatrixType & matrixT() const
Returns the triangular matrix in the Schur decomposition.
Definition: ComplexSchur.h:162