zerosized.cpp File Reference
#include "main.h"

Functions

template<typename MatrixType >
void zeroReduction (const MatrixType &m)
 
template<typename MatrixType >
void zeroSizedMatrix ()
 
template<typename VectorType >
void zeroSizedVector ()
 
 EIGEN_DECLARE_TEST (zerosized)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( zerosized  )
88  {
89  zeroSizedMatrix<Matrix2d>();
90  zeroSizedMatrix<Matrix3i>();
91  zeroSizedMatrix<Matrix<float, 2, Dynamic> >();
92  zeroSizedMatrix<MatrixXf>();
93  zeroSizedMatrix<Matrix<float, 0, 0> >();
94  zeroSizedMatrix<Matrix<float, Dynamic, 0, 0, 0, 0> >();
95  zeroSizedMatrix<Matrix<float, 0, Dynamic, 0, 0, 0> >();
96  zeroSizedMatrix<Matrix<float, Dynamic, Dynamic, 0, 0, 0> >();
97  zeroSizedMatrix<Matrix<float, 0, 4> >();
98  zeroSizedMatrix<Matrix<float, 4, 0> >();
99 
100  zeroSizedVector<Vector2d>();
101  zeroSizedVector<Vector3i>();
102  zeroSizedVector<VectorXf>();
103  zeroSizedVector<Matrix<float, 0, 1> >();
104  zeroSizedVector<Matrix<float, 1, 0> >();
105 }

◆ zeroReduction()

template<typename MatrixType >
void zeroReduction ( const MatrixType m)
13  {
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.norm() == 0);
20  VERIFY(m.squaredNorm() == 0);
21  VERIFY(m.count() == 0);
22  VERIFY(m.allFinite());
23  VERIFY(!m.hasNaN());
24  VERIFY_RAISES_ASSERT(m.minCoeff());
25  VERIFY_RAISES_ASSERT(m.maxCoeff());
26  Index i, j;
27  VERIFY_RAISES_ASSERT(m.minCoeff(&i, &j));
28  VERIFY_RAISES_ASSERT(m.maxCoeff(&i, &j));
29  VERIFY_RAISES_ASSERT(m.reshaped().minCoeff(&i));
30  VERIFY_RAISES_ASSERT(m.reshaped().maxCoeff(&i));
31 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
int * m
Definition: level2_cplx_impl.h:294
#define VERIFY(a)
Definition: main.h:362
#define VERIFY_RAISES_ASSERT(a)
Definition: main.h:329
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 i, j, m, VERIFY, and VERIFY_RAISES_ASSERT.

Referenced by zeroSizedMatrix(), and zeroSizedVector().

◆ zeroSizedMatrix()

template<typename MatrixType >
void zeroSizedMatrix ( )
34  {
35  MatrixType t1;
36  typedef typename MatrixType::Scalar Scalar;
37 
38  if (MatrixType::SizeAtCompileTime == Dynamic || MatrixType::SizeAtCompileTime == 0) {
39  zeroReduction(t1);
40  if (MatrixType::RowsAtCompileTime == Dynamic) VERIFY(t1.rows() == 0);
41  if (MatrixType::ColsAtCompileTime == Dynamic) VERIFY(t1.cols() == 0);
42 
43  if (MatrixType::RowsAtCompileTime == Dynamic && MatrixType::ColsAtCompileTime == Dynamic) {
44  MatrixType t2(0, 0);
45  VERIFY(t2.rows() == 0);
46  VERIFY(t2.cols() == 0);
47 
48  zeroReduction(t2);
49  VERIFY(t1 == t2);
50  }
51  }
52 
53  if (MatrixType::MaxColsAtCompileTime != 0 && MatrixType::MaxRowsAtCompileTime != 0) {
54  Index rows = MatrixType::RowsAtCompileTime == Dynamic ? internal::random<Index>(1, 10)
55  : Index(MatrixType::RowsAtCompileTime);
56  Index cols = MatrixType::ColsAtCompileTime == Dynamic ? internal::random<Index>(1, 10)
57  : Index(MatrixType::ColsAtCompileTime);
59  zeroReduction(m.template block<0, MatrixType::ColsAtCompileTime>(0, 0, 0, cols));
60  zeroReduction(m.template block<MatrixType::RowsAtCompileTime, 0>(0, 0, rows, 0));
61  zeroReduction(m.template block<0, 1>(0, 0));
62  zeroReduction(m.template block<1, 0>(0, 0));
63  Matrix<Scalar, Dynamic, Dynamic> prod = m.template block<MatrixType::RowsAtCompileTime, 0>(0, 0, rows, 0) *
64  m.template block<0, MatrixType::ColsAtCompileTime>(0, 0, 0, cols);
65  VERIFY(prod.rows() == rows && prod.cols() == cols);
66  VERIFY(prod.isZero());
67  prod = m.template block<1, 0>(0, 0) * m.template block<0, 1>(0, 0);
68  VERIFY(prod.size() == 1);
69  VERIFY(prod.isZero());
70  }
71 }
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
SCALAR Scalar
Definition: bench_gemm.cpp:45
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
const int Dynamic
Definition: Constants.h:25
EIGEN_DONT_INLINE void prod(const Lhs &a, const Rhs &b, Res &c)
Definition: product_threshold.cpp:53
void zeroReduction(const MatrixType &m)
Definition: zerosized.cpp:13

References cols, Eigen::Dynamic, m, prod(), rows, VERIFY, and zeroReduction().

◆ zeroSizedVector()

template<typename VectorType >
void zeroSizedVector ( )
74  {
75  VectorType t1;
76 
77  if (VectorType::SizeAtCompileTime == Dynamic || VectorType::SizeAtCompileTime == 0) {
78  zeroReduction(t1);
79  VERIFY(t1.size() == 0);
80  VectorType t2(DenseIndex(0)); // DenseIndex disambiguates with 0-the-null-pointer (error with gcc 4.4 and MSVC8)
81  VERIFY(t2.size() == 0);
82  zeroReduction(t2);
83 
84  VERIFY(t1 == t2);
85  }
86 }
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
Definition: Meta.h:75
Definition: fft_test_shared.h:66

References Eigen::Dynamic, VERIFY, and zeroReduction().