1 // This file is part of Eigen, a lightweight C++ template library
4 // Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
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/.
13 template<typename MatrixType
> void zeroReduction(const MatrixType
& m
) {
14 // Reductions that must hold for zero sized objects
20 VERIFY(m
.allFinite());
25 template<typename MatrixType
> void zeroSizedMatrix()
28 typedef typename
MatrixType::Scalar Scalar
;
30 if (MatrixType::SizeAtCompileTime
== Dynamic
|| MatrixType::SizeAtCompileTime
== 0)
33 if (MatrixType::RowsAtCompileTime
== Dynamic
)
34 VERIFY(t1
.rows() == 0);
35 if (MatrixType::ColsAtCompileTime
== Dynamic
)
36 VERIFY(t1
.cols() == 0);
38 if (MatrixType::RowsAtCompileTime
== Dynamic
&& MatrixType::ColsAtCompileTime
== Dynamic
)
41 MatrixType
t2(0, 0), t3(t1
);
42 VERIFY(t2
.rows() == 0);
43 VERIFY(t2
.cols() == 0);
50 if(MatrixType::MaxColsAtCompileTime
!=0 && MatrixType::MaxRowsAtCompileTime
!=0)
52 Index rows
= MatrixType::RowsAtCompileTime
==Dynamic
? internal::random
<Index
>(1,10) : Index(MatrixType::RowsAtCompileTime
);
53 Index cols
= MatrixType::ColsAtCompileTime
==Dynamic
? internal::random
<Index
>(1,10) : Index(MatrixType::ColsAtCompileTime
);
54 MatrixType
m(rows
,cols
);
55 zeroReduction(m
.template block
<0,MatrixType::ColsAtCompileTime
>(0,0,0,cols
));
56 zeroReduction(m
.template block
<MatrixType::RowsAtCompileTime
,0>(0,0,rows
,0));
57 zeroReduction(m
.template block
<0,1>(0,0));
58 zeroReduction(m
.template block
<1,0>(0,0));
59 Matrix
<Scalar
,Dynamic
,Dynamic
> prod
= m
.template block
<MatrixType::RowsAtCompileTime
,0>(0,0,rows
,0) * m
.template block
<0,MatrixType::ColsAtCompileTime
>(0,0,0,cols
);
60 VERIFY(prod
.rows()==rows
&& prod
.cols()==cols
);
61 VERIFY(prod
.isZero());
62 prod
= m
.template block
<1,0>(0,0) * m
.template block
<0,1>(0,0);
63 VERIFY(prod
.size()==1);
64 VERIFY(prod
.isZero());
68 template<typename VectorType
> void zeroSizedVector()
72 if (VectorType::SizeAtCompileTime
== Dynamic
|| VectorType::SizeAtCompileTime
==0)
75 VERIFY(t1
.size() == 0);
76 VectorType
t2(DenseIndex(0)); // DenseIndex disambiguates with 0-the-null-pointer (error with gcc 4.4 and MSVC8)
77 VERIFY(t2
.size() == 0);
86 zeroSizedMatrix
<Matrix2d
>();
87 zeroSizedMatrix
<Matrix3i
>();
88 zeroSizedMatrix
<Matrix
<float, 2, Dynamic
> >();
89 zeroSizedMatrix
<MatrixXf
>();
90 zeroSizedMatrix
<Matrix
<float, 0, 0> >();
91 zeroSizedMatrix
<Matrix
<float, Dynamic
, 0, 0, 0, 0> >();
92 zeroSizedMatrix
<Matrix
<float, 0, Dynamic
, 0, 0, 0> >();
93 zeroSizedMatrix
<Matrix
<float, Dynamic
, Dynamic
, 0, 0, 0> >();
94 zeroSizedMatrix
<Matrix
<float, 0, 4> >();
95 zeroSizedMatrix
<Matrix
<float, 4, 0> >();
97 zeroSizedVector
<Vector2d
>();
98 zeroSizedVector
<Vector3i
>();
99 zeroSizedVector
<VectorXf
>();
100 zeroSizedVector
<Matrix
<float, 0, 1> >();
101 zeroSizedVector
<Matrix
<float, 1, 0> >();