12 #ifndef EIGEN_GENERALIZEDEIGENSOLVER_H
13 #define EIGEN_GENERALIZEDEIGENSOLVER_H
74 typedef typename MatrixType::Scalar
Scalar;
164 compute(A, B, computeEigenvectors);
285 template<
typename MatrixType>
289 check_template_parameters();
293 eigen_assert(A.cols() == A.rows() && B.cols() == A.rows() && B.cols() == B.rows());
295 m_valuesOkay =
false;
296 m_vectorsOkay =
false;
299 m_realQZ.compute(A, B, computeEigenvectors);
300 if (m_realQZ.info() ==
Success)
303 m_alphas.resize(
size);
304 m_betas.resize(
size);
305 if (computeEigenvectors)
320 if (i ==
size - 1 || mS.coeff(i+1, i) ==
Scalar(0))
323 m_alphas.
coeffRef(i) = mS.diagonal().coeff(i);
324 m_betas.coeffRef(i) = mT.diagonal().coeff(i);
325 if (computeEigenvectors)
327 v.setConstant(
Scalar(0.0));
328 v.coeffRef(i) =
Scalar(1.0);
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--)
337 const Index st = j+1;
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) );
343 Matrix<Scalar, 2, 2> lhs = beta * mS.template block<2,2>(j-1,j-1) - alpha * mT.template block<2,2>(j-1,j-1);
344 v.template segment<2>(j-1) = lhs.partialPivLu().solve(rhs);
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;
354 m_eivec.col(i).real().normalize();
355 m_eivec.col(i).imag().setConstant(0);
367 b = mT.diagonal().coeff(i+1);
368 const RealScalar beta = m_betas.coeffRef(i) = m_betas.coeffRef(i+1) =
a*b;
376 m_alphas.coeffRef(i) = conj(alpha);
377 m_alphas.coeffRef(i+1) = alpha;
379 if (computeEigenvectors) {
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--)
388 const Index st = j+1;
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) );
395 cv.template segment<2>(j-1) = lhs.partialPivLu().solve(rhs);
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_vectorsOkay = computeEigenvectors;
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const AbsReturnType abs() const
Definition: ArrayCwiseUnaryOps.h:52
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Definition: ArrayCwiseUnaryOps.h:187
EIGEN_DEVICE_FUNC RealReturnType real() const
Definition: CommonCwiseUnaryOps.h:100
#define eigen_assert(x)
Definition: Macros.h:1037
#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE)
Definition: StaticAssert.h:187
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:127
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:84
Computes the generalized eigenvalues and eigenvectors of a pair of general matrices.
Definition: GeneralizedEigenSolver.h:59
bool m_valuesOkay
Definition: GeneralizedEigenSolver.h:280
bool m_vectorsOkay
Definition: GeneralizedEigenSolver.h:280
RealQZ< MatrixType > m_realQZ
Definition: GeneralizedEigenSolver.h:281
GeneralizedEigenSolver & compute(const MatrixType &A, const MatrixType &B, bool computeEigenvectors=true)
Computes generalized eigendecomposition of given matrix.
Definition: GeneralizedEigenSolver.h:287
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)
Definition: GeneralizedEigenSolver.h:263
NumTraits< Scalar >::Real RealScalar
Definition: GeneralizedEigenSolver.h:75
@ Options
Definition: GeneralizedEigenSolver.h:68
@ ColsAtCompileTime
Definition: GeneralizedEigenSolver.h:67
@ MaxRowsAtCompileTime
Definition: GeneralizedEigenSolver.h:69
@ RowsAtCompileTime
Definition: GeneralizedEigenSolver.h:66
@ MaxColsAtCompileTime
Definition: GeneralizedEigenSolver.h:70
EigenvectorsType eigenvectors() const
Definition: GeneralizedEigenSolver.h:179
Eigen::Index Index
Definition: GeneralizedEigenSolver.h:76
VectorType m_betas
Definition: GeneralizedEigenSolver.h:279
_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:202
ComplexVectorType m_tmp
Definition: GeneralizedEigenSolver.h:282
ComplexVectorType alphas() const
Definition: GeneralizedEigenSolver.h:213
static void check_template_parameters()
Definition: GeneralizedEigenSolver.h:271
EigenvectorsType m_eivec
Definition: GeneralizedEigenSolver.h:277
GeneralizedEigenSolver(Index size)
Default constructor with memory preallocation.
Definition: GeneralizedEigenSolver.h:133
ComputationInfo info() const
Definition: GeneralizedEigenSolver.h:255
std::complex< RealScalar > ComplexScalar
Complex scalar type for MatrixType.
Definition: GeneralizedEigenSolver.h:84
VectorType betas() const
Definition: GeneralizedEigenSolver.h:224
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
ComplexVectorType m_alphas
Definition: GeneralizedEigenSolver.h:278
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
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
Definition: PlainObjectBase.h:175
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:562
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & coeff(Index rowId, Index colId) const
Definition: PlainObjectBase.h:152
RealQZ & setMaxIterations(Index maxIters)
Definition: RealQZ.h:186
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: RealQZ.h:169
ComputationInfo
Definition: Constants.h:440
@ Success
Definition: Constants.h:442
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16() min(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:571
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
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
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1181
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:233