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