Home | History | Annotate | Download | only in test
      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 (at) 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 template<typename MatrixType> void zeroSizedMatrix()
     13 {
     14   MatrixType t1;
     15 
     16   if (MatrixType::SizeAtCompileTime == Dynamic)
     17   {
     18     if (MatrixType::RowsAtCompileTime == Dynamic)
     19       VERIFY(t1.rows() == 0);
     20     if (MatrixType::ColsAtCompileTime == Dynamic)
     21       VERIFY(t1.cols() == 0);
     22 
     23     if (MatrixType::RowsAtCompileTime == Dynamic && MatrixType::ColsAtCompileTime == Dynamic)
     24     {
     25       MatrixType t2(0, 0);
     26       VERIFY(t2.rows() == 0);
     27       VERIFY(t2.cols() == 0);
     28     }
     29   }
     30 }
     31 
     32 template<typename VectorType> void zeroSizedVector()
     33 {
     34   VectorType t1;
     35 
     36   if (VectorType::SizeAtCompileTime == Dynamic)
     37   {
     38     VERIFY(t1.size() == 0);
     39     VectorType t2(DenseIndex(0)); // DenseIndex disambiguates with 0-the-null-pointer (error with gcc 4.4 and MSVC8)
     40     VERIFY(t2.size() == 0);
     41   }
     42 }
     43 
     44 void test_zerosized()
     45 {
     46   zeroSizedMatrix<Matrix2d>();
     47   zeroSizedMatrix<Matrix3i>();
     48   zeroSizedMatrix<Matrix<float, 2, Dynamic> >();
     49   zeroSizedMatrix<MatrixXf>();
     50   zeroSizedMatrix<Matrix<float, 0, 0> >();
     51   zeroSizedMatrix<Matrix<float, Dynamic, 0, 0, 0, 0> >();
     52   zeroSizedMatrix<Matrix<float, 0, Dynamic, 0, 0, 0> >();
     53   zeroSizedMatrix<Matrix<float, Dynamic, Dynamic, 0, 0, 0> >();
     54 
     55   zeroSizedVector<Vector2d>();
     56   zeroSizedVector<Vector3i>();
     57   zeroSizedVector<VectorXf>();
     58   zeroSizedVector<Matrix<float, 0, 1> >();
     59 }
     60