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 "test4.hpp" |
14 | #include "utils.hpp" |
15 | |
16 | // Test matrix & vector expression templates |
17 | template<class V, class M, int N> |
18 | struct test_my_matrix_vector { |
19 | typedef typename V::value_type value_type; |
20 | |
21 | template<class VP, class MP> |
22 | void test_with (VP &v1, VP &v2, MP &m1) const { |
23 | { |
24 | #ifndef USE_DIAGONAL |
25 | // Rows and columns |
26 | initialize_matrix (m1); |
27 | for (int i = 0; i < N; ++ i) { |
28 | v2 = ublas::row (m1, i); |
29 | std::cout << "row (m, " << i << ") = " << v2 << std::endl; |
30 | v2 = ublas::column (m1, i); |
31 | std::cout << "column (m, " << i << ") = " << v2 << std::endl; |
32 | } |
33 | |
34 | // Outer product |
35 | initialize_vector (v1); |
36 | initialize_vector (v2); |
37 | v1 (0) = 0; |
38 | v1 (N - 1) = 0; |
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 | #else |
50 | BOOST_UBLAS_NOT_USED(v1); |
51 | BOOST_UBLAS_NOT_USED(v2); |
52 | BOOST_UBLAS_NOT_USED(m1); |
53 | #endif |
54 | } |
55 | } |
56 | void operator () () const { |
57 | { |
58 | V v1 (N), v2 (N); |
59 | #ifdef USE_BANDED |
60 | M m1 (N, N, 1, 1); |
61 | #endif |
62 | #ifdef USE_DIAGONAL |
63 | M m1 (N, N); |
64 | #endif |
65 | test_with (v1, v2, m1); |
66 | |
67 | ublas::matrix_row<M> mr1 (m1, 1), mr2 (m1, 1); |
68 | test_with (mr1, mr2, m1); |
69 | |
70 | ublas::matrix_column<M> mc1 (m1, 1), mc2 (m1, 1); |
71 | test_with (mc1, mc2, m1); |
72 | |
73 | #ifdef USE_RANGE |
74 | ublas::matrix_vector_range<M> mvr1 (m1, ublas::range (0, N), ublas::range (0, N)), |
75 | mvr2 (m1, ublas::range (0, N), ublas::range (0, N)); |
76 | test_with (mvr1, mvr2, m1); |
77 | #endif |
78 | |
79 | #ifdef USE_SLICE |
80 | ublas::matrix_vector_slice<M> mvs1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), |
81 | mvs2 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); |
82 | test_with (mvs1, mvs2, m1); |
83 | #endif |
84 | } |
85 | } |
86 | |
87 | void operator () (int) const { |
88 | #ifdef USE_ADAPTOR |
89 | { |
90 | #ifdef USE_BANDED |
91 | V v1 (N), v2 (N); |
92 | M m1 (N, N, 1, 1); |
93 | ublas::banded_adaptor<M> bam1 (m1, 1, 1); |
94 | test_with (v1, v2, bam1); |
95 | |
96 | ublas::matrix_row<ublas::banded_adaptor<M> > mr1 (bam1, 1), mr2 (bam1, 1); |
97 | test_with (mr1, mr2, bam1); |
98 | |
99 | ublas::matrix_column<ublas::banded_adaptor<M> > mc1 (bam1, 1), mc2 (bam1, 1); |
100 | test_with (mc1, mc2, bam1); |
101 | |
102 | #ifdef USE_RANGE |
103 | ublas::matrix_vector_range<ublas::banded_adaptor<M> > mvr1 (bam1, ublas::range (0, N), ublas::range (0, N)), |
104 | mvr2 (bam1, ublas::range (0, N), ublas::range (0, N)); |
105 | test_with (mvr1, mvr2, bam1); |
106 | #endif |
107 | |
108 | #ifdef USE_SLICE |
109 | ublas::matrix_vector_slice<ublas::banded_adaptor<M> > mvs1 (bam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), |
110 | mvs2 (bam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); |
111 | test_with (mvs1, mvs2, bam1); |
112 | #endif |
113 | #endif |
114 | #ifdef USE_DIAGONAL |
115 | V v1 (N), v2 (N); |
116 | M m1 (N, N); |
117 | ublas::diagonal_adaptor<M> dam1 (m1); |
118 | test_with (v1, v2, dam1); |
119 | |
120 | ublas::matrix_row<ublas::diagonal_adaptor<M> > mr1 (dam1, 1), mr2 (dam1, 1); |
121 | test_with (mr1, mr2, dam1); |
122 | |
123 | ublas::matrix_column<ublas::diagonal_adaptor<M> > mc1 (dam1, 1), mc2 (dam1, 1); |
124 | test_with (mc1, mc2, dam1); |
125 | |
126 | #ifdef USE_RANGE |
127 | ublas::matrix_vector_range<ublas::diagonal_adaptor<M> > mvr1 (dam1, ublas::range (0, N), ublas::range (0, N)), |
128 | mvr2 (dam1, ublas::range (0, N), ublas::range (0, N)); |
129 | test_with (mvr1, mvr2, dam1); |
130 | #endif |
131 | |
132 | #ifdef USE_SLICE |
133 | ublas::matrix_vector_slice<ublas::diagonal_adaptor<M> > mvs1 (dam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), |
134 | mvs2 (dam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); |
135 | test_with (mvs1, mvs2, dam1); |
136 | #endif |
137 | #endif |
138 | } |
139 | #endif |
140 | } |
141 | }; |
142 | |
143 | // Test matrix & vector |
144 | void test_matrix_vector () { |
145 | std::cout << "test_matrix_vector" << std::endl; |
146 | |
147 | #ifdef USE_BANDED |
148 | #ifdef USE_BOUNDED_ARRAY |
149 | #ifdef USE_FLOAT |
150 | std::cout << "float, bounded_array" << std::endl; |
151 | test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >, |
152 | ublas::banded_matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () (); |
153 | test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >, |
154 | ublas::banded_matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () (0); |
155 | #endif |
156 | |
157 | #ifdef USE_DOUBLE |
158 | std::cout << "double, bounded_array" << std::endl; |
159 | test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, |
160 | ublas::banded_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (); |
161 | test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, |
162 | ublas::banded_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (0); |
163 | #endif |
164 | |
165 | #ifdef USE_STD_COMPLEX |
166 | #ifdef USE_FLOAT |
167 | std::cout << "std::complex<float>, bounded_array" << std::endl; |
168 | test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >, |
169 | ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () (); |
170 | test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >, |
171 | ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () (0); |
172 | #endif |
173 | |
174 | #ifdef USE_DOUBLE |
175 | std::cout << "std::complex<double>, bounded_array" << std::endl; |
176 | test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, |
177 | ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (); |
178 | test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, |
179 | ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (0); |
180 | #endif |
181 | #endif |
182 | #endif |
183 | |
184 | #ifdef USE_UNBOUNDED_ARRAY |
185 | #ifdef USE_FLOAT |
186 | std::cout << "float, unbounded_array" << std::endl; |
187 | test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >, |
188 | ublas::banded_matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3> () (); |
189 | test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >, |
190 | ublas::banded_matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3> () (0); |
191 | #endif |
192 | |
193 | #ifdef USE_DOUBLE |
194 | std::cout << "double, unbounded_array" << std::endl; |
195 | test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, |
196 | ublas::banded_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3> () (); |
197 | test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, |
198 | ublas::banded_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3> () (0); |
199 | #endif |
200 | |
201 | #ifdef USE_STD_COMPLEX |
202 | #ifdef USE_FLOAT |
203 | std::cout << "std::complex<float>, unbounded_array" << std::endl; |
204 | test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >, |
205 | ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () (); |
206 | test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >, |
207 | ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () (0); |
208 | #endif |
209 | |
210 | #ifdef USE_DOUBLE |
211 | std::cout << "std::complex<double>, unbounded_array" << std::endl; |
212 | test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, |
213 | ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (); |
214 | test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, |
215 | ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (0); |
216 | #endif |
217 | #endif |
218 | #endif |
219 | |
220 | #ifdef USE_STD_VECTOR |
221 | #ifdef USE_FLOAT |
222 | std::cout << "float, std::vector" << std::endl; |
223 | test_my_matrix_vector<ublas::vector<float, std::vector<float> >, |
224 | ublas::banded_matrix<float, ublas::row_major, std::vector<float> >, 3> () (); |
225 | test_my_matrix_vector<ublas::vector<float, std::vector<float> >, |
226 | ublas::banded_matrix<float, ublas::row_major, std::vector<float> >, 3> () (0); |
227 | #endif |
228 | |
229 | #ifdef USE_DOUBLE |
230 | std::cout << "double, std::vector" << std::endl; |
231 | test_my_matrix_vector<ublas::vector<double, std::vector<double> >, |
232 | ublas::banded_matrix<double, ublas::row_major, std::vector<double> >, 3> () (); |
233 | test_my_matrix_vector<ublas::vector<double, std::vector<double> >, |
234 | ublas::banded_matrix<double, ublas::row_major, std::vector<double> >, 3> () (0); |
235 | #endif |
236 | |
237 | #ifdef USE_STD_COMPLEX |
238 | #ifdef USE_FLOAT |
239 | std::cout << "std::complex<float>, std::vector" << std::endl; |
240 | test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >, |
241 | ublas::banded_matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3> () (); |
242 | test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >, |
243 | ublas::banded_matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3> () (0); |
244 | #endif |
245 | |
246 | #ifdef USE_DOUBLE |
247 | std::cout << "std::complex<double>, std::vector" << std::endl; |
248 | test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, |
249 | ublas::banded_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3> () (); |
250 | test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, |
251 | ublas::banded_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3> () (0); |
252 | #endif |
253 | #endif |
254 | #endif |
255 | #endif |
256 | |
257 | #ifdef USE_DIAGONAL |
258 | #ifdef USE_BOUNDED_ARRAY |
259 | #ifdef USE_FLOAT |
260 | std::cout << "float, bounded_array" << std::endl; |
261 | test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >, |
262 | ublas::diagonal_matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () (); |
263 | test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >, |
264 | ublas::diagonal_matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () (0); |
265 | #endif |
266 | |
267 | #ifdef USE_DOUBLE |
268 | std::cout << "double, bounded_array" << std::endl; |
269 | test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, |
270 | ublas::diagonal_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (); |
271 | test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, |
272 | ublas::diagonal_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (0); |
273 | #endif |
274 | |
275 | #ifdef USE_STD_COMPLEX |
276 | #ifdef USE_FLOAT |
277 | std::cout << "std::complex<float>, bounded_array" << std::endl; |
278 | test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >, |
279 | ublas::diagonal_matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () (); |
280 | test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >, |
281 | ublas::diagonal_matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () (0); |
282 | #endif |
283 | |
284 | #ifdef USE_DOUBLE |
285 | std::cout << "std::complex<double>, bounded_array" << std::endl; |
286 | test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, |
287 | ublas::diagonal_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (); |
288 | test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, |
289 | ublas::diagonal_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (0); |
290 | #endif |
291 | #endif |
292 | #endif |
293 | |
294 | #ifdef USE_UNBOUNDED_ARRAY |
295 | #ifdef USE_FLOAT |
296 | std::cout << "float, unbounded_array" << std::endl; |
297 | test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >, |
298 | ublas::diagonal_matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3> () (); |
299 | test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >, |
300 | ublas::diagonal_matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3> () (0); |
301 | #endif |
302 | |
303 | #ifdef USE_DOUBLE |
304 | std::cout << "double, unbounded_array" << std::endl; |
305 | test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, |
306 | ublas::diagonal_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3> () (); |
307 | test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, |
308 | ublas::diagonal_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3> () (0); |
309 | #endif |
310 | |
311 | #ifdef USE_STD_COMPLEX |
312 | #ifdef USE_FLOAT |
313 | std::cout << "std::complex<float>, unbounded_array" << std::endl; |
314 | test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >, |
315 | ublas::diagonal_matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () (); |
316 | test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >, |
317 | ublas::diagonal_matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () (0); |
318 | #endif |
319 | |
320 | #ifdef USE_DOUBLE |
321 | std::cout << "std::complex<double>, unbounded_array" << std::endl; |
322 | test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, |
323 | ublas::diagonal_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (); |
324 | test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, |
325 | ublas::diagonal_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (0); |
326 | #endif |
327 | #endif |
328 | #endif |
329 | |
330 | #ifdef USE_STD_VECTOR |
331 | #ifdef USE_FLOAT |
332 | std::cout << "float, std::vector" << std::endl; |
333 | test_my_matrix_vector<ublas::vector<float, std::vector<float> >, |
334 | ublas::diagonal_matrix<float, ublas::row_major, std::vector<float> >, 3> () (); |
335 | test_my_matrix_vector<ublas::vector<float, std::vector<float> >, |
336 | ublas::diagonal_matrix<float, ublas::row_major, std::vector<float> >, 3> () (0); |
337 | #endif |
338 | |
339 | #ifdef USE_DOUBLE |
340 | std::cout << "double, std::vector" << std::endl; |
341 | test_my_matrix_vector<ublas::vector<double, std::vector<double> >, |
342 | ublas::diagonal_matrix<double, ublas::row_major, std::vector<double> >, 3> () (); |
343 | test_my_matrix_vector<ublas::vector<double, std::vector<double> >, |
344 | ublas::diagonal_matrix<double, ublas::row_major, std::vector<double> >, 3> () (0); |
345 | #endif |
346 | |
347 | #ifdef USE_STD_COMPLEX |
348 | #ifdef USE_FLOAT |
349 | std::cout << "std::complex<float>, std::vector" << std::endl; |
350 | test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >, |
351 | ublas::diagonal_matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3> () (); |
352 | test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >, |
353 | ublas::diagonal_matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3> () (0); |
354 | #endif |
355 | |
356 | #ifdef USE_DOUBLE |
357 | std::cout << "std::complex<double>, std::vector" << std::endl; |
358 | test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, |
359 | ublas::diagonal_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3> () (); |
360 | test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, |
361 | ublas::diagonal_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3> () (0); |
362 | #endif |
363 | #endif |
364 | #endif |
365 | #endif |
366 | } |
367 | |