2 // Copyright (c) 2000-2002
3 // Joerg Walter, Mathias Koch
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)
9 // The authors gratefully acknowledge the support of
10 // GeNeSys mbH & Co. KG in producing this work.
13 #if defined(__GNUC__) && (__GNUC__ >= 9)
14 #pragma GCC diagnostic ignored "-Wdeprecated-copy"
19 // Test matrix & vector expression templates
20 template <class V, class M, int N>
21 struct test_my_matrix_vector
23 typedef typename V::value_type value_type;
25 template <class VP, class MP>
26 void test_with(VP& v1, VP& v2, MP& m1) const
30 initialize_matrix(m1);
31 for (int i = 0; i < N; ++i)
33 v1 = ublas::row(m1, i);
34 std::cout << "row (m, " << i << ") = " << v1 << std::endl;
35 v1 = ublas::column(m1, i);
36 std::cout << "column (m, " << i << ") = " << v1 << std::endl;
40 initialize_vector(v1);
41 initialize_vector(v2);
42 m1 = ublas::outer_prod(v1, v2);
43 std::cout << "outer_prod (v1, v2) = " << m1 << std::endl;
45 // Matrix vector product
46 initialize_matrix(m1);
47 initialize_vector(v1);
48 v2 = ublas::prod(m1, v1);
49 std::cout << "prod (m1, v1) = " << v2 << std::endl;
50 v2 = ublas::prod(v1, m1);
51 std::cout << "prod (v1, m1) = " << v2 << std::endl;
54 void operator()() const
59 test_with(v1, v2, m1);
61 ublas::matrix_row<M> mr1(m1, 0), mr2(m1, 1);
62 test_with(mr1, mr2, m1);
64 ublas::matrix_column<M> mc1(m1, 0), mc2(m1, 1);
65 test_with(mc1, mc2, m1);
68 ublas::matrix_vector_range<M> mvr1(m1, ublas::range(0, N), ublas::range(0, N)),
69 mvr2(m1, ublas::range(0, N), ublas::range(0, N));
70 test_with(mvr1, mvr2, m1);
74 ublas::matrix_vector_slice<M> mvs1(m1, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
75 mvs2(m1, ublas::slice(0, 1, N), ublas::slice(0, 1, N));
76 test_with(mvs1, mvs2, m1);
82 // Test matrix & vector
83 void test_matrix_vector()
85 std::cout << "test_matrix_vector" << std::endl;
88 #ifdef USE_BOUNDED_ARRAY
90 std::cout << "mp_test_type, bounded_array" << std::endl;
91 test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >,
92 ublas::matrix<mp_test_type, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3>()();
96 std::cout << "double, bounded_array" << std::endl;
97 test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
98 ublas::matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3>()();
101 #ifdef USE_STD_COMPLEX
103 std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl;
104 test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >,
105 ublas::matrix<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3>()();
109 std::cout << "std::complex<double>, bounded_array" << std::endl;
110 test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
111 ublas::matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3>()();
116 #ifdef USE_UNBOUNDED_ARRAY
118 std::cout << "mp_test_type, unbounded_array" << std::endl;
119 test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >,
120 ublas::matrix<mp_test_type, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3>()();
124 std::cout << "double, unbounded_array" << std::endl;
125 test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
126 ublas::matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3>()();
129 #ifdef USE_STD_COMPLEX
131 std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl;
132 test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >,
133 ublas::matrix<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3>()();
137 std::cout << "std::complex<double>, unbounded_array" << std::endl;
138 test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
139 ublas::matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3>()();
144 #ifdef USE_STD_VECTOR
146 std::cout << "mp_test_type, std::vector" << std::endl;
147 test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >,
148 ublas::matrix<mp_test_type, ublas::row_major, std::vector<mp_test_type> >, 3>()();
152 std::cout << "double, std::vector" << std::endl;
153 test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
154 ublas::matrix<double, ublas::row_major, std::vector<double> >, 3>()();
157 #ifdef USE_STD_COMPLEX
159 std::cout << "std::complex<mp_test_type>, std::vector" << std::endl;
160 test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >,
161 ublas::matrix<std::complex<mp_test_type>, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3>()();
165 std::cout << "std::complex<double>, std::vector" << std::endl;
166 test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
167 ublas::matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3>()();
173 #ifdef USE_BOUNDED_MATRIX
175 std::cout << "mp_test_type, bounded" << std::endl;
176 test_my_matrix_vector<ublas::bounded_vector<mp_test_type, 3>,
177 ublas::bounded_matrix<mp_test_type, 3, 3>, 3>()();
181 std::cout << "double, bounded" << std::endl;
182 test_my_matrix_vector<ublas::bounded_vector<double, 3>,
183 ublas::bounded_matrix<double, 3, 3>, 3>()();
186 #ifdef USE_STD_COMPLEX
188 std::cout << "std::complex<mp_test_type>, bounded" << std::endl;
189 test_my_matrix_vector<ublas::bounded_vector<std::complex<mp_test_type>, 3>,
190 ublas::bounded_matrix<std::complex<mp_test_type>, 3, 3>, 3>()();
194 std::cout << "std::complex<double>, bounded" << std::endl;
195 test_my_matrix_vector<ublas::bounded_vector<std::complex<double>, 3>,
196 ublas::bounded_matrix<std::complex<double>, 3, 3>, 3>()();
201 #ifdef USE_VECTOR_OF_VECTOR
202 #ifdef USE_BOUNDED_ARRAY
204 std::cout << "mp_test_type, bounded_array" << std::endl;
205 test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >,
206 ublas::vector_of_vector<mp_test_type, ublas::row_major, ublas::bounded_array<ublas::bounded_array<mp_test_type, 3>, 3 + 1> >, 3>()();
210 std::cout << "double, bounded_array" << std::endl;
211 test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
212 ublas::vector_of_vector<double, ublas::row_major, ublas::bounded_array<ublas::bounded_array<double, 3>, 3 + 1> >, 3>()();
215 #ifdef USE_STD_COMPLEX
217 std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl;
218 test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >,
219 ublas::vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<mp_test_type>, 3>, 3 + 1> >, 3>()();
223 std::cout << "std::complex<double>, bounded_array" << std::endl;
224 test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
225 ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<double>, 3>, 3 + 1> >, 3>()();
230 #ifdef USE_UNBOUNDED_ARRAY
232 std::cout << "mp_test_type, unbounded_array" << std::endl;
233 test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >,
234 ublas::vector_of_vector<mp_test_type, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<mp_test_type> > >, 3>()();
238 std::cout << "double, unbounded_array" << std::endl;
239 test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
240 ublas::vector_of_vector<double, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<double> > >, 3>()();
243 #ifdef USE_STD_COMPLEX
245 std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl;
246 test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >,
247 ublas::vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<mp_test_type> > > >, 3>()();
251 std::cout << "std::complex<double>, unbounded_array" << std::endl;
252 test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
253 ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<double> > > >, 3>()();
258 #ifdef USE_STD_VECTOR
260 std::cout << "mp_test_type, std::vector" << std::endl;
261 test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >,
262 ublas::vector_of_vector<mp_test_type, ublas::row_major, std::vector<std::vector<mp_test_type> > >, 3>()();
266 std::cout << "double, std::vector" << std::endl;
267 test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
268 ublas::vector_of_vector<double, ublas::row_major, std::vector<std::vector<double> > >, 3>()();
271 #ifdef USE_STD_COMPLEX
273 std::cout << "std::complex<mp_test_type>, std::vector" << std::endl;
274 test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >,
275 ublas::vector_of_vector<std::complex<mp_test_type>, ublas::row_major, std::vector<std::vector<std::complex<mp_test_type> > > >, 3>()();
279 std::cout << "std::complex<double>, std::vector" << std::endl;
280 test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
281 ublas::vector_of_vector<std::complex<double>, ublas::row_major, std::vector<std::vector<std::complex<double> > > >, 3>()();