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 "test1.hpp"
14
15// Test matrix & vector expression templates
16template<class V, class M, int N>
17struct 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), v2 (N);
50 M m1 (N, N);
51 test_with (v1, v2, m1);
52
53 ublas::matrix_row<M> mr1 (m1, 0), mr2 (m1, 1);
54 test_with (mr1, mr2, m1);
55
56 ublas::matrix_column<M> mc1 (m1, 0), mc2 (m1, 1);
57 test_with (mc1, mc2, m1);
58
59#ifdef USE_RANGE
60 ublas::matrix_vector_range<M> mvr1 (m1, ublas::range (0, N), ublas::range (0, N)),
61 mvr2 (m1, ublas::range (0, N), ublas::range (0, N));
62 test_with (mvr1, mvr2, m1);
63#endif
64
65#ifdef USE_SLICE
66 ublas::matrix_vector_slice<M> mvs1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
67 mvs2 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N));
68 test_with (mvs1, mvs2, m1);
69#endif
70 }
71 }
72};
73
74// Test matrix & vector
75void test_matrix_vector () {
76 std::cout << "test_matrix_vector" << std::endl;
77
78#ifdef USE_MATRIX
79#ifdef USE_BOUNDED_ARRAY
80#ifdef USE_FLOAT
81 std::cout << "float, bounded_array" << std::endl;
82 test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >,
83 ublas::matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () ();
84#endif
85
86#ifdef USE_DOUBLE
87 std::cout << "double, bounded_array" << std::endl;
88 test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
89 ublas::matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () ();
90#endif
91
92#ifdef USE_STD_COMPLEX
93#ifdef USE_FLOAT
94 std::cout << "std::complex<float>, bounded_array" << std::endl;
95 test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >,
96 ublas::matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () ();
97#endif
98
99#ifdef USE_DOUBLE
100 std::cout << "std::complex<double>, bounded_array" << std::endl;
101 test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
102 ublas::matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () ();
103#endif
104#endif
105#endif
106
107#ifdef USE_UNBOUNDED_ARRAY
108#ifdef USE_FLOAT
109 std::cout << "float, unbounded_array" << std::endl;
110 test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >,
111 ublas::matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3> () ();
112#endif
113
114#ifdef USE_DOUBLE
115 std::cout << "double, unbounded_array" << std::endl;
116 test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
117 ublas::matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3> () ();
118#endif
119
120#ifdef USE_STD_COMPLEX
121#ifdef USE_FLOAT
122 std::cout << "std::complex<float>, unbounded_array" << std::endl;
123 test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >,
124 ublas::matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () ();
125#endif
126
127#ifdef USE_DOUBLE
128 std::cout << "std::complex<double>, unbounded_array" << std::endl;
129 test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
130 ublas::matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () ();
131#endif
132#endif
133#endif
134
135#ifdef USE_STD_VECTOR
136#ifdef USE_FLOAT
137 std::cout << "float, std::vector" << std::endl;
138 test_my_matrix_vector<ublas::vector<float, std::vector<float> >,
139 ublas::matrix<float, ublas::row_major, std::vector<float> >, 3> () ();
140#endif
141
142#ifdef USE_DOUBLE
143 std::cout << "double, std::vector" << std::endl;
144 test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
145 ublas::matrix<double, ublas::row_major, std::vector<double> >, 3> () ();
146#endif
147
148#ifdef USE_STD_COMPLEX
149#ifdef USE_FLOAT
150 std::cout << "std::complex<float>, std::vector" << std::endl;
151 test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >,
152 ublas::matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3> () ();
153#endif
154
155#ifdef USE_DOUBLE
156 std::cout << "std::complex<double>, std::vector" << std::endl;
157 test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
158 ublas::matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3> () ();
159#endif
160#endif
161#endif
162#endif
163
164#ifdef USE_BOUNDED_MATRIX
165#ifdef USE_FLOAT
166 std::cout << "float, bounded" << std::endl;
167 test_my_matrix_vector<ublas::bounded_vector<float, 3>,
168 ublas::bounded_matrix<float, 3, 3>, 3> () ();
169#endif
170
171#ifdef USE_DOUBLE
172 std::cout << "double, bounded" << std::endl;
173 test_my_matrix_vector<ublas::bounded_vector<double, 3>,
174 ublas::bounded_matrix<double, 3, 3>, 3> () ();
175#endif
176
177#ifdef USE_STD_COMPLEX
178#ifdef USE_FLOAT
179 std::cout << "std::complex<float>, bounded" << std::endl;
180 test_my_matrix_vector<ublas::bounded_vector<std::complex<float>, 3>,
181 ublas::bounded_matrix<std::complex<float>, 3, 3>, 3> () ();
182#endif
183
184#ifdef USE_DOUBLE
185 std::cout << "std::complex<double>, bounded" << std::endl;
186 test_my_matrix_vector<ublas::bounded_vector<std::complex<double>, 3>,
187 ublas::bounded_matrix<std::complex<double>, 3, 3>, 3> () ();
188#endif
189#endif
190#endif
191
192#ifdef USE_VECTOR_OF_VECTOR
193#ifdef USE_BOUNDED_ARRAY
194#ifdef USE_FLOAT
195 std::cout << "float, bounded_array" << std::endl;
196 test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >,
197 ublas::vector_of_vector<float, ublas::row_major, ublas::bounded_array<ublas::bounded_array<float, 3>, 3 + 1> >, 3> () ();
198#endif
199
200#ifdef USE_DOUBLE
201 std::cout << "double, bounded_array" << std::endl;
202 test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
203 ublas::vector_of_vector<double, ublas::row_major, ublas::bounded_array<ublas::bounded_array<double, 3>, 3 + 1> >, 3> () ();
204#endif
205
206#ifdef USE_STD_COMPLEX
207#ifdef USE_FLOAT
208 std::cout << "std::complex<float>, bounded_array" << std::endl;
209 test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >,
210 ublas::vector_of_vector<std::complex<float>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<float>, 3>, 3 + 1> >, 3> () ();
211#endif
212
213#ifdef USE_DOUBLE
214 std::cout << "std::complex<double>, bounded_array" << std::endl;
215 test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
216 ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<double>, 3>, 3 + 1> >, 3> () ();
217#endif
218#endif
219#endif
220
221#ifdef USE_UNBOUNDED_ARRAY
222#ifdef USE_FLOAT
223 std::cout << "float, unbounded_array" << std::endl;
224 test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >,
225 ublas::vector_of_vector<float, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<float> > >, 3> () ();
226#endif
227
228#ifdef USE_DOUBLE
229 std::cout << "double, unbounded_array" << std::endl;
230 test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
231 ublas::vector_of_vector<double, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<double> > >, 3> () ();
232#endif
233
234#ifdef USE_STD_COMPLEX
235#ifdef USE_FLOAT
236 std::cout << "std::complex<float>, unbounded_array" << std::endl;
237 test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >,
238 ublas::vector_of_vector<std::complex<float>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<float> > > >, 3> () ();
239#endif
240
241#ifdef USE_DOUBLE
242 std::cout << "std::complex<double>, unbounded_array" << std::endl;
243 test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
244 ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<double> > > >, 3> () ();
245#endif
246#endif
247#endif
248
249#ifdef USE_STD_VECTOR
250#ifdef USE_FLOAT
251 std::cout << "float, std::vector" << std::endl;
252 test_my_matrix_vector<ublas::vector<float, std::vector<float> >,
253 ublas::vector_of_vector<float, ublas::row_major, std::vector<std::vector<float> > >, 3> () ();
254#endif
255
256#ifdef USE_DOUBLE
257 std::cout << "double, std::vector" << std::endl;
258 test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
259 ublas::vector_of_vector<double, ublas::row_major, std::vector<std::vector<double> > >, 3> () ();
260#endif
261
262#ifdef USE_STD_COMPLEX
263#ifdef USE_FLOAT
264 std::cout << "std::complex<float>, std::vector" << std::endl;
265 test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >,
266 ublas::vector_of_vector<std::complex<float>, ublas::row_major, std::vector<std::vector<std::complex<float> > > >, 3> () ();
267#endif
268
269#ifdef USE_DOUBLE
270 std::cout << "std::complex<double>, std::vector" << std::endl;
271 test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
272 ublas::vector_of_vector<std::complex<double>, ublas::row_major, std::vector<std::vector<std::complex<double> > > >, 3> () ();
273#endif
274#endif
275#endif
276#endif
277}
278

source code of boost/libs/numeric/ublas/test/test12.cpp