source: pacpussensors/trunk/Vislab/lib3dv/eigen/test/real_qz.cpp@ 138

Last change on this file since 138 was 136, checked in by ldecherf, 8 years ago

Doc

File size: 2.4 KB
Line 
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2012 Alexey Korepanov <kaikaikai@yandex.ru>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#include "main.h"
11#include <limits>
12#include <Eigen/Eigenvalues>
13
14template<typename MatrixType> void real_qz(const MatrixType& m)
15{
16 /* this test covers the following files:
17 RealQZ.h
18 */
19 using std::abs;
20 typedef typename MatrixType::Index Index;
21 typedef typename MatrixType::Scalar Scalar;
22
23 Index dim = m.cols();
24
25 MatrixType A = MatrixType::Random(dim,dim),
26 B = MatrixType::Random(dim,dim);
27
28
29 // Regression test for bug 985: Randomly set rows or columns to zero
30 Index k=internal::random<Index>(0, dim-1);
31 switch(internal::random<int>(0,10)) {
32 case 0:
33 A.row(k).setZero(); break;
34 case 1:
35 A.col(k).setZero(); break;
36 case 2:
37 B.row(k).setZero(); break;
38 case 3:
39 B.col(k).setZero(); break;
40 default:
41 break;
42 }
43
44 RealQZ<MatrixType> qz(A,B);
45
46 VERIFY_IS_EQUAL(qz.info(), Success);
47 // check for zeros
48 bool all_zeros = true;
49 for (Index i=0; i<A.cols(); i++)
50 for (Index j=0; j<i; j++) {
51 if (abs(qz.matrixT()(i,j))!=Scalar(0.0))
52 all_zeros = false;
53 if (j<i-1 && abs(qz.matrixS()(i,j))!=Scalar(0.0))
54 all_zeros = false;
55 if (j==i-1 && j>0 && abs(qz.matrixS()(i,j))!=Scalar(0.0) && abs(qz.matrixS()(i-1,j-1))!=Scalar(0.0))
56 all_zeros = false;
57 }
58 VERIFY_IS_EQUAL(all_zeros, true);
59 VERIFY_IS_APPROX(qz.matrixQ()*qz.matrixS()*qz.matrixZ(), A);
60 VERIFY_IS_APPROX(qz.matrixQ()*qz.matrixT()*qz.matrixZ(), B);
61 VERIFY_IS_APPROX(qz.matrixQ()*qz.matrixQ().adjoint(), MatrixType::Identity(dim,dim));
62 VERIFY_IS_APPROX(qz.matrixZ()*qz.matrixZ().adjoint(), MatrixType::Identity(dim,dim));
63}
64
65void test_real_qz()
66{
67 int s = 0;
68 for(int i = 0; i < g_repeat; i++) {
69 CALL_SUBTEST_1( real_qz(Matrix4f()) );
70 s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4);
71 CALL_SUBTEST_2( real_qz(MatrixXd(s,s)) );
72
73 // some trivial but implementation-wise tricky cases
74 CALL_SUBTEST_2( real_qz(MatrixXd(1,1)) );
75 CALL_SUBTEST_2( real_qz(MatrixXd(2,2)) );
76 CALL_SUBTEST_3( real_qz(Matrix<double,1,1>()) );
77 CALL_SUBTEST_4( real_qz(Matrix2d()) );
78 }
79
80 TEST_SET_BUT_UNUSED_VARIABLE(s)
81}
Note: See TracBrowser for help on using the repository browser.