source: pacpussensors/trunk/Vislab/lib3dv/eigen/test/mapstaticmethods.cpp@ 136

Last change on this file since 136 was 136, checked in by ldecherf, 7 years ago

Doc

File size: 7.1 KB
Line 
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
10#include "main.h"
11
12float *ptr;
13const float *const_ptr;
14
15template<typename PlainObjectType,
16 bool IsDynamicSize = PlainObjectType::SizeAtCompileTime == Dynamic,
17 bool IsVector = PlainObjectType::IsVectorAtCompileTime
18>
19struct mapstaticmethods_impl {};
20
21template<typename PlainObjectType, bool IsVector>
22struct mapstaticmethods_impl<PlainObjectType, false, IsVector>
23{
24 static void run(const PlainObjectType& m)
25 {
26 mapstaticmethods_impl<PlainObjectType, true, IsVector>::run(m);
27
28 int i = internal::random<int>(2,5), j = internal::random<int>(2,5);
29
30 PlainObjectType::Map(ptr).setZero();
31 PlainObjectType::MapAligned(ptr).setZero();
32 PlainObjectType::Map(const_ptr).sum();
33 PlainObjectType::MapAligned(const_ptr).sum();
34
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();
39
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();
44
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();
49
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();
54
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();
59
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();
64 }
65};
66
67template<typename PlainObjectType>
68struct mapstaticmethods_impl<PlainObjectType, true, false>
69{
70 static void run(const PlainObjectType& m)
71 {
72 int rows = m.rows(), cols = m.cols();
73
74 int i = internal::random<int>(2,5), j = internal::random<int>(2,5);
75
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();
80
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();
85
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();
90
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();
95
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();
100
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();
105
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();
110 }
111};
112
113template<typename PlainObjectType>
114struct mapstaticmethods_impl<PlainObjectType, true, true>
115{
116 static void run(const PlainObjectType& v)
117 {
118 int size = v.size();
119
120 int i = internal::random<int>(2,5);
121
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();
126
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();
131
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();
136 }
137};
138
139template<typename PlainObjectType>
140void mapstaticmethods(const PlainObjectType& m)
141{
142 mapstaticmethods_impl<PlainObjectType>::run(m);
143 VERIFY(true); // just to avoid 'unused function' warning
144}
145
146void test_mapstaticmethods()
147{
148 ptr = internal::aligned_new<float>(1000);
149 for(int i = 0; i < 1000; i++) ptr[i] = float(i);
150
151 const_ptr = ptr;
152
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)) ));
170
171 internal::aligned_delete(ptr, 1000);
172}
173
Note: See TracBrowser for help on using the repository browser.