schur_real.cpp File Reference
#include "main.h"
#include <limits>
#include <Eigen/Eigenvalues>

Functions

template<typename MatrixType >
void verifyIsQuasiTriangular (const MatrixType &T)
 
template<typename MatrixType >
void schur (int size=MatrixType::ColsAtCompileTime)
 
void test_bug2633 ()
 
 EIGEN_DECLARE_TEST (schur_real)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( schur_real  )
107  {
108  CALL_SUBTEST_1((schur<Matrix4f>()));
109  CALL_SUBTEST_2((schur<MatrixXd>(internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 4))));
112 
113  // Test problem size constructors
115 
117 }
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Performs a real Schur decomposition of a square matrix.
Definition: RealSchur.h:58
void schur(int size=MatrixType::ColsAtCompileTime)
Definition: schur_real.cpp:39
void test_bug2633()
Definition: schur_real.cpp:100
#define CALL_SUBTEST_6(FUNC)
Definition: split_test_helper.h:34
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22

References CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, CALL_SUBTEST_6, EIGEN_TEST_MAX_SIZE, schur(), and test_bug2633().

◆ schur()

template<typename MatrixType >
void schur ( int  size = MatrixType::ColsAtCompileTime)
39  {
40  // Test basic functionality: T is quasi-triangular and A = U T U*
41  for (int counter = 0; counter < g_repeat; ++counter) {
42  MatrixType A = MatrixType::Random(size, size);
45  MatrixType U = schurOfA.matrixU();
46  MatrixType T = schurOfA.matrixT();
48  VERIFY_IS_APPROX(A, U * T * U.transpose());
49  }
50 
51  // Test asserts when not initialized
52  RealSchur<MatrixType> rsUninitialized;
53  VERIFY_RAISES_ASSERT(rsUninitialized.matrixT());
54  VERIFY_RAISES_ASSERT(rsUninitialized.matrixU());
55  VERIFY_RAISES_ASSERT(rsUninitialized.info());
56 
57  // Test whether compute() and constructor returns same result
58  MatrixType A = MatrixType::Random(size, size);
60  rs1.compute(A);
63  VERIFY_IS_EQUAL(rs2.info(), Success);
64  VERIFY_IS_EQUAL(rs1.matrixT(), rs2.matrixT());
65  VERIFY_IS_EQUAL(rs1.matrixU(), rs2.matrixU());
66 
67  // Test maximum number of iterations
71  VERIFY_IS_EQUAL(rs3.matrixT(), rs1.matrixT());
72  VERIFY_IS_EQUAL(rs3.matrixU(), rs1.matrixU());
73  if (size > 2) {
74  rs3.setMaxIterations(1).compute(A);
77  }
78 
79  MatrixType Atriangular = A;
80  Atriangular.template triangularView<StrictlyLower>().setZero();
81  rs3.setMaxIterations(1).compute(Atriangular); // triangular matrices do not need any iterations
83  VERIFY_IS_APPROX(rs3.matrixT(), Atriangular); // approx because of scaling...
84  VERIFY_IS_EQUAL(rs3.matrixU(), MatrixType::Identity(size, size));
85 
86  // Test computation of only T, not U
87  RealSchur<MatrixType> rsOnlyT(A, false);
88  VERIFY_IS_EQUAL(rsOnlyT.info(), Success);
89  VERIFY_IS_EQUAL(rs1.matrixT(), rsOnlyT.matrixT());
90  VERIFY_RAISES_ASSERT(rsOnlyT.matrixU());
91 
92  if (size > 2 && size < 20) {
93  // Test matrix with NaN
94  A(0, 0) = std::numeric_limits<typename MatrixType::Scalar>::quiet_NaN();
95  RealSchur<MatrixType> rsNaN(A);
96  VERIFY_IS_EQUAL(rsNaN.info(), NoConvergence);
97  }
98 }
cout<< "Here is a random 4x4 matrix, A:"<< endl<< A<< endl<< endl;ComplexSchur< MatrixXcf > schurOfA(A, false)
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
RealSchur & setMaxIterations(Index maxIters)
Sets the maximum number of iterations allowed.
Definition: RealSchur.h:204
const MatrixType & matrixU() const
Returns the orthogonal matrix in the Schur decomposition.
Definition: RealSchur.h:128
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: RealSchur.h:194
Index getMaxIterations()
Returns the maximum number of iterations.
Definition: RealSchur.h:210
const MatrixType & matrixT() const
Returns the quasi-triangular matrix in the Schur decomposition.
Definition: RealSchur.h:144
RealSchur & compute(const EigenBase< InputType > &matrix, bool computeU=true)
Computes Schur decomposition of given matrix.
@ Success
Definition: Constants.h:440
@ NoConvergence
Definition: Constants.h:444
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
#define VERIFY_RAISES_ASSERT(a)
Definition: main.h:329
static int g_repeat
Definition: main.h:191
double U
Swimming speed.
Definition: two_d_variable_diff_adapt.cc:53
void verifyIsQuasiTriangular(const MatrixType &T)
Definition: schur_real.cpp:15

