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.

173 lines
7.1 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. 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. int 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. int 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. }