1 // This file is part of Eigen, a lightweight C++ template library
4 // Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
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/.
13 const float *const_ptr
;
15 template<typename PlainObjectType
,
16 bool IsDynamicSize
= PlainObjectType::SizeAtCompileTime
== Dynamic
,
17 bool IsVector
= PlainObjectType::IsVectorAtCompileTime
19 struct mapstaticmethods_impl
{};
21 template<typename PlainObjectType
, bool IsVector
>
22 struct mapstaticmethods_impl
<PlainObjectType
, false, IsVector
>
24 static void run(const PlainObjectType
& m
)
26 mapstaticmethods_impl
<PlainObjectType
, true, IsVector
>::run(m
);
28 int i
= internal::random
<int>(2,5), j
= internal::random
<int>(2,5);
30 PlainObjectType::Map(ptr
).setZero();
31 PlainObjectType::MapAligned(ptr
).setZero();
32 PlainObjectType::Map(const_ptr
).sum();
33 PlainObjectType::MapAligned(const_ptr
).sum();
35 PlainObjectType::Map(ptr
, InnerStride
<>(i
)).setZero();
36 PlainObjectType::MapAligned(ptr
, InnerStride
<>(i
)).setZero();
37 PlainObjectType::Map(const_ptr
, InnerStride
<>(i
)).sum();
38 PlainObjectType::MapAligned(const_ptr
, InnerStride
<>(i
)).sum();
40 PlainObjectType::Map(ptr
, InnerStride
<2>()).setZero();
41 PlainObjectType::MapAligned(ptr
, InnerStride
<3>()).setZero();
42 PlainObjectType::Map(const_ptr
, InnerStride
<4>()).sum();
43 PlainObjectType::MapAligned(const_ptr
, InnerStride
<5>()).sum();
45 PlainObjectType::Map(ptr
, OuterStride
<>(i
)).setZero();
46 PlainObjectType::MapAligned(ptr
, OuterStride
<>(i
)).setZero();
47 PlainObjectType::Map(const_ptr
, OuterStride
<>(i
)).sum();
48 PlainObjectType::MapAligned(const_ptr
, OuterStride
<>(i
)).sum();
50 PlainObjectType::Map(ptr
, OuterStride
<2>()).setZero();
51 PlainObjectType::MapAligned(ptr
, OuterStride
<3>()).setZero();
52 PlainObjectType::Map(const_ptr
, OuterStride
<4>()).sum();
53 PlainObjectType::MapAligned(const_ptr
, OuterStride
<5>()).sum();
55 PlainObjectType::Map(ptr
, Stride
<Dynamic
, Dynamic
>(i
,j
)).setZero();
56 PlainObjectType::MapAligned(ptr
, Stride
<2,Dynamic
>(2,i
)).setZero();
57 PlainObjectType::Map(const_ptr
, Stride
<Dynamic
,3>(i
,3)).sum();
58 PlainObjectType::MapAligned(const_ptr
, Stride
<Dynamic
, Dynamic
>(i
,j
)).sum();
60 PlainObjectType::Map(ptr
, Stride
<2,3>()).setZero();
61 PlainObjectType::MapAligned(ptr
, Stride
<3,4>()).setZero();
62 PlainObjectType::Map(const_ptr
, Stride
<2,4>()).sum();
63 PlainObjectType::MapAligned(const_ptr
, Stride
<5,3>()).sum();
67 template<typename PlainObjectType
>
68 struct mapstaticmethods_impl
<PlainObjectType
, true, false>
70 static void run(const PlainObjectType
& m
)
72 int rows
= m
.rows(), cols
= m
.cols();
74 int i
= internal::random
<int>(2,5), j
= internal::random
<int>(2,5);
76 PlainObjectType::Map(ptr
, rows
, cols
).setZero();
77 PlainObjectType::MapAligned(ptr
, rows
, cols
).setZero();
78 PlainObjectType::Map(const_ptr
, rows
, cols
).sum();
79 PlainObjectType::MapAligned(const_ptr
, rows
, cols
).sum();
81 PlainObjectType::Map(ptr
, rows
, cols
, InnerStride
<>(i
)).setZero();
82 PlainObjectType::MapAligned(ptr
, rows
, cols
, InnerStride
<>(i
)).setZero();
83 PlainObjectType::Map(const_ptr
, rows
, cols
, InnerStride
<>(i
)).sum();
84 PlainObjectType::MapAligned(const_ptr
, rows
, cols
, InnerStride
<>(i
)).sum();
86 PlainObjectType::Map(ptr
, rows
, cols
, InnerStride
<2>()).setZero();
87 PlainObjectType::MapAligned(ptr
, rows
, cols
, InnerStride
<3>()).setZero();
88 PlainObjectType::Map(const_ptr
, rows
, cols
, InnerStride
<4>()).sum();
89 PlainObjectType::MapAligned(const_ptr
, rows
, cols
, InnerStride
<5>()).sum();
91 PlainObjectType::Map(ptr
, rows
, cols
, OuterStride
<>(i
)).setZero();
92 PlainObjectType::MapAligned(ptr
, rows
, cols
, OuterStride
<>(i
)).setZero();
93 PlainObjectType::Map(const_ptr
, rows
, cols
, OuterStride
<>(i
)).sum();
94 PlainObjectType::MapAligned(const_ptr
, rows
, cols
, OuterStride
<>(i
)).sum();
96 PlainObjectType::Map(ptr
, rows
, cols
, OuterStride
<2>()).setZero();
97 PlainObjectType::MapAligned(ptr
, rows
, cols
, OuterStride
<3>()).setZero();
98 PlainObjectType::Map(const_ptr
, rows
, cols
, OuterStride
<4>()).sum();
99 PlainObjectType::MapAligned(const_ptr
, rows
, cols
, OuterStride
<5>()).sum();
101 PlainObjectType::Map(ptr
, rows
, cols
, Stride
<Dynamic
, Dynamic
>(i
,j
)).setZero();
102 PlainObjectType::MapAligned(ptr
, rows
, cols
, Stride
<2,Dynamic
>(2,i
)).setZero();
103 PlainObjectType::Map(const_ptr
, rows
, cols
, Stride
<Dynamic
,3>(i
,3)).sum();
104 PlainObjectType::MapAligned(const_ptr
, rows
, cols
, Stride
<Dynamic
, Dynamic
>(i
,j
)).sum();
106 PlainObjectType::Map(ptr
, rows
, cols
, Stride
<2,3>()).setZero();
107 PlainObjectType::MapAligned(ptr
, rows
, cols
, Stride
<3,4>()).setZero();
108 PlainObjectType::Map(const_ptr
, rows
, cols
, Stride
<2,4>()).sum();
109 PlainObjectType::MapAligned(const_ptr
, rows
, cols
, Stride
<5,3>()).sum();
113 template<typename PlainObjectType
>
114 struct mapstaticmethods_impl
<PlainObjectType
, true, true>
116 static void run(const PlainObjectType
& v
)
120 int i
= internal::random
<int>(2,5);
122 PlainObjectType::Map(ptr
, size
).setZero();
123 PlainObjectType::MapAligned(ptr
, size
).setZero();
124 PlainObjectType::Map(const_ptr
, size
).sum();
125 PlainObjectType::MapAligned(const_ptr
, size
).sum();
127 PlainObjectType::Map(ptr
, size
, InnerStride
<>(i
)).setZero();
128 PlainObjectType::MapAligned(ptr
, size
, InnerStride
<>(i
)).setZero();
129 PlainObjectType::Map(const_ptr
, size
, InnerStride
<>(i
)).sum();
130 PlainObjectType::MapAligned(const_ptr
, size
, InnerStride
<>(i
)).sum();
132 PlainObjectType::Map(ptr
, size
, InnerStride
<2>()).setZero();
133 PlainObjectType::MapAligned(ptr
, size
, InnerStride
<3>()).setZero();
134 PlainObjectType::Map(const_ptr
, size
, InnerStride
<4>()).sum();
135 PlainObjectType::MapAligned(const_ptr
, size
, InnerStride
<5>()).sum();
139 template<typename PlainObjectType
>
140 void mapstaticmethods(const PlainObjectType
& m
)
142 mapstaticmethods_impl
<PlainObjectType
>::run(m
);
143 VERIFY(true); // just to avoid 'unused function' warning
146 void test_mapstaticmethods()
148 ptr
= internal::aligned_new
<float>(1000);
149 for(int i
= 0; i
< 1000; i
++) ptr
[i
] = float(i
);
153 CALL_SUBTEST_1(( mapstaticmethods(Matrix
<float, 1, 1>()) ));
154 CALL_SUBTEST_1(( mapstaticmethods(Vector2f()) ));
155 CALL_SUBTEST_2(( mapstaticmethods(Vector3f()) ));
156 CALL_SUBTEST_2(( mapstaticmethods(Matrix2f()) ));
157 CALL_SUBTEST_3(( mapstaticmethods(Matrix4f()) ));
158 CALL_SUBTEST_3(( mapstaticmethods(Array4f()) ));
159 CALL_SUBTEST_4(( mapstaticmethods(Array3f()) ));
160 CALL_SUBTEST_4(( mapstaticmethods(Array33f()) ));
161 CALL_SUBTEST_5(( mapstaticmethods(Array44f()) ));
162 CALL_SUBTEST_5(( mapstaticmethods(VectorXf(1)) ));
163 CALL_SUBTEST_5(( mapstaticmethods(VectorXf(8)) ));
164 CALL_SUBTEST_6(( mapstaticmethods(MatrixXf(1,1)) ));
165 CALL_SUBTEST_6(( mapstaticmethods(MatrixXf(5,7)) ));
166 CALL_SUBTEST_7(( mapstaticmethods(ArrayXf(1)) ));
167 CALL_SUBTEST_7(( mapstaticmethods(ArrayXf(5)) ));
168 CALL_SUBTEST_8(( mapstaticmethods(ArrayXXf(1,1)) ));
169 CALL_SUBTEST_8(( mapstaticmethods(ArrayXXf(8,6)) ));
171 internal::aligned_delete(ptr
, 1000);