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.

132 lines
4.1 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
  5. // Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com>
  6. //
  7. // This Source Code Form is subject to the terms of the Mozilla
  8. // Public License v. 2.0. If a copy of the MPL was not distributed
  9. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  10. #include "main.h"
  11. #include <Eigen/StdDeque>
  12. #include <Eigen/Geometry>
  13. template<typename MatrixType>
  14. void check_stddeque_matrix(const MatrixType& m)
  15. {
  16. typedef typename MatrixType::Index Index;
  17. Index rows = m.rows();
  18. Index cols = m.cols();
  19. MatrixType x = MatrixType::Random(rows,cols), y = MatrixType::Random(rows,cols);
  20. std::deque<MatrixType,StormEigen::aligned_allocator<MatrixType> > v(10, MatrixType(rows,cols)), w(20, y);
  21. v.front() = x;
  22. w.front() = w.back();
  23. VERIFY_IS_APPROX(w.front(), w.back());
  24. v = w;
  25. typename std::deque<MatrixType,StormEigen::aligned_allocator<MatrixType> >::iterator vi = v.begin();
  26. typename std::deque<MatrixType,StormEigen::aligned_allocator<MatrixType> >::iterator wi = w.begin();
  27. for(int i = 0; i < 20; i++)
  28. {
  29. VERIFY_IS_APPROX(*vi, *wi);
  30. ++vi;
  31. ++wi;
  32. }
  33. v.resize(21);
  34. v.back() = x;
  35. VERIFY_IS_APPROX(v.back(), x);
  36. v.resize(22,y);
  37. VERIFY_IS_APPROX(v.back(), y);
  38. v.push_back(x);
  39. VERIFY_IS_APPROX(v.back(), x);
  40. }
  41. template<typename TransformType>
  42. void check_stddeque_transform(const TransformType&)
  43. {
  44. typedef typename TransformType::MatrixType MatrixType;
  45. TransformType x(MatrixType::Random()), y(MatrixType::Random());
  46. std::deque<TransformType,StormEigen::aligned_allocator<TransformType> > v(10), w(20, y);
  47. v.front() = x;
  48. w.front() = w.back();
  49. VERIFY_IS_APPROX(w.front(), w.back());
  50. v = w;
  51. typename std::deque<TransformType,StormEigen::aligned_allocator<TransformType> >::iterator vi = v.begin();
  52. typename std::deque<TransformType,StormEigen::aligned_allocator<TransformType> >::iterator wi = w.begin();
  53. for(int i = 0; i < 20; i++)
  54. {
  55. VERIFY_IS_APPROX(*vi, *wi);
  56. ++vi;
  57. ++wi;
  58. }
  59. v.resize(21);
  60. v.back() = x;
  61. VERIFY_IS_APPROX(v.back(), x);
  62. v.resize(22,y);
  63. VERIFY_IS_APPROX(v.back(), y);
  64. v.push_back(x);
  65. VERIFY_IS_APPROX(v.back(), x);
  66. }
  67. template<typename QuaternionType>
  68. void check_stddeque_quaternion(const QuaternionType&)
  69. {
  70. typedef typename QuaternionType::Coefficients Coefficients;
  71. QuaternionType x(Coefficients::Random()), y(Coefficients::Random());
  72. std::deque<QuaternionType,StormEigen::aligned_allocator<QuaternionType> > v(10), w(20, y);
  73. v.front() = x;
  74. w.front() = w.back();
  75. VERIFY_IS_APPROX(w.front(), w.back());
  76. v = w;
  77. typename std::deque<QuaternionType,StormEigen::aligned_allocator<QuaternionType> >::iterator vi = v.begin();
  78. typename std::deque<QuaternionType,StormEigen::aligned_allocator<QuaternionType> >::iterator wi = w.begin();
  79. for(int i = 0; i < 20; i++)
  80. {
  81. VERIFY_IS_APPROX(*vi, *wi);
  82. ++vi;
  83. ++wi;
  84. }
  85. v.resize(21);
  86. v.back() = x;
  87. VERIFY_IS_APPROX(v.back(), x);
  88. v.resize(22,y);
  89. VERIFY_IS_APPROX(v.back(), y);
  90. v.push_back(x);
  91. VERIFY_IS_APPROX(v.back(), x);
  92. }
  93. void test_stddeque()
  94. {
  95. // some non vectorizable fixed sizes
  96. CALL_SUBTEST_1(check_stddeque_matrix(Vector2f()));
  97. CALL_SUBTEST_1(check_stddeque_matrix(Matrix3f()));
  98. CALL_SUBTEST_2(check_stddeque_matrix(Matrix3d()));
  99. // some vectorizable fixed sizes
  100. CALL_SUBTEST_1(check_stddeque_matrix(Matrix2f()));
  101. CALL_SUBTEST_1(check_stddeque_matrix(Vector4f()));
  102. CALL_SUBTEST_1(check_stddeque_matrix(Matrix4f()));
  103. CALL_SUBTEST_2(check_stddeque_matrix(Matrix4d()));
  104. // some dynamic sizes
  105. CALL_SUBTEST_3(check_stddeque_matrix(MatrixXd(1,1)));
  106. CALL_SUBTEST_3(check_stddeque_matrix(VectorXd(20)));
  107. CALL_SUBTEST_3(check_stddeque_matrix(RowVectorXf(20)));
  108. CALL_SUBTEST_3(check_stddeque_matrix(MatrixXcf(10,10)));
  109. // some Transform
  110. CALL_SUBTEST_4(check_stddeque_transform(Affine2f()));
  111. CALL_SUBTEST_4(check_stddeque_transform(Affine3f()));
  112. CALL_SUBTEST_4(check_stddeque_transform(Affine3d()));
  113. // some Quaternion
  114. CALL_SUBTEST_5(check_stddeque_quaternion(Quaternionf()));
  115. CALL_SUBTEST_5(check_stddeque_quaternion(Quaterniond()));
  116. }