12#ifndef EIGEN_GENERALIZEDEIGENSOLVER_H
13#define EIGEN_GENERALIZEDEIGENSOLVER_H
66 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
67 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
68 Options = MatrixType::Options,
69 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
70 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
74 typedef typename MatrixType::Scalar
Scalar;
122 m_computeEigenvectors(
false),
123 m_isInitialized(
false),
134 : m_eivec(size, size),
137 m_computeEigenvectors(
false),
138 m_isInitialized(
false),
156 : m_eivec(A.rows(), A.cols()),
159 m_computeEigenvectors(
false),
160 m_isInitialized(
false),
180 eigen_assert(info() ==
Success &&
"GeneralizedEigenSolver failed to compute eigenvectors");
181 eigen_assert(m_computeEigenvectors &&
"Eigenvectors for GeneralizedEigenSolver were not calculated");
205 eigen_assert(info() ==
Success &&
"GeneralizedEigenSolver failed to compute eigenvalues.");
216 eigen_assert(info() ==
Success &&
"GeneralizedEigenSolver failed to compute alphas.");
227 eigen_assert(info() ==
Success &&
"GeneralizedEigenSolver failed to compute betas.");
258 eigen_assert(m_isInitialized &&
"EigenSolver is not initialized.");
259 return m_realQZ.
info();
272 static void check_template_parameters()
274 EIGEN_STATIC_ASSERT_NON_INTEGER(
Scalar);
281 bool m_computeEigenvectors;
282 bool m_isInitialized;
283 RealQZ<MatrixType> m_realQZ;
287template<
typename MatrixType>
288GeneralizedEigenSolver<MatrixType>&
291 check_template_parameters();
295 eigen_assert(A.cols() == A.rows() && B.cols() == A.rows() && B.cols() == B.rows());
296 Index size = A.cols();
300 if (m_realQZ.info() ==
Success)
303 m_alphas.resize(size);
304 m_betas.resize(size);
307 m_eivec.resize(size,size);
320 if (i == size - 1 ||
mS.coeff(i+1, i) ==
Scalar(0))
323 m_alphas.coeffRef(i) =
mS.
diagonal().coeff(i);
328 v.coeffRef(i) =
Scalar(1.0);
330 if(abs(m_betas.coeffRef(i)) >= (std::numeric_limits<RealScalar>::min)())
333 const Scalar alpha = real(m_alphas.coeffRef(i));
334 const Scalar beta = m_betas.coeffRef(i);
335 for (
Index j = i-1; j >= 0; j--)
338 const Index sz = i-j;
339 if (j > 0 &&
mS.coeff(j, j-1) !=
Scalar(0))
342 Matrix<Scalar, 2, 1> rhs = (alpha*
mT.template
block<2,Dynamic>(j-1,
st,2,sz) - beta*
mS.template
block<2,Dynamic>(j-1,
st,2,sz)) .lazyProduct( v.segment(
st,sz) );
349 v.coeffRef(j) = -v.segment(
st,sz).
transpose().cwiseProduct(beta*
mS.block(j,
st,1,sz) - alpha*
mT.block(j,
st,1,sz)).
sum() / (beta*
mS.coeffRef(j,j) - alpha*
mT.coeffRef(j,j));
353 m_eivec.col(i).real().noalias() = m_realQZ.matrixZ().transpose() * v;
368 const RealScalar beta = m_betas.coeffRef(i) = m_betas.coeffRef(i+1) = a*b;
374 Scalar z = sqrt(abs(p * p +
S2.coeff(1,0) *
S2.coeff(0,1)));
376 m_alphas.coeffRef(i) =
conj(alpha);
377 m_alphas.coeffRef(i+1) = alpha;
382 cv.coeffRef(i+1) =
Scalar(1.0);
384 cv.coeffRef(i) = -(
static_cast<Scalar>(beta*
mS.coeffRef(i,i+1)) - alpha*
mT.coeffRef(i,i+1))
385 / (
static_cast<Scalar>(beta*
mS.coeffRef(i,i)) - alpha*
mT.coeffRef(i,i));
386 for (
Index j = i-1; j >= 0; j--)
389 const Index sz = i+1-j;
390 if (j > 0 &&
mS.coeff(j, j-1) !=
Scalar(0))
393 Matrix<ComplexScalar, 2, 1> rhs = (alpha*
mT.template
block<2,Dynamic>(j-1,
st,2,sz) - beta*
mS.template
block<2,Dynamic>(j-1,
st,2,sz)) .lazyProduct( cv.segment(
st,sz) );
398 cv.coeffRef(j) = cv.segment(
st,sz).transpose().cwiseProduct(beta*
mS.block(j,
st,1,sz) - alpha*
mT.block(j,
st,1,sz)).sum()
399 / (alpha*
mT.coeffRef(j,j) -
static_cast<Scalar>(beta*
mS.coeffRef(j,j)));
402 m_eivec.col(i+1).noalias() = (m_realQZ.matrixZ().transpose() * cv);
403 m_eivec.col(i+1).normalize();
404 m_eivec.col(i) = m_eivec.col(i+1).conjugate();
411 m_isInitialized =
true;
EIGEN_DEVICE_FUNC Derived & setConstant(const Scalar &value)
Sets all coefficients in this expression to value val.
Definition CwiseNullaryOp.h:345
EIGEN_DEVICE_FUNC Scalar sum() const
Definition Redux.h:459
EIGEN_DEVICE_FUNC TransposeReturnType transpose()
Definition Transpose.h:182
\eigenvalues_module
Definition GeneralizedEigenSolver.h:59
GeneralizedEigenSolver & compute(const MatrixType &A, const MatrixType &B, bool computeEigenvectors=true)
Computes generalized eigendecomposition of given matrix.
Definition GeneralizedEigenSolver.h:289
GeneralizedEigenSolver(const MatrixType &A, const MatrixType &B, bool computeEigenvectors=true)
Constructor; computes the generalized eigendecomposition of given matrix pair.
Definition GeneralizedEigenSolver.h:155
GeneralizedEigenSolver & setMaxIterations(Index maxIters)
Sets the maximal number of iterations allowed.
Definition GeneralizedEigenSolver.h:264
Eigen::Index Index
Definition GeneralizedEigenSolver.h:76
_MatrixType MatrixType
Synonym for the template parameter _MatrixType.
Definition GeneralizedEigenSolver.h:63
Matrix< Scalar, ColsAtCompileTime, 1, Options &~RowMajor, MaxColsAtCompileTime, 1 > VectorType
Type for vector of real scalar values eigenvalues as returned by betas().
Definition GeneralizedEigenSolver.h:91
EigenvalueType eigenvalues() const
Returns an expression of the computed generalized eigenvalues.
Definition GeneralizedEigenSolver.h:203
ComplexVectorType alphas() const
Definition GeneralizedEigenSolver.h:214
GeneralizedEigenSolver(Index size)
Default constructor with memory preallocation.
Definition GeneralizedEigenSolver.h:133
std::complex< RealScalar > ComplexScalar
Complex scalar type for MatrixType.
Definition GeneralizedEigenSolver.h:84
VectorType betas() const
Definition GeneralizedEigenSolver.h:225
Matrix< ComplexScalar, ColsAtCompileTime, 1, Options &~RowMajor, MaxColsAtCompileTime, 1 > ComplexVectorType
Type for vector of complex scalar values eigenvalues as returned by alphas().
Definition GeneralizedEigenSolver.h:98
CwiseBinaryOp< internal::scalar_quotient_op< ComplexScalar, Scalar >, ComplexVectorType, VectorType > EigenvalueType
Expression type for the eigenvalues as returned by eigenvalues().
Definition GeneralizedEigenSolver.h:102
GeneralizedEigenSolver()
Default constructor.
Definition GeneralizedEigenSolver.h:118
MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.
Definition GeneralizedEigenSolver.h:74
Matrix< ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime > EigenvectorsType
Type for matrix of eigenvectors as returned by eigenvectors().
Definition GeneralizedEigenSolver.h:109
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
EIGEN_DEVICE_FUNC const DiagonalWrapper< const Derived > asDiagonal() const
Definition DiagonalMatrix.h:325
const PartialPivLU< PlainObject > partialPivLu() const
\lu_module
Definition PartialPivLU.h:602
EIGEN_DEVICE_FUNC void normalize()
Normalizes the vector, i.e.
Definition Dot.h:140
EIGEN_DEVICE_FUNC DiagonalReturnType diagonal()
Definition Diagonal.h:187
ComputationInfo info() const
Reports whether previous computation was successful.
Definition RealQZ.h:169
RealQZ & setMaxIterations(Index maxIters)
Sets the maximal number of iterations allowed to converge to one eigenvalue or decouple the problem.
Definition RealQZ.h:186
ComputationInfo
Enum for reporting the status of a computation.
Definition Constants.h:440
@ Success
Computation was successful.
Definition Constants.h:442
Namespace containing all symbols from the Eigen library.
Definition LDLT.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
Holds information about the various numeric (i.e.
Definition NumTraits.h:236