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
64 typedef typename MatrixType::Scalar
Scalar;
66 typedef typename MatrixType::Index
Index;
98 m_isInitialized(false),
99 m_matUisUptodate(false),
113 : m_matT(matrix.rows(),matrix.cols()),
114 m_matU(matrix.rows(),matrix.cols()),
115 m_hess(matrix.rows()),
116 m_isInitialized(false),
117 m_matUisUptodate(false),
120 compute(matrix, computeU);
139 eigen_assert(m_isInitialized &&
"ComplexSchur is not initialized.");
140 eigen_assert(m_matUisUptodate &&
"The matrix U has not been computed during the ComplexSchur decomposition.");
163 eigen_assert(m_isInitialized &&
"ComplexSchur is not initialized.");
189 ComplexSchur& compute(
const MatrixType& matrix,
bool computeU =
true);
208 template<
typename HessMatrixType,
typename OrthMatrixType>
209 ComplexSchur& computeFromHessenberg(
const HessMatrixType& matrixH,
const OrthMatrixType& matrixQ,
bool computeU=
true);
217 eigen_assert(m_isInitialized &&
"ComplexSchur is not initialized.");
228 m_maxIters = maxIters;
243 static const int m_maxIterationsPerRow = 30;
254 bool subdiagonalEntryIsNeglegible(Index i);
255 ComplexScalar computeShift(Index iu, Index iter);
256 void reduceToTriangularForm(
bool computeU);
264 inline bool
ComplexSchur<MatrixType>::subdiagonalEntryIsNeglegible(Index i)
266 RealScalar
d = numext::norm1(m_matT.
coeff(i,i)) + numext::norm1(m_matT.
coeff(i+1,i+1));
267 RealScalar sd = numext::norm1(m_matT.
coeff(i+1,i));
270 m_matT.
coeffRef(i+1,i) = ComplexScalar(0);
278 template<
typename MatrixType>
282 if (iter == 10 || iter == 20)
291 RealScalar normt = t.cwiseAbs().sum();
294 ComplexScalar b = t.
coeff(0,1) * t.
coeff(1,0);
295 ComplexScalar c = t.
coeff(0,0) - t.
coeff(1,1);
296 ComplexScalar disc =
sqrt(c*c + RealScalar(4)*b);
297 ComplexScalar det = t.
coeff(0,0) * t.
coeff(1,1) - b;
298 ComplexScalar trace = t.
coeff(0,0) + t.
coeff(1,1);
299 ComplexScalar eival1 = (trace + disc) / RealScalar(2);
300 ComplexScalar eival2 = (trace - disc) / RealScalar(2);
302 if(numext::norm1(eival1) > numext::norm1(eival2))
303 eival2 = det / eival1;
305 eival1 = det / eival2;
308 if(numext::norm1(eival1-t.
coeff(1,1)) < numext::norm1(eival2-t.
coeff(1,1)))
309 return normt * eival1;
311 return normt * eival2;
315 template<
typename MatrixType>
318 m_matUisUptodate =
false;
321 if(matrix.cols() == 1)
323 m_matT = matrix.template cast<ComplexScalar>();
324 if(computeU) m_matU = ComplexMatrixType::Identity(1,1);
326 m_isInitialized =
true;
327 m_matUisUptodate = computeU;
332 computeFromHessenberg(m_matT, m_matU, computeU);
336 template<
typename MatrixType>
337 template<
typename HessMatrixType,
typename OrthMatrixType>
343 reduceToTriangularForm(computeU);
349 template<
typename MatrixType,
bool IsComplex>
350 struct complex_schur_reduce_to_hessenberg
361 template<
typename MatrixType>
375 _this.
m_matU = Q.template cast<ComplexScalar>();
383 template<
typename MatrixType>
386 Index maxIters = m_maxIters;
388 maxIters = m_maxIterationsPerRow * m_matT.
rows();
394 Index iu = m_matT.
cols() - 1;
404 if(!subdiagonalEntryIsNeglegible(iu-1))
break;
415 if(totalIter > maxIters)
break;
419 while(il > 0 && !subdiagonalEntryIsNeglegible(il-1))
428 ComplexScalar shift = computeShift(iu, iter);
431 m_matT.rightCols(m_matT.
cols()-il).applyOnTheLeft(il, il+1, rot.
adjoint());
432 m_matT.topRows((std::min)(il+2,iu)+1).applyOnTheRight(il, il+1, rot);
433 if(computeU) m_matU.applyOnTheRight(il, il+1, rot);
435 for(Index i=il+1 ; i<iu ; i++)
438 m_matT.
coeffRef(i+1,i-1) = ComplexScalar(0);
439 m_matT.rightCols(m_matT.
cols()-i).applyOnTheLeft(i, i+1, rot.
adjoint());
440 m_matT.topRows((std::min)(i+2,iu)+1).applyOnTheRight(i, i+1, rot);
441 if(computeU) m_matU.applyOnTheRight(i, i+1, rot);
445 if(totalIter <= maxIters)
450 m_isInitialized =
true;
451 m_matUisUptodate = computeU;
456 #endif // EIGEN_COMPLEX_SCHUR_H
NumTraits< Scalar >::Real RealScalar
ComplexSchur & setMaxIterations(Index maxIters)
Sets the maximum number of iterations allowed.
void makeGivens(const Scalar &p, const Scalar &q, Scalar *z=0)
ComplexSchur & compute(const MatrixType &matrix, bool computeU=true)
Computes Schur decomposition of given matrix.
RealReturnType real() const
Rotation given by a cosine-sine pair.
HessenbergDecomposition< MatrixType > m_hess
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
EIGEN_STRONG_INLINE Index cols() const
bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, typename NumTraits< Scalar >::Real precision=NumTraits< Scalar >::dummy_precision())
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.
ComputationInfo info() const
Reports whether previous computation was successful.
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.
static void run(ComplexSchur< MatrixType > &_this, const MatrixType &matrix, bool computeU)
MatrixHReturnType matrixH() const
Constructs the Hessenberg matrix H in the decomposition.
HessenbergDecomposition & compute(const MatrixType &matrix)
Computes Hessenberg decomposition of given matrix.
EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
Index getMaxIterations()
Returns the maximum number of iterations.
ComplexSchur(Index size=RowsAtCompileTime==Dynamic ? 1 :RowsAtCompileTime)
Default constructor.
ComplexScalar computeShift(Index iu, Index iter)
EIGEN_STRONG_INLINE Index rows() const
static void run(ComplexSchur< MatrixType > &_this, const MatrixType &matrix, bool computeU)
ComplexSchur(const MatrixType &matrix, bool computeU=true)
Constructor; computes Schur decomposition of given matrix.
void reduceToTriangularForm(bool computeU)
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs_op< Scalar >, const Derived > abs() const
const ComplexMatrixType & matrixU() const
Returns the unitary matrix in the Schur decomposition.
HouseholderSequenceType matrixQ() const
Reconstructs the orthogonal matrix Q in the decomposition.
EIGEN_STRONG_INLINE const Scalar & coeff(Index rowId, Index colId) const
Performs a complex Schur decomposition of a real or complex square matrix.
const ComplexMatrixType & matrixT() const
Returns the triangular matrix in the Schur decomposition.
JacobiRotation adjoint() const
const CwiseUnaryOp< internal::scalar_sqrt_op< Scalar >, const Derived > sqrt() const