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.

84 lines
2.3 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 zeroReduction(const MatrixType& m) {
  11. // Reductions that must hold for zero sized objects
  12. VERIFY(m.all());
  13. VERIFY(!m.any());
  14. VERIFY(m.prod()==1);
  15. VERIFY(m.sum()==0);
  16. VERIFY(m.count()==0);
  17. VERIFY(m.allFinite());
  18. VERIFY(!m.hasNaN());
  19. }
  20. template<typename MatrixType> void zeroSizedMatrix()
  21. {
  22. MatrixType t1;
  23. if (MatrixType::SizeAtCompileTime == Dynamic || MatrixType::SizeAtCompileTime == 0)
  24. {
  25. zeroReduction(t1);
  26. if (MatrixType::RowsAtCompileTime == Dynamic)
  27. VERIFY(t1.rows() == 0);
  28. if (MatrixType::ColsAtCompileTime == Dynamic)
  29. VERIFY(t1.cols() == 0);
  30. if (MatrixType::RowsAtCompileTime == Dynamic && MatrixType::ColsAtCompileTime == Dynamic)
  31. {
  32. MatrixType t2(0, 0);
  33. VERIFY(t2.rows() == 0);
  34. VERIFY(t2.cols() == 0);
  35. zeroReduction(t2);
  36. VERIFY(t1==t2);
  37. }
  38. }
  39. }
  40. template<typename VectorType> void zeroSizedVector()
  41. {
  42. VectorType t1;
  43. if (VectorType::SizeAtCompileTime == Dynamic || VectorType::SizeAtCompileTime==0)
  44. {
  45. zeroReduction(t1);
  46. VERIFY(t1.size() == 0);
  47. VectorType t2(DenseIndex(0)); // DenseIndex disambiguates with 0-the-null-pointer (error with gcc 4.4 and MSVC8)
  48. VERIFY(t2.size() == 0);
  49. zeroReduction(t2);
  50. VERIFY(t1==t2);
  51. }
  52. }
  53. void test_zerosized()
  54. {
  55. zeroSizedMatrix<Matrix2d>();
  56. zeroSizedMatrix<Matrix3i>();
  57. zeroSizedMatrix<Matrix<float, 2, Dynamic> >();
  58. zeroSizedMatrix<MatrixXf>();
  59. zeroSizedMatrix<Matrix<float, 0, 0> >();
  60. zeroSizedMatrix<Matrix<float, Dynamic, 0, 0, 0, 0> >();
  61. zeroSizedMatrix<Matrix<float, 0, Dynamic, 0, 0, 0> >();
  62. zeroSizedMatrix<Matrix<float, Dynamic, Dynamic, 0, 0, 0> >();
  63. zeroSizedMatrix<Matrix<float, 0, 4> >();
  64. zeroSizedMatrix<Matrix<float, 4, 0> >();
  65. zeroSizedVector<Vector2d>();
  66. zeroSizedVector<Vector3i>();
  67. zeroSizedVector<VectorXf>();
  68. zeroSizedVector<Matrix<float, 0, 1> >();
  69. zeroSizedVector<Matrix<float, 1, 0> >();
  70. }