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.

175 lines
7.2 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. typedef typename PlainObjectType::Index Index;
  60. Index rows = m.rows(), cols = m.cols();
  61. int i = internal::random<int>(2,5), j = internal::random<int>(2,5);
  62. PlainObjectType::Map(ptr, rows, cols).setZero();
  63. PlainObjectType::MapAligned(ptr, rows, cols).setZero();
  64. PlainObjectType::Map(const_ptr, rows, cols).sum();
  65. PlainObjectType::MapAligned(const_ptr, rows, cols).sum();
  66. PlainObjectType::Map(ptr, rows, cols, InnerStride<>(i)).setZero();
  67. PlainObjectType::MapAligned(ptr, rows, cols, InnerStride<>(i)).setZero();
  68. PlainObjectType::Map(const_ptr, rows, cols, InnerStride<>(i)).sum();
  69. PlainObjectType::MapAligned(const_ptr, rows, cols, InnerStride<>(i)).sum();
  70. PlainObjectType::Map(ptr, rows, cols, InnerStride<2>()).setZero();
  71. PlainObjectType::MapAligned(ptr, rows, cols, InnerStride<3>()).setZero();
  72. PlainObjectType::Map(const_ptr, rows, cols, InnerStride<4>()).sum();
  73. PlainObjectType::MapAligned(const_ptr, rows, cols, InnerStride<5>()).sum();
  74. PlainObjectType::Map(ptr, rows, cols, OuterStride<>(i)).setZero();
  75. PlainObjectType::MapAligned(ptr, rows, cols, OuterStride<>(i)).setZero();
  76. PlainObjectType::Map(const_ptr, rows, cols, OuterStride<>(i)).sum();
  77. PlainObjectType::MapAligned(const_ptr, rows, cols, OuterStride<>(i)).sum();
  78. PlainObjectType::Map(ptr, rows, cols, OuterStride<2>()).setZero();
  79. PlainObjectType::MapAligned(ptr, rows, cols, OuterStride<3>()).setZero();
  80. PlainObjectType::Map(const_ptr, rows, cols, OuterStride<4>()).sum();
  81. PlainObjectType::MapAligned(const_ptr, rows, cols, OuterStride<5>()).sum();
  82. PlainObjectType::Map(ptr, rows, cols, Stride<Dynamic, Dynamic>(i,j)).setZero();
  83. PlainObjectType::MapAligned(ptr, rows, cols, Stride<2,Dynamic>(2,i)).setZero();
  84. PlainObjectType::Map(const_ptr, rows, cols, Stride<Dynamic,3>(i,3)).sum();
  85. PlainObjectType::MapAligned(const_ptr, rows, cols, Stride<Dynamic, Dynamic>(i,j)).sum();
  86. PlainObjectType::Map(ptr, rows, cols, Stride<2,3>()).setZero();
  87. PlainObjectType::MapAligned(ptr, rows, cols, Stride<3,4>()).setZero();
  88. PlainObjectType::Map(const_ptr, rows, cols, Stride<2,4>()).sum();
  89. PlainObjectType::MapAligned(const_ptr, rows, cols, Stride<5,3>()).sum();
  90. }
  91. };
  92. template<typename PlainObjectType>
  93. struct mapstaticmethods_impl<PlainObjectType, true, true>
  94. {
  95. static void run(const PlainObjectType& v)
  96. {
  97. typedef typename PlainObjectType::Index Index;
  98. Index size = v.size();
  99. int i = internal::random<int>(2,5);
  100. PlainObjectType::Map(ptr, size).setZero();
  101. PlainObjectType::MapAligned(ptr, size).setZero();
  102. PlainObjectType::Map(const_ptr, size).sum();
  103. PlainObjectType::MapAligned(const_ptr, size).sum();
  104. PlainObjectType::Map(ptr, size, InnerStride<>(i)).setZero();
  105. PlainObjectType::MapAligned(ptr, size, InnerStride<>(i)).setZero();
  106. PlainObjectType::Map(const_ptr, size, InnerStride<>(i)).sum();
  107. PlainObjectType::MapAligned(const_ptr, size, InnerStride<>(i)).sum();
  108. PlainObjectType::Map(ptr, size, InnerStride<2>()).setZero();
  109. PlainObjectType::MapAligned(ptr, size, InnerStride<3>()).setZero();
  110. PlainObjectType::Map(const_ptr, size, InnerStride<4>()).sum();
  111. PlainObjectType::MapAligned(const_ptr, size, InnerStride<5>()).sum();
  112. }
  113. };
  114. template<typename PlainObjectType>
  115. void mapstaticmethods(const PlainObjectType& m)
  116. {
  117. mapstaticmethods_impl<PlainObjectType>::run(m);
  118. VERIFY(true); // just to avoid 'unused function' warning
  119. }
  120. void test_mapstaticmethods()
  121. {
  122. ptr = internal::aligned_new<float>(1000);
  123. for(int i = 0; i < 1000; i++) ptr[i] = float(i);
  124. const_ptr = ptr;
  125. CALL_SUBTEST_1(( mapstaticmethods(Matrix<float, 1, 1>()) ));
  126. CALL_SUBTEST_1(( mapstaticmethods(Vector2f()) ));
  127. CALL_SUBTEST_2(( mapstaticmethods(Vector3f()) ));
  128. CALL_SUBTEST_2(( mapstaticmethods(Matrix2f()) ));
  129. CALL_SUBTEST_3(( mapstaticmethods(Matrix4f()) ));
  130. CALL_SUBTEST_3(( mapstaticmethods(Array4f()) ));
  131. CALL_SUBTEST_4(( mapstaticmethods(Array3f()) ));
  132. CALL_SUBTEST_4(( mapstaticmethods(Array33f()) ));
  133. CALL_SUBTEST_5(( mapstaticmethods(Array44f()) ));
  134. CALL_SUBTEST_5(( mapstaticmethods(VectorXf(1)) ));
  135. CALL_SUBTEST_5(( mapstaticmethods(VectorXf(8)) ));
  136. CALL_SUBTEST_6(( mapstaticmethods(MatrixXf(1,1)) ));
  137. CALL_SUBTEST_6(( mapstaticmethods(MatrixXf(5,7)) ));
  138. CALL_SUBTEST_7(( mapstaticmethods(ArrayXf(1)) ));
  139. CALL_SUBTEST_7(( mapstaticmethods(ArrayXf(5)) ));
  140. CALL_SUBTEST_8(( mapstaticmethods(ArrayXXf(1,1)) ));
  141. CALL_SUBTEST_8(( mapstaticmethods(ArrayXXf(8,6)) ));
  142. internal::aligned_delete(ptr, 1000);
  143. }