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

Macros

#define EIGEN_RUNTIME_NO_MALLOC
 

Functions

template<typename MatrixType >
void real_qz (const MatrixType &m)
 
 EIGEN_DECLARE_TEST (real_qz)
 

Macro Definition Documentation

◆ EIGEN_RUNTIME_NO_MALLOC

#define EIGEN_RUNTIME_NO_MALLOC

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( real_qz  )
79  {
80  int s = 0;
81  for (int i = 0; i < g_repeat; i++) {
82  CALL_SUBTEST_1(real_qz(Matrix4f()));
83  s = internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 4);
84  CALL_SUBTEST_2(real_qz(MatrixXd(s, s)));
85 
86  // some trivial but implementation-wise tricky cases
87  CALL_SUBTEST_2(real_qz(MatrixXd(1, 1)));
88  CALL_SUBTEST_2(real_qz(MatrixXd(2, 2)));
90  CALL_SUBTEST_4(real_qz(Matrix2d()));
91  }
92 
94 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#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
RealScalar s
Definition: level1_cplx_impl.h:130
#define TEST_SET_BUT_UNUSED_VARIABLE(X)
Definition: main.h:139
static int g_repeat
Definition: main.h:191
void real_qz(const MatrixType &m)
Definition: real_qz.cpp:16
#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_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, EIGEN_TEST_MAX_SIZE, Eigen::g_repeat, i, real_qz(), s, and TEST_SET_BUT_UNUSED_VARIABLE.

◆ real_qz()

template<typename MatrixType >
void real_qz ( const MatrixType m)
16  {
17  /* this test covers the following files:
18  RealQZ.h
19  */
20  using std::abs;
21 
22  Index dim = m.cols();
23 
24  MatrixType A = MatrixType::Random(dim, dim), B = MatrixType::Random(dim, dim);
25 
26  // Regression test for bug 985: Randomly set rows or columns to zero
27  Index k = internal::random<Index>(0, dim - 1);
28  switch (internal::random<int>(0, 10)) {
29  case 0:
30  A.row(k).setZero();
31  break;
32  case 1:
33  A.col(k).setZero();
34  break;
35  case 2:
36  B.row(k).setZero();
37  break;
38  case 3:
39  B.col(k).setZero();
40  break;
41  default:
42  break;
43  }
44 
46  // TODO enable full-prealocation of required memory, this probably requires an in-place mode for
47  // HessenbergDecomposition
48  // Eigen::internal::set_is_malloc_allowed(false);
49  qz.compute(A, B);
50  // Eigen::internal::set_is_malloc_allowed(true);
51 
52  VERIFY_IS_EQUAL(qz.info(), Success);
53  // check for zeros
54  bool all_zeros = true;
55  for (Index i = 0; i < A.cols(); i++)
56  for (Index j = 0; j < i; j++) {
57  if (!numext::is_exactly_zero(abs(qz.matrixT()(i, j)))) {
58  std::cerr << "Error: T(" << i << "," << j << ") = " << qz.matrixT()(i, j) << std::endl;
59  all_zeros = false;
60  }
61  if (j < i - 1 && !numext::is_exactly_zero(abs(qz.matrixS()(i, j)))) {
62  std::cerr << "Error: S(" << i << "," << j << ") = " << qz.matrixS()(i, j) << std::endl;
63  all_zeros = false;
64  }
65  if (j == i - 1 && j > 0 && !numext::is_exactly_zero(abs(qz.matrixS()(i, j))) &&
66  !numext::is_exactly_zero(abs(qz.matrixS()(i - 1, j - 1)))) {
67  std::cerr << "Error: S(" << i << "," << j << ") = " << qz.matrixS()(i, j) << " && S(" << i - 1 << "," << j - 1
68  << ") = " << qz.matrixS()(i - 1, j - 1) << std::endl;
69  all_zeros = false;
70  }
71  }
72  VERIFY_IS_EQUAL(all_zeros, true);
73  VERIFY_IS_APPROX(qz.matrixQ() * qz.matrixS() * qz.matrixZ(), A);
74  VERIFY_IS_APPROX(qz.matrixQ() * qz.matrixT() * qz.matrixZ(), B);
75  VERIFY_IS_APPROX(qz.matrixQ() * qz.matrixQ().adjoint(), MatrixType::Identity(dim, dim));
76  VERIFY_IS_APPROX(qz.matrixZ() * qz.matrixZ().adjoint(), MatrixType::Identity(dim, dim));
77 }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
RealQZ< MatrixXf > qz(4)
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:192
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:569
Definition: matrices.h:74
@ Success
Definition: Constants.h:440
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
int * m
Definition: level2_cplx_impl.h:294
char char char int int * k
Definition: level2_impl.h:374
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
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
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References abs(), Eigen::PlainObjectBase< Derived >::cols(), i, Eigen::numext::is_exactly_zero(), j, k, m, qz(), Eigen::PlainObjectBase< Derived >::setZero(), Eigen::Success, VERIFY_IS_APPROX, and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().