aboutsummaryrefslogtreecommitdiff
path: root/Eigen/src/Eigenvalues/RealSchur.h
diff options
context:
space:
mode:
Diffstat (limited to 'Eigen/src/Eigenvalues/RealSchur.h')
-rw-r--r--Eigen/src/Eigenvalues/RealSchur.h41
1 files changed, 31 insertions, 10 deletions
diff --git a/Eigen/src/Eigenvalues/RealSchur.h b/Eigen/src/Eigenvalues/RealSchur.h
index 16d387537..f5c86041d 100644
--- a/Eigen/src/Eigenvalues/RealSchur.h
+++ b/Eigen/src/Eigenvalues/RealSchur.h
@@ -64,7 +64,7 @@ template<typename _MatrixType> class RealSchur
};
typedef typename MatrixType::Scalar Scalar;
typedef std::complex<typename NumTraits<Scalar>::Real> ComplexScalar;
- typedef typename MatrixType::Index Index;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> EigenvalueType;
typedef Matrix<Scalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> ColumnVectorType;
@@ -80,7 +80,7 @@ template<typename _MatrixType> class RealSchur
*
* \sa compute() for an example.
*/
- RealSchur(Index size = RowsAtCompileTime==Dynamic ? 1 : RowsAtCompileTime)
+ explicit RealSchur(Index size = RowsAtCompileTime==Dynamic ? 1 : RowsAtCompileTime)
: m_matT(size, size),
m_matU(size, size),
m_workspaceVector(size),
@@ -100,7 +100,8 @@ template<typename _MatrixType> class RealSchur
* Example: \include RealSchur_RealSchur_MatrixType.cpp
* Output: \verbinclude RealSchur_RealSchur_MatrixType.out
*/
- RealSchur(const MatrixType& matrix, bool computeU = true)
+ template<typename InputType>
+ explicit RealSchur(const EigenBase<InputType>& matrix, bool computeU = true)
: m_matT(matrix.rows(),matrix.cols()),
m_matU(matrix.rows(),matrix.cols()),
m_workspaceVector(matrix.rows()),
@@ -109,7 +110,7 @@ template<typename _MatrixType> class RealSchur
m_matUisUptodate(false),
m_maxIters(-1)
{
- compute(matrix, computeU);
+ compute(matrix.derived(), computeU);
}
/** \brief Returns the orthogonal matrix in the Schur decomposition.
@@ -165,7 +166,8 @@ template<typename _MatrixType> class RealSchur
*
* \sa compute(const MatrixType&, bool, Index)
*/
- RealSchur& compute(const MatrixType& matrix, bool computeU = true);
+ template<typename InputType>
+ RealSchur& compute(const EigenBase<InputType>& matrix, bool computeU = true);
/** \brief Computes Schur decomposition of a Hessenberg matrix H = Z T Z^T
* \param[in] matrixH Matrix in Hessenberg form H
@@ -243,26 +245,45 @@ template<typename _MatrixType> class RealSchur
template<typename MatrixType>
-RealSchur<MatrixType>& RealSchur<MatrixType>::compute(const MatrixType& matrix, bool computeU)
+template<typename InputType>
+RealSchur<MatrixType>& RealSchur<MatrixType>::compute(const EigenBase<InputType>& matrix, bool computeU)
{
+ const Scalar considerAsZero = (std::numeric_limits<Scalar>::min)();
+
eigen_assert(matrix.cols() == matrix.rows());
Index maxIters = m_maxIters;
if (maxIters == -1)
maxIters = m_maxIterationsPerRow * matrix.rows();
+ Scalar scale = matrix.derived().cwiseAbs().maxCoeff();
+ if(scale<considerAsZero)
+ {
+ m_matT.setZero(matrix.rows(),matrix.cols());
+ if(computeU)
+ m_matU.setIdentity(matrix.rows(),matrix.cols());
+ m_info = Success;
+ m_isInitialized = true;
+ m_matUisUptodate = computeU;
+ return *this;
+ }
+
// Step 1. Reduce to Hessenberg form
- m_hess.compute(matrix);
+ m_hess.compute(matrix.derived()/scale);
// Step 2. Reduce to real Schur form
computeFromHessenberg(m_hess.matrixH(), m_hess.matrixQ(), computeU);
+
+ m_matT *= scale;
return *this;
}
template<typename MatrixType>
template<typename HessMatrixType, typename OrthMatrixType>
RealSchur<MatrixType>& RealSchur<MatrixType>::computeFromHessenberg(const HessMatrixType& matrixH, const OrthMatrixType& matrixQ, bool computeU)
-{
- m_matT = matrixH;
+{
+ using std::abs;
+
+ m_matT = matrixH;
if(computeU)
m_matU = matrixQ;
@@ -343,7 +364,7 @@ inline typename MatrixType::Scalar RealSchur<MatrixType>::computeNormOfT()
/** \internal Look for single small sub-diagonal element and returns its index */
template<typename MatrixType>
-inline typename MatrixType::Index RealSchur<MatrixType>::findSmallSubdiagEntry(Index iu)
+inline Index RealSchur<MatrixType>::findSmallSubdiagEntry(Index iu)
{
using std::abs;
Index res = iu;