mapstaticmethods.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. float *ptr;
  11. const float *const_ptr;
  12. template<typename PlainObjectType,
  13. bool IsDynamicSize = PlainObjectType::SizeAtCompileTime == Dynamic,
  14. bool IsVector = PlainObjectType::IsVectorAtCompileTime
  15. >
  16. struct mapstaticmethods_impl {};
  17. template<typename PlainObjectType, bool IsVector>
  18. struct mapstaticmethods_impl<PlainObjectType, false, IsVector>
  19. {
  20. static void run(const PlainObjectType& m)
  21. {
  22. mapstaticmethods_impl<PlainObjectType, true, IsVector>::run(m);
  23. int i = internal::random<int>(2,5), j = internal::random<int>(2,5);
  24. PlainObjectType::Map(ptr).setZero();
  25. PlainObjectType::MapAligned(ptr).setZero();
  26. PlainObjectType::Map(const_ptr).sum();
  27. PlainObjectType::MapAligned(const_ptr).sum();
  28. PlainObjectType::Map(ptr, InnerStride<>(i)).setZero();
  29. PlainObjectType::MapAligned(ptr, InnerStride<>(i)).setZero();
  30. PlainObjectType::Map(const_ptr, InnerStride<>(i)).sum();
  31. PlainObjectType::MapAligned(const_ptr, InnerStride<>(i)).sum();
  32. PlainObjectType::Map(ptr, InnerStride<2>()).setZero();
  33. PlainObjectType::MapAligned(ptr, InnerStride<3>()).setZero();
  34. PlainObjectType::Map(const_ptr, InnerStride<4>()).sum();
  35. PlainObjectType::MapAligned(const_ptr, InnerStride<5>()).sum();
  36. PlainObjectType::Map(ptr, OuterStride<>(i)).setZero();
  37. PlainObjectType::MapAligned(ptr, OuterStride<>(i)).setZero();
  38. PlainObjectType::Map(const_ptr, OuterStride<>(i)).sum();
  39. PlainObjectType::MapAligned(const_ptr, OuterStride<>(i)).sum();
  40. PlainObjectType::Map(ptr, OuterStride<2>()).setZero();
  41. PlainObjectType::MapAligned(ptr, OuterStride<3>()).setZero();
  42. PlainObjectType::Map(const_ptr, OuterStride<4>()).sum();
  43. PlainObjectType::MapAligned(const_ptr, OuterStride<5>()).sum();
  44. PlainObjectType::Map(ptr, Stride<Dynamic, Dynamic>(i,j)).setZero();
  45. PlainObjectType::MapAligned(ptr, Stride<2,Dynamic>(2,i)).setZero();
  46. PlainObjectType::Map(const_ptr, Stride<Dynamic,3>(i,3)).sum();
  47. PlainObjectType::MapAligned(const_ptr, Stride<Dynamic, Dynamic>(i,j)).sum();
  48. PlainObjectType::Map(ptr, Stride<2,3>()).setZero();
  49. PlainObjectType::MapAligned(ptr, Stride<3,4>()).setZero();
  50. PlainObjectType::Map(const_ptr, Stride<2,4>()).sum();
  51. PlainObjectType::MapAligned(const_ptr, Stride<5,3>()).sum();
  52. }
  53. };
  54. template<typename PlainObjectType>
  55. struct mapstaticmethods_impl<PlainObjectType, true, false>
  56. {
  57. static void run(const PlainObjectType& m)
  58. {
  59. Index rows = m.rows(), cols = m.cols();
  60. int i = internal::random<int>(2,5), j = internal::random<int>(2,5);
  61. PlainObjectType::Map(ptr, rows, cols).setZero();
  62. PlainObjectType::MapAligned(ptr, rows, cols).setZero();
  63. PlainObjectType::Map(const_ptr, rows, cols).sum();
  64. PlainObjectType::MapAligned(const_ptr, rows, cols).sum();
  65. PlainObjectType::Map(ptr, rows, cols, InnerStride<>(i)).setZero();
  66. PlainObjectType::MapAligned(ptr, rows, cols, InnerStride<>(i)).setZero();
  67. PlainObjectType::Map(const_ptr, rows, cols, InnerStride<>(i)).sum();
  68. PlainObjectType::MapAligned(const_ptr, rows, cols, InnerStride<>(i)).sum();
  69. PlainObjectType::Map(ptr, rows, cols, InnerStride<2>()).setZero();
  70. PlainObjectType::MapAligned(ptr, rows, cols, InnerStride<3>()).setZero();
  71. PlainObjectType::Map(const_ptr, rows, cols, InnerStride<4>()).sum();
  72. PlainObjectType::MapAligned(const_ptr, rows, cols, InnerStride<5>()).sum();
  73. PlainObjectType::Map(ptr, rows, cols, OuterStride<>(i)).setZero();
  74. PlainObjectType::MapAligned(ptr, rows, cols, OuterStride<>(i)).setZero();
  75. PlainObjectType::Map(const_ptr, rows, cols, OuterStride<>(i)).sum();
  76. PlainObjectType::MapAligned(const_ptr, rows, cols, OuterStride<>(i)).sum();
  77. PlainObjectType::Map(ptr, rows, cols, OuterStride<2>()).setZero();
  78. PlainObjectType::MapAligned(ptr, rows, cols, OuterStride<3>()).setZero();
  79. PlainObjectType::Map(const_ptr, rows, cols, OuterStride<4>()).sum();
  80. PlainObjectType::MapAligned(const_ptr, rows, cols, OuterStride<5>()).sum();
  81. PlainObjectType::Map(ptr, rows, cols, Stride<Dynamic, Dynamic>(i,j)).setZero();
  82. PlainObjectType::MapAligned(ptr, rows, cols, Stride<2,Dynamic>(2,i)).setZero();
  83. PlainObjectType::Map(const_ptr, rows, cols, Stride<Dynamic,3>(i,3)).sum();
  84. PlainObjectType::MapAligned(const_ptr, rows, cols, Stride<Dynamic, Dynamic>(i,j)).sum();
  85. PlainObjectType::Map(ptr, rows, cols, Stride<2,3>()).setZero();
  86. PlainObjectType::MapAligned(ptr, rows, cols, Stride<3,4>()).setZero();
  87. PlainObjectType::Map(const_ptr, rows, cols, Stride<2,4>()).sum();
  88. PlainObjectType::MapAligned(const_ptr, rows, cols, Stride<5,3>()).sum();
  89. }
  90. };
  91. template<typename PlainObjectType>
  92. struct mapstaticmethods_impl<PlainObjectType, true, true>
  93. {
  94. static void run(const PlainObjectType& v)
  95. {
  96. Index size = v.size();
  97. int i = internal::random<int>(2,5);
  98. PlainObjectType::Map(ptr, size).setZero();
  99. PlainObjectType::MapAligned(ptr, size).setZero();
  100. PlainObjectType::Map(const_ptr, size).sum();
  101. PlainObjectType::MapAligned(const_ptr, size).sum();
  102. PlainObjectType::Map(ptr, size, InnerStride<>(i)).setZero();
  103. PlainObjectType::MapAligned(ptr, size, InnerStride<>(i)).setZero();
  104. PlainObjectType::Map(const_ptr, size, InnerStride<>(i)).sum();
  105. PlainObjectType::MapAligned(const_ptr, size, InnerStride<>(i)).sum();
  106. PlainObjectType::Map(ptr, size, InnerStride<2>()).setZero();
  107. PlainObjectType::MapAligned(ptr, size, InnerStride<3>()).setZero();
  108. PlainObjectType::Map(const_ptr, size, InnerStride<4>()).sum();
  109. PlainObjectType::MapAligned(const_ptr, size, InnerStride<5>()).sum();
  110. }
  111. };
  112. template<typename PlainObjectType>
  113. void mapstaticmethods(const PlainObjectType& m)
  114. {
  115. mapstaticmethods_impl<PlainObjectType>::run(m);
  116. VERIFY(true); // just to avoid 'unused function' warning
  117. }
  118. void test_mapstaticmethods()
  119. {
  120. ptr = internal::aligned_new<float>(1000);
  121. for(int i = 0; i < 1000; i++) ptr[i] = float(i);
  122. const_ptr = ptr;
  123. CALL_SUBTEST_1(( mapstaticmethods(Matrix<float, 1, 1>()) ));
  124. CALL_SUBTEST_1(( mapstaticmethods(Vector2f()) ));
  125. CALL_SUBTEST_2(( mapstaticmethods(Vector3f()) ));
  126. CALL_SUBTEST_2(( mapstaticmethods(Matrix2f()) ));
  127. CALL_SUBTEST_3(( mapstaticmethods(Matrix4f()) ));
  128. CALL_SUBTEST_3(( mapstaticmethods(Array4f()) ));
  129. CALL_SUBTEST_4(( mapstaticmethods(Array3f()) ));
  130. CALL_SUBTEST_4(( mapstaticmethods(Array33f()) ));
  131. CALL_SUBTEST_5(( mapstaticmethods(Array44f()) ));
  132. CALL_SUBTEST_5(( mapstaticmethods(VectorXf(1)) ));
  133. CALL_SUBTEST_5(( mapstaticmethods(VectorXf(8)) ));
  134. CALL_SUBTEST_6(( mapstaticmethods(MatrixXf(1,1)) ));
  135. CALL_SUBTEST_6(( mapstaticmethods(MatrixXf(5,7)) ));
  136. CALL_SUBTEST_7(( mapstaticmethods(ArrayXf(1)) ));
  137. CALL_SUBTEST_7(( mapstaticmethods(ArrayXf(5)) ));
  138. CALL_SUBTEST_8(( mapstaticmethods(ArrayXXf(1,1)) ));
  139. CALL_SUBTEST_8(( mapstaticmethods(ArrayXXf(8,6)) ));
  140. internal::aligned_delete(ptr, 1000);
  141. }