References Eigen::RealSchur< MatrixType_ >::compute(), Eigen::g_repeat, Eigen::RealSchur< MatrixType_ >::getMaxIterations(), Eigen::RealSchur< MatrixType_ >::info(), Eigen::RealSchur< MatrixType_ >::matrixT(), Eigen::RealSchur< MatrixType_ >::matrixU(), Eigen::NoConvergence, schurOfA(), Eigen::RealSchur< MatrixType_ >::setMaxIterations(), size, Eigen::Success, RachelsAdvectionDiffusion::U, VERIFY_IS_APPROX, VERIFY_IS_EQUAL, VERIFY_RAISES_ASSERT, and verifyIsQuasiTriangular().

Referenced by EIGEN_DECLARE_TEST(), and test_bug2633().

◆ test_bug2633()

void test_bug2633 ( )
100  {
101  Eigen::MatrixXd A(4, 4);
102  A << 0, 0, 0, -2, 1, 0, 0, -0, 0, 1, 0, 2, 0, 0, 2, -0;
104  VERIFY(schur.info() == Eigen::Success);
105 }
#define VERIFY(a)
Definition: main.h:362

References schur(), Eigen::Success, and VERIFY.

Referenced by EIGEN_DECLARE_TEST().

◆ verifyIsQuasiTriangular()

template<typename MatrixType >
void verifyIsQuasiTriangular ( const MatrixType T)
15  {
16  const Index size = T.cols();
17  typedef typename MatrixType::Scalar Scalar;
18 
19  // Check T is lower Hessenberg
20  for (int row = 2; row < size; ++row) {
21  for (int col = 0; col < row - 1; ++col) {
23  }
24  }
25 
26  // Check that any non-zero on the subdiagonal is followed by a zero and is
27  // part of a 2x2 diagonal block with imaginary eigenvalues.
28  for (int row = 1; row < size; ++row) {
29  if (!numext::is_exactly_zero(T(row, row - 1))) {
30  VERIFY(row == size - 1 || numext::is_exactly_zero(T(row + 1, row)));
31  Scalar tr = T(row - 1, row - 1) + T(row, row);
32  Scalar det = T(row - 1, row - 1) * T(row, row) - T(row - 1, row) * T(row, row - 1);
33  VERIFY(4 * det > tr * tr);
34  }
35  }
36 }
Eigen::Triplet< double > T
Definition: EigenUnitTest.cpp:11
m col(1)
m row(1)
SCALAR Scalar
Definition: bench_gemm.cpp:45
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool is_exactly_zero(const X &x)
Definition: Meta.h:592
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83

References col(), Eigen::numext::is_exactly_zero(), row(), size, VERIFY, and VERIFY_IS_EQUAL.

Referenced by schur().