source: pacpussensors/trunk/Vislab/lib3dv/eigen/test/zerosized.cpp@ 136

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

Doc

File size: 2.3 KB
Line 
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
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
12
13template<typename MatrixType> void zeroReduction(const MatrixType& m) {
14 // Reductions that must hold for zero sized objects
15 VERIFY(m.all());
16 VERIFY(!m.any());
17 VERIFY(m.prod()==1);
18 VERIFY(m.sum()==0);
19 VERIFY(m.count()==0);
20 VERIFY(m.allFinite());
21 VERIFY(!m.hasNaN());
22}
23
24
25template<typename MatrixType> void zeroSizedMatrix()
26{
27 MatrixType t1;
28
29 if (MatrixType::SizeAtCompileTime == Dynamic || MatrixType::SizeAtCompileTime == 0)
30 {
31 zeroReduction(t1);
32 if (MatrixType::RowsAtCompileTime == Dynamic)
33 VERIFY(t1.rows() == 0);
34 if (MatrixType::ColsAtCompileTime == Dynamic)
35 VERIFY(t1.cols() == 0);
36
37 if (MatrixType::RowsAtCompileTime == Dynamic && MatrixType::ColsAtCompileTime == Dynamic)
38 {
39
40 MatrixType t2(0, 0);
41 VERIFY(t2.rows() == 0);
42 VERIFY(t2.cols() == 0);
43
44 zeroReduction(t2);
45 VERIFY(t1==t2);
46 }
47 }
48}
49
50template<typename VectorType> void zeroSizedVector()
51{
52 VectorType t1;
53
54 if (VectorType::SizeAtCompileTime == Dynamic || VectorType::SizeAtCompileTime==0)
55 {
56 zeroReduction(t1);
57 VERIFY(t1.size() == 0);
58 VectorType t2(DenseIndex(0)); // DenseIndex disambiguates with 0-the-null-pointer (error with gcc 4.4 and MSVC8)
59 VERIFY(t2.size() == 0);
60 zeroReduction(t2);
61
62 VERIFY(t1==t2);
63 }
64}
65
66void test_zerosized()
67{
68 zeroSizedMatrix<Matrix2d>();
69 zeroSizedMatrix<Matrix3i>();
70 zeroSizedMatrix<Matrix<float, 2, Dynamic> >();
71 zeroSizedMatrix<MatrixXf>();
72 zeroSizedMatrix<Matrix<float, 0, 0> >();
73 zeroSizedMatrix<Matrix<float, Dynamic, 0, 0, 0, 0> >();
74 zeroSizedMatrix<Matrix<float, 0, Dynamic, 0, 0, 0> >();
75 zeroSizedMatrix<Matrix<float, Dynamic, Dynamic, 0, 0, 0> >();
76 zeroSizedMatrix<Matrix<float, 0, 4> >();
77 zeroSizedMatrix<Matrix<float, 4, 0> >();
78
79 zeroSizedVector<Vector2d>();
80 zeroSizedVector<Vector3i>();
81 zeroSizedVector<VectorXf>();
82 zeroSizedVector<Matrix<float, 0, 1> >();
83 zeroSizedVector<Matrix<float, 1, 0> >();
84}
Note: See TracBrowser for help on using the repository browser.