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

Functions

template<typename MatrixType >
void schur (int size=MatrixType::ColsAtCompileTime)
 
 EIGEN_DECLARE_TEST (schur_complex)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( schur_complex  )
82  {
83  CALL_SUBTEST_1((schur<Matrix4cd>()));
84  CALL_SUBTEST_2((schur<MatrixXcf>(internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 4))));
85  CALL_SUBTEST_3((schur<Matrix<std::complex<float>, 1, 1> >()));
87 
88  // Test problem size constructors
90 }
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
Performs a complex Schur decomposition of a real or complex square matrix.
Definition: ComplexSchur.h:56
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
void schur(int size=MatrixType::ColsAtCompileTime)
Definition: schur_complex.cpp:15
#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, EIGEN_TEST_MAX_SIZE, and schur().

◆ schur()

template<typename MatrixType >
void schur ( int  size = MatrixType::ColsAtCompileTime)
15  {
16  typedef typename ComplexSchur<MatrixType>::ComplexScalar ComplexScalar;
17  typedef typename ComplexSchur<MatrixType>::ComplexMatrixType ComplexMatrixType;
18 
19  // Test basic functionality: T is triangular and A = U T U*
20  for (int counter = 0; counter < g_repeat; ++counter) {
21  MatrixType A = MatrixType::Random(size, size);
24  ComplexMatrixType U = schurOfA.matrixU();
25  ComplexMatrixType T = schurOfA.matrixT();
26  for (int row = 1; row < size; ++row) {
27  for (int col = 0; col < row; ++col) {
28  VERIFY(T(row, col) == (typename MatrixType::Scalar)0);
29  }
30  }
31  VERIFY_IS_APPROX(A.template cast<ComplexScalar>(), U * T * U.adjoint());
32  }
33 
34  // Test asserts when not initialized
35  ComplexSchur<MatrixType> csUninitialized;
36  VERIFY_RAISES_ASSERT(csUninitialized.matrixT());
37  VERIFY_RAISES_ASSERT(csUninitialized.matrixU());
38  VERIFY_RAISES_ASSERT(csUninitialized.info());
39 
40  // Test whether compute() and constructor returns same result
41  MatrixType A = MatrixType::Random(size, size);
43  cs1.compute(A);
46  VERIFY_IS_EQUAL(cs2.info(), Success);
47  VERIFY_IS_EQUAL(cs1.matrixT(), cs2.matrixT());
48  VERIFY_IS_EQUAL(cs1.matrixU(), cs2.matrixU());
49 
50  // Test maximum number of iterations
54  VERIFY_IS_EQUAL(cs3.matrixT(), cs1.matrixT());
55  VERIFY_IS_EQUAL(cs3.matrixU(), cs1.matrixU());
56  cs3.setMaxIterations(1).compute(A);
57  // The schur decomposition does often converge with a single iteration.
58  // VERIFY_IS_EQUAL(cs3.info(), size > 1 ? NoConvergence : Success);
60 
61  MatrixType Atriangular = A;
62  Atriangular.template triangularView<StrictlyLower>().setZero();
63  cs3.setMaxIterations(1).compute(Atriangular); // triangular matrices do not need any iterations
65  VERIFY_IS_EQUAL(cs3.matrixT(), Atriangular.template cast<ComplexScalar>());
66  VERIFY_IS_EQUAL(cs3.matrixU(), ComplexMatrixType::Identity(size, size));
67 
68  // Test computation of only T, not U
69  ComplexSchur<MatrixType> csOnlyT(A, false);
70  VERIFY_IS_EQUAL(csOnlyT.info(), Success);
71  VERIFY_IS_EQUAL(cs1.matrixT(), csOnlyT.matrixT());
72  VERIFY_RAISES_ASSERT(csOnlyT.matrixU());
73 
74  if (size > 1 && size < 20) {
75  // Test matrix with NaN
76  A(0, 0) = std::numeric_limits<typename MatrixType::RealScalar>::quiet_NaN();
78  VERIFY_IS_EQUAL(csNaN.info(), NoConvergence);
79  }
80 }
cout<< "Here is a random 4x4 matrix, A:"<< endl<< A<< endl<< endl;ComplexSchur< MatrixXcf > schurOfA(A, false)
Eigen::Triplet< double > T
Definition: EigenUnitTest.cpp:11
m col(1)
m row(1)
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: ComplexSchur.h:220
const ComplexMatrixType & matrixU() const
Returns the unitary matrix in the Schur decomposition.
Definition: ComplexSchur.h:142
const ComplexMatrixType & matrixT() const
Returns the triangular matrix in the Schur decomposition.
Definition: ComplexSchur.h:165
Index getMaxIterations()
Returns the maximum number of iterations.
Definition: ComplexSchur.h:236
ComplexSchur & setMaxIterations(Index maxIters)
Sets the maximum number of iterations allowed.
Definition: ComplexSchur.h:230
ComplexSchur & 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(a)
Definition: main.h:362
#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

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

Referenced by EIGEN_DECLARE_TEST().