1 | // |
---|
2 | // Copyright (c) 2000-2002 |
---|
3 | // Joerg Walter, Mathias Koch |
---|
4 | // |
---|
5 | // Permission to use, copy, modify, distribute and sell this software |
---|
6 | // and its documentation for any purpose is hereby granted without fee, |
---|
7 | // provided that the above copyright notice appear in all copies and |
---|
8 | // that both that copyright notice and this permission notice appear |
---|
9 | // in supporting documentation. The authors make no representations |
---|
10 | // about the suitability of this software for any purpose. |
---|
11 | // It is provided "as is" without express or implied warranty. |
---|
12 | // |
---|
13 | // The authors gratefully acknowledge the support of |
---|
14 | // GeNeSys mbH & Co. KG in producing this work. |
---|
15 | // |
---|
16 | |
---|
17 | #include "test3.hpp" |
---|
18 | |
---|
19 | // Test matrix & vector expression templates |
---|
20 | template<class V, class M, int N> |
---|
21 | struct test_my_matrix_vector { |
---|
22 | typedef typename V::value_type value_type; |
---|
23 | |
---|
24 | template<class VP, class MP> |
---|
25 | void test_with (VP &v1, VP &v2, MP &m1) const { |
---|
26 | { |
---|
27 | // Rows and columns |
---|
28 | initialize_matrix (m1); |
---|
29 | for (int i = 0; i < N; ++ i) { |
---|
30 | v1 = ublas::row (m1, i); |
---|
31 | std::cout << "row (m, " << i << ") = " << v1 << std::endl; |
---|
32 | v1 = ublas::column (m1, i); |
---|
33 | std::cout << "column (m, " << i << ") = " << v1 << std::endl; |
---|
34 | } |
---|
35 | |
---|
36 | // Outer product |
---|
37 | initialize_vector (v1); |
---|
38 | initialize_vector (v2); |
---|
39 | m1 = ublas::outer_prod (v1, v2); |
---|
40 | std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; |
---|
41 | |
---|
42 | // Matrix vector product |
---|
43 | initialize_matrix (m1); |
---|
44 | initialize_vector (v1); |
---|
45 | v2 = ublas::prod (m1, v1); |
---|
46 | std::cout << "prod (m1, v1) = " << v2 << std::endl; |
---|
47 | v2 = ublas::prod (v1, m1); |
---|
48 | std::cout << "prod (v1, m1) = " << v2 << std::endl; |
---|
49 | } |
---|
50 | } |
---|
51 | void operator () () const { |
---|
52 | { |
---|
53 | V v1 (N, N), v2 (N, N); |
---|
54 | M m1 (N, N, N * N); |
---|
55 | |
---|
56 | test_with (v1, v2, m1); |
---|
57 | |
---|
58 | ublas::matrix_row<M> mr1 (m1, 0), mr2 (m1, N - 1); |
---|
59 | test_with (mr1, mr2, m1); |
---|
60 | |
---|
61 | ublas::matrix_column<M> mc1 (m1, 0), mc2 (m1, N - 1); |
---|
62 | test_with (mc1, mc2, m1); |
---|
63 | |
---|
64 | #ifdef USE_RANGE |
---|
65 | ublas::matrix_vector_range<M> mvr1 (m1, ublas::range (0, N), ublas::range (0, N)), |
---|
66 | mvr2 (m1, ublas::range (0, N), ublas::range (0, N)); |
---|
67 | test_with (mvr1, mvr2, m1); |
---|
68 | #endif |
---|
69 | |
---|
70 | #ifdef USE_SLICE |
---|
71 | ublas::matrix_vector_slice<M> mvs1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), |
---|
72 | mvs2 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); |
---|
73 | test_with (mvs1, mvs2, m1); |
---|
74 | #endif |
---|
75 | } |
---|
76 | } |
---|
77 | }; |
---|
78 | |
---|
79 | // Test matrix & vector |
---|
80 | void test_matrix_vector () { |
---|
81 | std::cout << "test_matrix_vector" << std::endl; |
---|
82 | |
---|
83 | #ifdef USE_SPARSE_MATRIX |
---|
84 | #ifdef USE_MAP_ARRAY |
---|
85 | #ifdef USE_FLOAT |
---|
86 | std::cout << "float, map_array" << std::endl; |
---|
87 | test_my_matrix_vector<ublas::mapped_vector<float, ublas::map_array<std::size_t, float> >, |
---|
88 | ublas::mapped_matrix<float, ublas::row_major, ublas::map_array<std::size_t, float> >, 3 > () (); |
---|
89 | #endif |
---|
90 | |
---|
91 | #ifdef USE_DOUBLE |
---|
92 | std::cout << "double, map_array" << std::endl; |
---|
93 | test_my_matrix_vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> >, |
---|
94 | ublas::mapped_matrix<double, ublas::row_major, ublas::map_array<std::size_t, double> >, 3 > () (); |
---|
95 | #endif |
---|
96 | |
---|
97 | #ifdef USE_STD_COMPLEX |
---|
98 | #ifdef USE_FLOAT |
---|
99 | std::cout << "std::complex<float>, map_array" << std::endl; |
---|
100 | test_my_matrix_vector<ublas::mapped_vector<std::complex<float>, ublas::map_array<std::size_t, std::complex<float> > >, |
---|
101 | ublas::mapped_matrix<std::complex<float>, ublas::row_major, ublas::map_array<std::size_t, std::complex<float> > >, 3 > () (); |
---|
102 | #endif |
---|
103 | |
---|
104 | #ifdef USE_DOUBLE |
---|
105 | std::cout << "std::complex<double>, map_array" << std::endl; |
---|
106 | test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >, |
---|
107 | ublas::mapped_matrix<std::complex<double>, ublas::row_major, ublas::map_array<std::size_t, std::complex<double> > >, 3 > () (); |
---|
108 | #endif |
---|
109 | #endif |
---|
110 | #endif |
---|
111 | |
---|
112 | #ifdef USE_STD_MAP |
---|
113 | #ifdef USE_FLOAT |
---|
114 | std::cout << "float, std::map" << std::endl; |
---|
115 | test_my_matrix_vector<ublas::mapped_vector<float, std::map<std::size_t, float> >, |
---|
116 | ublas::mapped_matrix<float, ublas::row_major, std::map<std::size_t, float> >, 3 > () (); |
---|
117 | #endif |
---|
118 | |
---|
119 | #ifdef USE_DOUBLE |
---|
120 | std::cout << "double, std::map" << std::endl; |
---|
121 | test_my_matrix_vector<ublas::mapped_vector<double, std::map<std::size_t, double> >, |
---|
122 | ublas::mapped_matrix<double, ublas::row_major, std::map<std::size_t, double> >, 3 > () (); |
---|
123 | #endif |
---|
124 | |
---|
125 | #ifdef USE_STD_COMPLEX |
---|
126 | #ifdef USE_FLOAT |
---|
127 | std::cout << "std::complex<float>, std::map" << std::endl; |
---|
128 | test_my_matrix_vector<ublas::mapped_vector<std::complex<float>, std::map<std::size_t, std::complex<float> > >, |
---|
129 | ublas::mapped_matrix<std::complex<float>, ublas::row_major, std::map<std::size_t, std::complex<float> > >, 3 > () (); |
---|
130 | #endif |
---|
131 | |
---|
132 | #ifdef USE_DOUBLE |
---|
133 | std::cout << "std::complex<double>, std::map" << std::endl; |
---|
134 | test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > >, |
---|
135 | ublas::mapped_matrix<std::complex<double>, ublas::row_major, std::map<std::size_t, std::complex<double> > >, 3 > () (); |
---|
136 | #endif |
---|
137 | #endif |
---|
138 | #endif |
---|
139 | #endif |
---|
140 | |
---|
141 | #ifdef USE_SPARSE_VECTOR_OF_SPARSE_VECTOR |
---|
142 | #ifdef USE_MAP_ARRAY |
---|
143 | #ifdef USE_FLOAT |
---|
144 | std::cout << "float, mapped_vector map_array" << std::endl; |
---|
145 | test_my_matrix_vector<ublas::mapped_vector<float, ublas::map_array<std::size_t, float> >, |
---|
146 | ublas::mapped_vector<float, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, float> > >, 3 > () (); |
---|
147 | #endif |
---|
148 | |
---|
149 | #ifdef USE_DOUBLE |
---|
150 | std::cout << "double, mapped_vector map_array" << std::endl; |
---|
151 | test_my_matrix_vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> >, |
---|
152 | ublas::mapped_vector<double, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, double> > >, 3 > () (); |
---|
153 | #endif |
---|
154 | |
---|
155 | #ifdef USE_STD_COMPLEX |
---|
156 | #ifdef USE_FLOAT |
---|
157 | std::cout << "std::complex<float>, mapped_vector map_array" << std::endl; |
---|
158 | test_my_matrix_vector<ublas::mapped_vector<std::complex<float>, ublas::map_array<std::size_t, std::complex<float> > >, |
---|
159 | ublas::mapped_vector<std::complex<float>, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, std::complex<float> > > >, 3 > () (); |
---|
160 | #endif |
---|
161 | |
---|
162 | #ifdef USE_DOUBLE |
---|
163 | std::cout << "std::complex<double>,mapped_vector map_array" << std::endl; |
---|
164 | test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >, |
---|
165 | ublas::mapped_vector<std::complex<double>, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, std::complex<double> > > >, 3 > () (); |
---|
166 | #endif |
---|
167 | #endif |
---|
168 | #endif |
---|
169 | |
---|
170 | #ifdef USE_STD_MAP |
---|
171 | #ifdef USE_FLOAT |
---|
172 | std::cout << "float, mapped_vector std::map" << std::endl; |
---|
173 | test_my_matrix_vector<ublas::mapped_vector<float, std::map<std::size_t, float> >, |
---|
174 | ublas::mapped_vector<float, ublas::row_major, std::map<std::size_t, std::map<std::size_t, float> > >, 3 > () (); |
---|
175 | #endif |
---|
176 | |
---|
177 | #ifdef USE_DOUBLE |
---|
178 | std::cout << "double, mapped_vector std::map" << std::endl; |
---|
179 | test_my_matrix_vector<ublas::mapped_vector<double, std::map<std::size_t, double> >, |
---|
180 | ublas::mapped_vector<double, ublas::row_major, std::map<std::size_t, std::map<std::size_t, double> > >, 3 > () (); |
---|
181 | #endif |
---|
182 | |
---|
183 | #ifdef USE_STD_COMPLEX |
---|
184 | #ifdef USE_FLOAT |
---|
185 | std::cout << "std::complex<float>, mapped_vector std::map" << std::endl; |
---|
186 | test_my_matrix_vector<ublas::mapped_vector<std::complex<float>, std::map<std::size_t, std::complex<float> > >, |
---|
187 | ublas::mapped_vector<std::complex<float>, ublas::row_major, std::map<std::size_t, std::map<std::size_t, std::complex<float> > > >, 3 > () (); |
---|
188 | #endif |
---|
189 | |
---|
190 | #ifdef USE_DOUBLE |
---|
191 | std::cout << "std::complex<double>, mapped_vector std::map" << std::endl; |
---|
192 | test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > >, |
---|
193 | ublas::mapped_vector<std::complex<double>, ublas::row_major, std::map<std::size_t, std::map<std::size_t, std::complex<double> > > >, 3 > () (); |
---|
194 | #endif |
---|
195 | #endif |
---|
196 | #endif |
---|
197 | #endif |
---|
198 | |
---|
199 | #ifdef USE_GENERALIZED_VECTOR_OF_VECTOR |
---|
200 | #ifdef USE_MAP_ARRAY |
---|
201 | #ifdef USE_FLOAT |
---|
202 | std::cout << "float, generalized_vector_of_vector map_array" << std::endl; |
---|
203 | test_my_matrix_vector<ublas::mapped_vector<float, ublas::map_array<std::size_t, float> >, |
---|
204 | ublas::generalized_vector_of_vector<float, ublas::row_major, ublas::vector<ublas::mapped_vector<float, ublas::map_array<std::size_t, float> > > >, 3 > () (); |
---|
205 | test_my_matrix_vector<ublas::mapped_vector<float, ublas::map_array<std::size_t, float> >, |
---|
206 | ublas::generalized_vector_of_vector<float, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<float, ublas::map_array<std::size_t, float> >, ublas::map_array<std::size_t, ublas::mapped_vector<float, ublas::map_array<std::size_t, float> > > > >, 3 > () (); |
---|
207 | #endif |
---|
208 | |
---|
209 | #ifdef USE_DOUBLE |
---|
210 | std::cout << "double, generalized_vector_of_vector map_array" << std::endl; |
---|
211 | test_my_matrix_vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> >, |
---|
212 | ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> > > >, 3 > () (); |
---|
213 | test_my_matrix_vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> >, |
---|
214 | ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> >, ublas::map_array<std::size_t, ublas::mapped_vector<double, ublas::map_array<std::size_t, double> > > > >, 3 > () (); |
---|
215 | #endif |
---|
216 | |
---|
217 | #ifdef USE_STD_COMPLEX |
---|
218 | #ifdef USE_FLOAT |
---|
219 | std::cout << "std::complex<float>, generalized_vector_of_vector map_array" << std::endl; |
---|
220 | test_my_matrix_vector<ublas::mapped_vector<std::complex<float>, ublas::map_array<std::size_t, std::complex<float> > >, |
---|
221 | ublas::generalized_vector_of_vector<std::complex<float>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<float>, ublas::map_array<std::size_t, std::complex<float> > > > >, 3 > () (); |
---|
222 | test_my_matrix_vector<ublas::mapped_vector<std::complex<float>, ublas::map_array<std::size_t, std::complex<float> > >, |
---|
223 | ublas::generalized_vector_of_vector<std::complex<float>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<float>, ublas::map_array<std::size_t, std::complex<float> > >, ublas::map_array<std::size_t, ublas::mapped_vector<std::complex<float>, ublas::map_array<std::size_t, std::complex<float> > > > > >, 3 > () (); |
---|
224 | #endif |
---|
225 | |
---|
226 | #ifdef USE_DOUBLE |
---|
227 | std::cout << "std::complex<double>, generalized_vector_of_vector map_array" << std::endl; |
---|
228 | test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >, |
---|
229 | ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > > > >, 3 > () (); |
---|
230 | test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >, |
---|
231 | ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >, ublas::map_array<std::size_t, ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > > > > >, 3 > () (); |
---|
232 | #endif |
---|
233 | #endif |
---|
234 | #endif |
---|
235 | |
---|
236 | #ifdef USE_STD_MAP |
---|
237 | #ifdef USE_FLOAT |
---|
238 | std::cout << "float, generalized_vector_of_vector std::map" << std::endl; |
---|
239 | test_my_matrix_vector<ublas::mapped_vector<float, std::map<std::size_t, float> >, |
---|
240 | ublas::generalized_vector_of_vector<float, ublas::row_major, ublas::vector<ublas::mapped_vector<float, std::map<std::size_t, float> > > >, 3 > () (); |
---|
241 | test_my_matrix_vector<ublas::mapped_vector<float, std::map<std::size_t, float> >, |
---|
242 | ublas::generalized_vector_of_vector<float, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<float, std::map<std::size_t, float> >, std::map<std::size_t, ublas::mapped_vector<float, std::map<std::size_t, float> > > > >, 3 > () (); |
---|
243 | #endif |
---|
244 | |
---|
245 | #ifdef USE_DOUBLE |
---|
246 | std::cout << "double, generalized_vector_of_vector std::map" << std::endl; |
---|
247 | test_my_matrix_vector<ublas::mapped_vector<double, std::map<std::size_t, double> >, |
---|
248 | ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::vector<ublas::mapped_vector<double, std::map<std::size_t, double> > > >, 3 > () (); |
---|
249 | test_my_matrix_vector<ublas::mapped_vector<double, std::map<std::size_t, double> >, |
---|
250 | ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<double, std::map<std::size_t, double> >, std::map<std::size_t, ublas::mapped_vector<double, std::map<std::size_t, double> > > > >, 3 > () (); |
---|
251 | #endif |
---|
252 | |
---|
253 | #ifdef USE_STD_COMPLEX |
---|
254 | #ifdef USE_FLOAT |
---|
255 | std::cout << "std::complex<float>, generalized_vector_of_vector std::map" << std::endl; |
---|
256 | test_my_matrix_vector<ublas::mapped_vector<std::complex<float>, std::map<std::size_t, std::complex<float> > >, |
---|
257 | ublas::generalized_vector_of_vector<std::complex<float>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<float>, std::map<std::size_t, std::complex<float> > > > >, 3 > () (); |
---|
258 | test_my_matrix_vector<ublas::mapped_vector<std::complex<float>, std::map<std::size_t, std::complex<float> > >, |
---|
259 | ublas::generalized_vector_of_vector<std::complex<float>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<float>, std::map<std::size_t, std::complex<float> > >, std::map<std::size_t, ublas::mapped_vector<std::complex<float>, std::map<std::size_t, std::complex<float> > > > > >, 3 > () (); |
---|
260 | #endif |
---|
261 | |
---|
262 | #ifdef USE_DOUBLE |
---|
263 | std::cout << "std::complex<double>, generalized_vector_of_vector std::map" << std::endl; |
---|
264 | test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > >, |
---|
265 | ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > > > >, 3 > () (); |
---|
266 | test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > >, |
---|
267 | ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > >, std::map<std::size_t, ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > > > > >, 3 > () (); |
---|
268 | #endif |
---|
269 | #endif |
---|
270 | #endif |
---|
271 | #endif |
---|
272 | |
---|
273 | #ifdef USE_COMPRESSED_MATRIX |
---|
274 | #ifdef USE_FLOAT |
---|
275 | std::cout << "float compressed" << std::endl; |
---|
276 | test_my_matrix_vector<ublas::compressed_vector<float>, |
---|
277 | ublas::compressed_matrix<float>, 3 > () (); |
---|
278 | #endif |
---|
279 | |
---|
280 | #ifdef USE_DOUBLE |
---|
281 | std::cout << "double compressed" << std::endl; |
---|
282 | test_my_matrix_vector<ublas::compressed_vector<double>, |
---|
283 | ublas::compressed_matrix<double>, 3 > () (); |
---|
284 | #endif |
---|
285 | |
---|
286 | #ifdef USE_STD_COMPLEX |
---|
287 | #ifdef USE_FLOAT |
---|
288 | std::cout << "std::complex<float> compressed" << std::endl; |
---|
289 | test_my_matrix_vector<ublas::compressed_vector<std::complex<float> >, |
---|
290 | ublas::compressed_matrix<std::complex<float> >, 3 > () (); |
---|
291 | #endif |
---|
292 | |
---|
293 | #ifdef USE_DOUBLE |
---|
294 | std::cout << "std::complex<double> compressed" << std::endl; |
---|
295 | test_my_matrix_vector<ublas::compressed_vector<std::complex<double> >, |
---|
296 | ublas::compressed_matrix<std::complex<double> >, 3 > () (); |
---|
297 | #endif |
---|
298 | #endif |
---|
299 | #endif |
---|
300 | |
---|
301 | #ifdef USE_COORDINATE_MATRIX |
---|
302 | #ifdef USE_FLOAT |
---|
303 | std::cout << "float coordinate" << std::endl; |
---|
304 | test_my_matrix_vector<ublas::coordinate_vector<float>, |
---|
305 | ublas::coordinate_matrix<float>, 3 > () (); |
---|
306 | #endif |
---|
307 | |
---|
308 | #ifdef USE_DOUBLE |
---|
309 | std::cout << "double coordinate" << std::endl; |
---|
310 | test_my_matrix_vector<ublas::coordinate_vector<double>, |
---|
311 | ublas::coordinate_matrix<double>, 3 > () (); |
---|
312 | #endif |
---|
313 | |
---|
314 | #ifdef USE_STD_COMPLEX |
---|
315 | #ifdef USE_FLOAT |
---|
316 | std::cout << "std::complex<float> coordinate" << std::endl; |
---|
317 | test_my_matrix_vector<ublas::coordinate_vector<std::complex<float> >, |
---|
318 | ublas::coordinate_matrix<std::complex<float> >, 3 > () (); |
---|
319 | #endif |
---|
320 | |
---|
321 | #ifdef USE_DOUBLE |
---|
322 | std::cout << "std::complex<double> coordinate" << std::endl; |
---|
323 | test_my_matrix_vector<ublas::coordinate_vector<std::complex<double> >, |
---|
324 | ublas::coordinate_matrix<std::complex<double> >, 3 > () (); |
---|
325 | #endif |
---|
326 | #endif |
---|
327 | #endif |
---|
328 | } |
---|