12 #ifndef EIGEN_COMPLEX_SCHUR_H 13 #define EIGEN_COMPLEX_SCHUR_H 56 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
57 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
58 Options = MatrixType::Options,
59 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
60 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
98 m_isInitialized(false),
99 m_matUisUptodate(false),
112 template<
typename InputType>
114 : m_matT(matrix.
rows(),matrix.
cols()),
115 m_matU(matrix.
rows(),matrix.
cols()),
116 m_hess(matrix.
rows()),
117 m_isInitialized(false),
118 m_matUisUptodate(false),
140 eigen_assert(m_isInitialized &&
"ComplexSchur is not initialized.");
141 eigen_assert(m_matUisUptodate &&
"The matrix U has not been computed during the ComplexSchur decomposition.");
164 eigen_assert(m_isInitialized &&
"ComplexSchur is not initialized.");
190 template<
typename InputType>
210 template<
typename HessMatrixType,
typename OrthMatrixType>
211 ComplexSchur& computeFromHessenberg(
const HessMatrixType& matrixH,
const OrthMatrixType& matrixQ,
bool computeU=
true);
219 eigen_assert(m_isInitialized &&
"ComplexSchur is not initialized.");
230 m_maxIters = maxIters;
245 static const int m_maxIterationsPerRow = 30;
256 bool subdiagonalEntryIsNeglegible(Index
i);
257 ComplexScalar computeShift(Index iu, Index
iter);
258 void reduceToTriangularForm(
bool computeU);
265 template<typename MatrixType>
266 inline bool
ComplexSchur<MatrixType>::subdiagonalEntryIsNeglegible(Index i)
268 RealScalar
d = numext::norm1(m_matT.
coeff(
i,
i)) + numext::norm1(m_matT.
coeff(
i+1,
i+1));
269 RealScalar sd = numext::norm1(m_matT.
coeff(
i+1,
i));
280 template<
typename MatrixType>
284 if (iter == 10 || iter == 20)
293 RealScalar normt = t.cwiseAbs().sum();
299 ComplexScalar det = t.
coeff(0,0) * t.
coeff(1,1) -
b;
300 ComplexScalar trace = t.
coeff(0,0) + t.
coeff(1,1);
301 ComplexScalar eival1 = (trace + disc) /
RealScalar(2);
302 ComplexScalar eival2 = (trace - disc) /
RealScalar(2);
303 RealScalar eival1_norm = numext::norm1(eival1);
304 RealScalar eival2_norm = numext::norm1(eival2);
307 if(eival1_norm > eival2_norm)
308 eival2 = det / eival1;
310 eival1 = det / eival2;
313 if(numext::norm1(eival1-t.
coeff(1,1)) < numext::norm1(eival2-t.
coeff(1,1)))
314 return normt * eival1;
316 return normt * eival2;
320 template<
typename MatrixType>
321 template<
typename InputType>
324 m_matUisUptodate =
false;
327 if(matrix.
cols() == 1)
329 m_matT = matrix.
derived().template cast<ComplexScalar>();
330 if(computeU) m_matU = ComplexMatrixType::Identity(1,1);
332 m_isInitialized =
true;
333 m_matUisUptodate = computeU;
338 computeFromHessenberg(m_matT, m_matU, computeU);
342 template<
typename MatrixType>
343 template<
typename HessMatrixType,
typename OrthMatrixType>
349 reduceToTriangularForm(computeU);
355 template<
typename MatrixType,
bool IsComplex>
356 struct complex_schur_reduce_to_hessenberg
367 template<
typename MatrixType>
381 _this.
m_matU = Q.template cast<ComplexScalar>();
389 template<
typename MatrixType>
392 Index maxIters = m_maxIters;
394 maxIters = m_maxIterationsPerRow * m_matT.
rows();
400 Index iu = m_matT.
cols() - 1;
410 if(!subdiagonalEntryIsNeglegible(iu-1))
break;
421 if(totalIter > maxIters)
break;
425 while(il > 0 && !subdiagonalEntryIsNeglegible(il-1))
434 ComplexScalar shift = computeShift(iu, iter);
437 m_matT.rightCols(m_matT.
cols()-il).applyOnTheLeft(il, il+1, rot.
adjoint());
438 m_matT.topRows((
std::min)(il+2,iu)+1).applyOnTheRight(il, il+1, rot);
439 if(computeU) m_matU.applyOnTheRight(il, il+1, rot);
441 for(Index
i=il+1 ;
i<iu ;
i++)
445 m_matT.rightCols(m_matT.
cols()-
i).applyOnTheLeft(
i,
i+1, rot.
adjoint());
446 m_matT.topRows((
std::min)(
i+2,iu)+1).applyOnTheRight(
i,
i+1, rot);
447 if(computeU) m_matU.applyOnTheRight(
i,
i+1, rot);
451 if(totalIter <= maxIters)
456 m_isInitialized =
true;
457 m_matUisUptodate = computeU;
462 #endif // EIGEN_COMPLEX_SCHUR_H
int EIGEN_BLAS_FUNC() rot(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pc, RealScalar *ps)
EIGEN_DEVICE_FUNC bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
NumTraits< Scalar >::Real RealScalar
ComplexSchur(const EigenBase< InputType > &matrix, bool computeU=true)
Constructor; computes Schur decomposition of given matrix.
ComplexSchur & setMaxIterations(Index maxIters)
Sets the maximum number of iterations allowed.
Namespace containing all symbols from the Eigen library.
Rotation given by a cosine-sine pair.
HessenbergDecomposition< MatrixType > m_hess
iterator iter(handle obj)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
ComplexSchur & computeFromHessenberg(const HessMatrixType &matrixH, const OrthMatrixType &matrixQ, bool computeU=true)
Compute Schur decomposition from a given Hessenberg matrix.
std::complex< RealScalar > ComplexScalar
Complex scalar type for _MatrixType.
ComplexSchur & compute(const EigenBase< InputType > &matrix, bool computeU=true)
Computes Schur decomposition of given matrix.
ComputationInfo info() const
Reports whether previous computation was successful.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
Matrix< ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime > ComplexMatrixType
Type for the matrices in the Schur decomposition.
MatrixType::Scalar Scalar
Scalar type for matrices of type _MatrixType.
HessenbergDecomposition & compute(const EigenBase< InputType > &matrix)
Computes Hessenberg decomposition of given matrix.
static void run(ComplexSchur< MatrixType > &_this, const MatrixType &matrix, bool computeU)
MatrixHReturnType matrixH() const
Constructs the Hessenberg matrix H in the decomposition.
EIGEN_DEVICE_FUNC void makeGivens(const Scalar &p, const Scalar &q, Scalar *r=0)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & coeff(Index rowId, Index colId) const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Index getMaxIterations()
Returns the maximum number of iterations.
ComplexSchur(Index size=RowsAtCompileTime==Dynamic ? 1 :RowsAtCompileTime)
Default constructor.
ComplexScalar computeShift(Index iu, Index iter)
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
NumTraits< Scalar >::Real RealScalar
EIGEN_DEVICE_FUNC JacobiRotation adjoint() const
static void run(ComplexSchur< MatrixType > &_this, const MatrixType &matrix, bool computeU)
EIGEN_CONSTEXPR Index size(const T &x)
void reduceToTriangularForm(bool computeU)
const ComplexMatrixType & matrixU() const
Returns the unitary matrix in the Schur decomposition.
HouseholderSequenceType matrixQ() const
Reconstructs the orthogonal matrix Q in the decomposition.
Jet< T, N > sqrt(const Jet< T, N > &f)
EIGEN_DONT_INLINE void compute(Solver &solver, const MatrixType &A)
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Performs a complex Schur decomposition of a real or complex square matrix.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
EIGEN_DEVICE_FUNC Derived & derived()
const ComplexMatrixType & matrixT() const
Returns the triangular matrix in the Schur decomposition.