1*bf2c3715SXin Li // This file is part of Eigen, a lightweight C++ template library
2*bf2c3715SXin Li // for linear algebra.
3*bf2c3715SXin Li //
4*bf2c3715SXin Li // Copyright (C) 2011 Benoit Jacob <[email protected]>
5*bf2c3715SXin Li //
6*bf2c3715SXin Li // This Source Code Form is subject to the terms of the Mozilla
7*bf2c3715SXin Li // Public License v. 2.0. If a copy of the MPL was not distributed
8*bf2c3715SXin Li // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9*bf2c3715SXin Li
10*bf2c3715SXin Li #include "main.h"
11*bf2c3715SXin Li
12*bf2c3715SXin Li // GCC<=4.8 has spurious shadow warnings, because `ptr` re-appears inside template instantiations
13*bf2c3715SXin Li // workaround: put these in an anonymous namespace
14*bf2c3715SXin Li namespace {
15*bf2c3715SXin Li float *ptr;
16*bf2c3715SXin Li const float *const_ptr;
17*bf2c3715SXin Li }
18*bf2c3715SXin Li
19*bf2c3715SXin Li template<typename PlainObjectType,
20*bf2c3715SXin Li bool IsDynamicSize = PlainObjectType::SizeAtCompileTime == Dynamic,
21*bf2c3715SXin Li bool IsVector = PlainObjectType::IsVectorAtCompileTime
22*bf2c3715SXin Li >
23*bf2c3715SXin Li struct mapstaticmethods_impl {};
24*bf2c3715SXin Li
25*bf2c3715SXin Li template<typename PlainObjectType, bool IsVector>
26*bf2c3715SXin Li struct mapstaticmethods_impl<PlainObjectType, false, IsVector>
27*bf2c3715SXin Li {
runmapstaticmethods_impl28*bf2c3715SXin Li static void run(const PlainObjectType& m)
29*bf2c3715SXin Li {
30*bf2c3715SXin Li mapstaticmethods_impl<PlainObjectType, true, IsVector>::run(m);
31*bf2c3715SXin Li
32*bf2c3715SXin Li int i = internal::random<int>(2,5), j = internal::random<int>(2,5);
33*bf2c3715SXin Li
34*bf2c3715SXin Li PlainObjectType::Map(ptr).setZero();
35*bf2c3715SXin Li PlainObjectType::MapAligned(ptr).setZero();
36*bf2c3715SXin Li PlainObjectType::Map(const_ptr).sum();
37*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr).sum();
38*bf2c3715SXin Li
39*bf2c3715SXin Li PlainObjectType::Map(ptr, InnerStride<>(i)).setZero();
40*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, InnerStride<>(i)).setZero();
41*bf2c3715SXin Li PlainObjectType::Map(const_ptr, InnerStride<>(i)).sum();
42*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, InnerStride<>(i)).sum();
43*bf2c3715SXin Li
44*bf2c3715SXin Li PlainObjectType::Map(ptr, InnerStride<2>()).setZero();
45*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, InnerStride<3>()).setZero();
46*bf2c3715SXin Li PlainObjectType::Map(const_ptr, InnerStride<4>()).sum();
47*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, InnerStride<5>()).sum();
48*bf2c3715SXin Li
49*bf2c3715SXin Li PlainObjectType::Map(ptr, OuterStride<>(i)).setZero();
50*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, OuterStride<>(i)).setZero();
51*bf2c3715SXin Li PlainObjectType::Map(const_ptr, OuterStride<>(i)).sum();
52*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, OuterStride<>(i)).sum();
53*bf2c3715SXin Li
54*bf2c3715SXin Li PlainObjectType::Map(ptr, OuterStride<2>()).setZero();
55*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, OuterStride<3>()).setZero();
56*bf2c3715SXin Li PlainObjectType::Map(const_ptr, OuterStride<4>()).sum();
57*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, OuterStride<5>()).sum();
58*bf2c3715SXin Li
59*bf2c3715SXin Li PlainObjectType::Map(ptr, Stride<Dynamic, Dynamic>(i,j)).setZero();
60*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, Stride<2,Dynamic>(2,i)).setZero();
61*bf2c3715SXin Li PlainObjectType::Map(const_ptr, Stride<Dynamic,3>(i,3)).sum();
62*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, Stride<Dynamic, Dynamic>(i,j)).sum();
63*bf2c3715SXin Li
64*bf2c3715SXin Li PlainObjectType::Map(ptr, Stride<2,3>()).setZero();
65*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, Stride<3,4>()).setZero();
66*bf2c3715SXin Li PlainObjectType::Map(const_ptr, Stride<2,4>()).sum();
67*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, Stride<5,3>()).sum();
68*bf2c3715SXin Li }
69*bf2c3715SXin Li };
70*bf2c3715SXin Li
71*bf2c3715SXin Li template<typename PlainObjectType>
72*bf2c3715SXin Li struct mapstaticmethods_impl<PlainObjectType, true, false>
73*bf2c3715SXin Li {
runmapstaticmethods_impl74*bf2c3715SXin Li static void run(const PlainObjectType& m)
75*bf2c3715SXin Li {
76*bf2c3715SXin Li Index rows = m.rows(), cols = m.cols();
77*bf2c3715SXin Li
78*bf2c3715SXin Li int i = internal::random<int>(2,5), j = internal::random<int>(2,5);
79*bf2c3715SXin Li
80*bf2c3715SXin Li PlainObjectType::Map(ptr, rows, cols).setZero();
81*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, rows, cols).setZero();
82*bf2c3715SXin Li PlainObjectType::Map(const_ptr, rows, cols).sum();
83*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, rows, cols).sum();
84*bf2c3715SXin Li
85*bf2c3715SXin Li PlainObjectType::Map(ptr, rows, cols, InnerStride<>(i)).setZero();
86*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, rows, cols, InnerStride<>(i)).setZero();
87*bf2c3715SXin Li PlainObjectType::Map(const_ptr, rows, cols, InnerStride<>(i)).sum();
88*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, rows, cols, InnerStride<>(i)).sum();
89*bf2c3715SXin Li
90*bf2c3715SXin Li PlainObjectType::Map(ptr, rows, cols, InnerStride<2>()).setZero();
91*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, rows, cols, InnerStride<3>()).setZero();
92*bf2c3715SXin Li PlainObjectType::Map(const_ptr, rows, cols, InnerStride<4>()).sum();
93*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, rows, cols, InnerStride<5>()).sum();
94*bf2c3715SXin Li
95*bf2c3715SXin Li PlainObjectType::Map(ptr, rows, cols, OuterStride<>(i)).setZero();
96*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, rows, cols, OuterStride<>(i)).setZero();
97*bf2c3715SXin Li PlainObjectType::Map(const_ptr, rows, cols, OuterStride<>(i)).sum();
98*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, rows, cols, OuterStride<>(i)).sum();
99*bf2c3715SXin Li
100*bf2c3715SXin Li PlainObjectType::Map(ptr, rows, cols, OuterStride<2>()).setZero();
101*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, rows, cols, OuterStride<3>()).setZero();
102*bf2c3715SXin Li PlainObjectType::Map(const_ptr, rows, cols, OuterStride<4>()).sum();
103*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, rows, cols, OuterStride<5>()).sum();
104*bf2c3715SXin Li
105*bf2c3715SXin Li PlainObjectType::Map(ptr, rows, cols, Stride<Dynamic, Dynamic>(i,j)).setZero();
106*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, rows, cols, Stride<2,Dynamic>(2,i)).setZero();
107*bf2c3715SXin Li PlainObjectType::Map(const_ptr, rows, cols, Stride<Dynamic,3>(i,3)).sum();
108*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, rows, cols, Stride<Dynamic, Dynamic>(i,j)).sum();
109*bf2c3715SXin Li
110*bf2c3715SXin Li PlainObjectType::Map(ptr, rows, cols, Stride<2,3>()).setZero();
111*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, rows, cols, Stride<3,4>()).setZero();
112*bf2c3715SXin Li PlainObjectType::Map(const_ptr, rows, cols, Stride<2,4>()).sum();
113*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, rows, cols, Stride<5,3>()).sum();
114*bf2c3715SXin Li }
115*bf2c3715SXin Li };
116*bf2c3715SXin Li
117*bf2c3715SXin Li template<typename PlainObjectType>
118*bf2c3715SXin Li struct mapstaticmethods_impl<PlainObjectType, true, true>
119*bf2c3715SXin Li {
runmapstaticmethods_impl120*bf2c3715SXin Li static void run(const PlainObjectType& v)
121*bf2c3715SXin Li {
122*bf2c3715SXin Li Index size = v.size();
123*bf2c3715SXin Li
124*bf2c3715SXin Li int i = internal::random<int>(2,5);
125*bf2c3715SXin Li
126*bf2c3715SXin Li PlainObjectType::Map(ptr, size).setZero();
127*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, size).setZero();
128*bf2c3715SXin Li PlainObjectType::Map(const_ptr, size).sum();
129*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, size).sum();
130*bf2c3715SXin Li
131*bf2c3715SXin Li PlainObjectType::Map(ptr, size, InnerStride<>(i)).setZero();
132*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, size, InnerStride<>(i)).setZero();
133*bf2c3715SXin Li PlainObjectType::Map(const_ptr, size, InnerStride<>(i)).sum();
134*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, size, InnerStride<>(i)).sum();
135*bf2c3715SXin Li
136*bf2c3715SXin Li PlainObjectType::Map(ptr, size, InnerStride<2>()).setZero();
137*bf2c3715SXin Li PlainObjectType::MapAligned(ptr, size, InnerStride<3>()).setZero();
138*bf2c3715SXin Li PlainObjectType::Map(const_ptr, size, InnerStride<4>()).sum();
139*bf2c3715SXin Li PlainObjectType::MapAligned(const_ptr, size, InnerStride<5>()).sum();
140*bf2c3715SXin Li }
141*bf2c3715SXin Li };
142*bf2c3715SXin Li
143*bf2c3715SXin Li template<typename PlainObjectType>
mapstaticmethods(const PlainObjectType & m)144*bf2c3715SXin Li void mapstaticmethods(const PlainObjectType& m)
145*bf2c3715SXin Li {
146*bf2c3715SXin Li mapstaticmethods_impl<PlainObjectType>::run(m);
147*bf2c3715SXin Li VERIFY(true); // just to avoid 'unused function' warning
148*bf2c3715SXin Li }
149*bf2c3715SXin Li
EIGEN_DECLARE_TEST(mapstaticmethods)150*bf2c3715SXin Li EIGEN_DECLARE_TEST(mapstaticmethods)
151*bf2c3715SXin Li {
152*bf2c3715SXin Li ptr = internal::aligned_new<float>(1000);
153*bf2c3715SXin Li for(int i = 0; i < 1000; i++) ptr[i] = float(i);
154*bf2c3715SXin Li
155*bf2c3715SXin Li const_ptr = ptr;
156*bf2c3715SXin Li
157*bf2c3715SXin Li CALL_SUBTEST_1(( mapstaticmethods(Matrix<float, 1, 1>()) ));
158*bf2c3715SXin Li CALL_SUBTEST_1(( mapstaticmethods(Vector2f()) ));
159*bf2c3715SXin Li CALL_SUBTEST_2(( mapstaticmethods(Vector3f()) ));
160*bf2c3715SXin Li CALL_SUBTEST_2(( mapstaticmethods(Matrix2f()) ));
161*bf2c3715SXin Li CALL_SUBTEST_3(( mapstaticmethods(Matrix4f()) ));
162*bf2c3715SXin Li CALL_SUBTEST_3(( mapstaticmethods(Array4f()) ));
163*bf2c3715SXin Li CALL_SUBTEST_4(( mapstaticmethods(Array3f()) ));
164*bf2c3715SXin Li CALL_SUBTEST_4(( mapstaticmethods(Array33f()) ));
165*bf2c3715SXin Li CALL_SUBTEST_5(( mapstaticmethods(Array44f()) ));
166*bf2c3715SXin Li CALL_SUBTEST_5(( mapstaticmethods(VectorXf(1)) ));
167*bf2c3715SXin Li CALL_SUBTEST_5(( mapstaticmethods(VectorXf(8)) ));
168*bf2c3715SXin Li CALL_SUBTEST_6(( mapstaticmethods(MatrixXf(1,1)) ));
169*bf2c3715SXin Li CALL_SUBTEST_6(( mapstaticmethods(MatrixXf(5,7)) ));
170*bf2c3715SXin Li CALL_SUBTEST_7(( mapstaticmethods(ArrayXf(1)) ));
171*bf2c3715SXin Li CALL_SUBTEST_7(( mapstaticmethods(ArrayXf(5)) ));
172*bf2c3715SXin Li CALL_SUBTEST_8(( mapstaticmethods(ArrayXXf(1,1)) ));
173*bf2c3715SXin Li CALL_SUBTEST_8(( mapstaticmethods(ArrayXXf(8,6)) ));
174*bf2c3715SXin Li
175*bf2c3715SXin Li internal::aligned_delete(ptr, 1000);
176*bf2c3715SXin Li }
177*bf2c3715SXin Li
178