mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
RealSchur: Make sure zeros are really zero (cont'd); add default ctor, docs.
This commit is contained in:
@@ -29,23 +29,19 @@ template<typename MatrixType> void verifyIsQuasiTriangular(const MatrixType& T)
|
||||
{
|
||||
const int size = T.cols();
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
|
||||
// The "zeros" in the real Schur decomposition are only approximately zero
|
||||
RealScalar norm = T.norm();
|
||||
|
||||
// Check T is lower Hessenberg
|
||||
for(int row = 2; row < size; ++row) {
|
||||
for(int col = 0; col < row - 1; ++col) {
|
||||
VERIFY_IS_MUCH_SMALLER_THAN(T(row,col), norm);
|
||||
VERIFY(T(row,col) == Scalar(0));
|
||||
}
|
||||
}
|
||||
|
||||
// Check that any non-zero on the subdiagonal is followed by a zero and is
|
||||
// part of a 2x2 diagonal block with imaginary eigenvalues.
|
||||
for(int row = 1; row < size; ++row) {
|
||||
if (!test_ei_isMuchSmallerThan(T(row,row-1), norm)) {
|
||||
VERIFY(row == size-1 || test_ei_isMuchSmallerThan(T(row+1,row), norm));
|
||||
if (T(row,row-1) != Scalar(0)) {
|
||||
VERIFY(row == size-1 || T(row+1,row) == 0);
|
||||
Scalar tr = T(row-1,row-1) + T(row,row);
|
||||
Scalar det = T(row-1,row-1) * T(row,row) - T(row-1,row) * T(row,row-1);
|
||||
VERIFY(4 * det > tr * tr);
|
||||
@@ -61,9 +57,23 @@ template<typename MatrixType> void schur(int size = MatrixType::ColsAtCompileTim
|
||||
RealSchur<MatrixType> schurOfA(A);
|
||||
MatrixType U = schurOfA.matrixU();
|
||||
MatrixType T = schurOfA.matrixT();
|
||||
std::cout << "T = \n" << T << "\n\n";
|
||||
verifyIsQuasiTriangular(T);
|
||||
VERIFY_IS_APPROX(A, U * T * U.transpose());
|
||||
}
|
||||
|
||||
// Test asserts when not initialized
|
||||
RealSchur<MatrixType> rsUninitialized;
|
||||
VERIFY_RAISES_ASSERT(rsUninitialized.matrixT());
|
||||
VERIFY_RAISES_ASSERT(rsUninitialized.matrixU());
|
||||
|
||||
// Test whether compute() and constructor returns same result
|
||||
MatrixType A = MatrixType::Random(size, size);
|
||||
RealSchur<MatrixType> rs1;
|
||||
rs1.compute(A);
|
||||
RealSchur<MatrixType> rs2(A);
|
||||
VERIFY_IS_EQUAL(rs1.matrixT(), rs2.matrixT());
|
||||
VERIFY_IS_EQUAL(rs1.matrixU(), rs2.matrixU());
|
||||
}
|
||||
|
||||
void test_schur_real()
|
||||
|
||||
Reference in New Issue
Block a user