stdlist.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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/StdList>
  12. #include <Eigen/Geometry>
  13. template<typename MatrixType>
  14. void check_stdlist_matrix(const MatrixType& m)
  15. {
  16. Index rows = m.rows();
  17. Index cols = m.cols();
  18. MatrixType x = MatrixType::Random(rows,cols), y = MatrixType::Random(rows,cols);
  19. std::list<MatrixType,Eigen::aligned_allocator<MatrixType> > v(10, MatrixType::Zero(rows,cols)), w(20, y);
  20. v.front() = x;
  21. w.front() = w.back();
  22. VERIFY_IS_APPROX(w.front(), w.back());
  23. v = w;
  24. typename std::list<MatrixType,Eigen::aligned_allocator<MatrixType> >::iterator vi = v.begin();
  25. typename std::list<MatrixType,Eigen::aligned_allocator<MatrixType> >::iterator wi = w.begin();
  26. for(int i = 0; i < 20; i++)
  27. {
  28. VERIFY_IS_APPROX(*vi, *wi);
  29. ++vi;
  30. ++wi;
  31. }
  32. v.resize(21, MatrixType::Zero(rows,cols));
  33. v.back() = x;
  34. VERIFY_IS_APPROX(v.back(), x);
  35. v.resize(22,y);
  36. VERIFY_IS_APPROX(v.back(), y);
  37. v.push_back(x);
  38. VERIFY_IS_APPROX(v.back(), x);
  39. }
  40. template<typename TransformType>
  41. void check_stdlist_transform(const TransformType&)
  42. {
  43. typedef typename TransformType::MatrixType MatrixType;
  44. TransformType x(MatrixType::Random()), y(MatrixType::Random()), ti=TransformType::Identity();
  45. std::list<TransformType,Eigen::aligned_allocator<TransformType> > v(10,ti), w(20, y);
  46. v.front() = x;
  47. w.front() = w.back();
  48. VERIFY_IS_APPROX(w.front(), w.back());
  49. v = w;
  50. typename std::list<TransformType,Eigen::aligned_allocator<TransformType> >::iterator vi = v.begin();
  51. typename std::list<TransformType,Eigen::aligned_allocator<TransformType> >::iterator wi = w.begin();
  52. for(int i = 0; i < 20; i++)
  53. {
  54. VERIFY_IS_APPROX(*vi, *wi);
  55. ++vi;
  56. ++wi;
  57. }
  58. v.resize(21, ti);
  59. v.back() = x;
  60. VERIFY_IS_APPROX(v.back(), x);
  61. v.resize(22,y);
  62. VERIFY_IS_APPROX(v.back(), y);
  63. v.push_back(x);
  64. VERIFY_IS_APPROX(v.back(), x);
  65. }
  66. template<typename QuaternionType>
  67. void check_stdlist_quaternion(const QuaternionType&)
  68. {
  69. typedef typename QuaternionType::Coefficients Coefficients;
  70. QuaternionType x(Coefficients::Random()), y(Coefficients::Random()), qi=QuaternionType::Identity();
  71. std::list<QuaternionType,Eigen::aligned_allocator<QuaternionType> > v(10,qi), w(20, y);
  72. v.front() = x;
  73. w.front() = w.back();
  74. VERIFY_IS_APPROX(w.front(), w.back());
  75. v = w;
  76. typename std::list<QuaternionType,Eigen::aligned_allocator<QuaternionType> >::iterator vi = v.begin();
  77. typename std::list<QuaternionType,Eigen::aligned_allocator<QuaternionType> >::iterator wi = w.begin();
  78. for(int i = 0; i < 20; i++)
  79. {
  80. VERIFY_IS_APPROX(*vi, *wi);
  81. ++vi;
  82. ++wi;
  83. }
  84. v.resize(21,qi);
  85. v.back() = x;
  86. VERIFY_IS_APPROX(v.back(), x);
  87. v.resize(22,y);
  88. VERIFY_IS_APPROX(v.back(), y);
  89. v.push_back(x);
  90. VERIFY_IS_APPROX(v.back(), x);
  91. }
  92. void test_stdlist()
  93. {
  94. // some non vectorizable fixed sizes
  95. CALL_SUBTEST_1(check_stdlist_matrix(Vector2f()));
  96. CALL_SUBTEST_1(check_stdlist_matrix(Matrix3f()));
  97. CALL_SUBTEST_2(check_stdlist_matrix(Matrix3d()));
  98. // some vectorizable fixed sizes
  99. CALL_SUBTEST_1(check_stdlist_matrix(Matrix2f()));
  100. CALL_SUBTEST_1(check_stdlist_matrix(Vector4f()));
  101. CALL_SUBTEST_1(check_stdlist_matrix(Matrix4f()));
  102. CALL_SUBTEST_2(check_stdlist_matrix(Matrix4d()));
  103. // some dynamic sizes
  104. CALL_SUBTEST_3(check_stdlist_matrix(MatrixXd(1,1)));
  105. CALL_SUBTEST_3(check_stdlist_matrix(VectorXd(20)));
  106. CALL_SUBTEST_3(check_stdlist_matrix(RowVectorXf(20)));
  107. CALL_SUBTEST_3(check_stdlist_matrix(MatrixXcf(10,10)));
  108. // some Transform
  109. CALL_SUBTEST_4(check_stdlist_transform(Affine2f()));
  110. CALL_SUBTEST_4(check_stdlist_transform(Affine3f()));
  111. CALL_SUBTEST_4(check_stdlist_transform(Affine3d()));
  112. // some Quaternion
  113. CALL_SUBTEST_5(check_stdlist_quaternion(Quaternionf()));
  114. CALL_SUBTEST_5(check_stdlist_quaternion(Quaterniond()));
  115. }