You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.7 KiB

  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. #include "main.h"
  10. template<typename MatrixType> void zeroSizedMatrix()
  11. {
  12. MatrixType t1;
  13. if (MatrixType::SizeAtCompileTime == Dynamic)
  14. {
  15. if (MatrixType::RowsAtCompileTime == Dynamic)
  16. VERIFY(t1.rows() == 0);
  17. if (MatrixType::ColsAtCompileTime == Dynamic)
  18. VERIFY(t1.cols() == 0);
  19. if (MatrixType::RowsAtCompileTime == Dynamic && MatrixType::ColsAtCompileTime == Dynamic)
  20. {
  21. MatrixType t2(0, 0);
  22. VERIFY(t2.rows() == 0);
  23. VERIFY(t2.cols() == 0);
  24. }
  25. }
  26. }
  27. template<typename VectorType> void zeroSizedVector()
  28. {
  29. VectorType t1;
  30. if (VectorType::SizeAtCompileTime == Dynamic)
  31. {
  32. VERIFY(t1.size() == 0);
  33. VectorType t2(DenseIndex(0)); // DenseIndex disambiguates with 0-the-null-pointer (error with gcc 4.4 and MSVC8)
  34. VERIFY(t2.size() == 0);
  35. }
  36. }
  37. void test_zerosized()
  38. {
  39. zeroSizedMatrix<Matrix2d>();
  40. zeroSizedMatrix<Matrix3i>();
  41. zeroSizedMatrix<Matrix<float, 2, Dynamic> >();
  42. zeroSizedMatrix<MatrixXf>();
  43. zeroSizedMatrix<Matrix<float, 0, 0> >();
  44. zeroSizedMatrix<Matrix<float, Dynamic, 0, 0, 0, 0> >();
  45. zeroSizedMatrix<Matrix<float, 0, Dynamic, 0, 0, 0> >();
  46. zeroSizedMatrix<Matrix<float, Dynamic, Dynamic, 0, 0, 0> >();
  47. zeroSizedVector<Vector2d>();
  48. zeroSizedVector<Vector3i>();
  49. zeroSizedVector<VectorXf>();
  50. zeroSizedVector<Matrix<float, 0, 1> >();
  51. }