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