12#ifndef EIGEN_GENERALIZEDEIGENSOLVER_H
13#define EIGEN_GENERALIZEDEIGENSOLVER_H
74 typedef typename MatrixType::Scalar
Scalar;
164 compute(A, B, computeEigenvectors);
285template<
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));
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) );
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 RealReturnType real() const
Definition: CommonCwiseUnaryOps.h:100
#define eigen_assert(x)
Definition: Macros.h:1047
#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE)
Definition: StaticAssert.h:187
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:127
constexpr common_return_t< T1, T2 > beta(const T1 a, const T2 b) noexcept
Compile-time beta function.
Definition: beta.hpp:36
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:84
\eigenvalues_module
Definition: GeneralizedEigenSolver.h:59
@ 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
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
NumTraits< Scalar >::Real RealScalar
Definition: GeneralizedEigenSolver.h:75
EigenvectorsType eigenvectors() const
Definition: GeneralizedEigenSolver.h:179
GeneralizedEigenSolver & setMaxIterations(Index maxIters)
Sets the maximal number of iterations allowed.
Definition: GeneralizedEigenSolver.h:263
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 const Scalar & coeff(Index rowId, Index colId) const
This is an overloaded version of DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index,...
Definition: PlainObjectBase.h:152
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
UnitType abs(const UnitType x) noexcept
Compute absolute value.
Definition: math.h:721
auto sqrt(const UnitType &value) noexcept -> unit_t< square_root< typename units::traits::unit_t_traits< UnitType >::unit_type >, typename units::traits::unit_t_traits< UnitType >::underlying_type, linear_scale >
computes the square root of value
Definition: math.h:483
ComputationInfo
Enum for reporting the status of a computation.
Definition: Constants.h:440
@ Success
Computation was successful.
Definition: Constants.h:442
constexpr common_t< T1, T2 > min(const T1 x, const T2 y) noexcept
Compile-time pairwise minimum function.
Definition: min.hpp:35
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
Namespace containing all symbols from the Eigen library.
Definition: Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Definition: VisionPipeline.h:7
Holds information about the various numeric (i.e.
Definition: NumTraits.h:233