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 "test5.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 v2 = ublas::row (m1, i);
27 std::cout << "row (m, " << i << ") = " << v2 << std::endl;
28 v2 = ublas::column (m1, i);
29 std::cout << "column (m, " << i << ") = " << v2 << std::endl;
30 }
31
32 // Outer product
33 initialize_vector (v1);
34 initialize_vector (v2);
35 v1 (0) = 0;
36 v2 (N - 1) = 0;
37 m1 = ublas::outer_prod (v1, v2);
38 std::cout << "outer_prod (v1, v2) = " << m1 << std::endl;
39
40 // Matrix vector product
41 initialize_matrix (m1);
42 initialize_vector (v1);
43 v2 = ublas::prod (m1, v1);
44 std::cout << "prod (m1, v1) = " << v2 << std::endl;
45 v2 = ublas::prod (v1, m1);
46 std::cout << "prod (v1, m1) = " << v2 << std::endl;
47 }
48 }
49 void operator () () const {
50 {
51 V v1 (N), v2 (N);
52 M m1 (N, N);
53 test_with (v1, v2, m1);
54
55 ublas::matrix_row<M> mr1 (m1, N - 1), mr2 (m1, N - 1);
56 test_with (mr1, mr2, m1);
57
58 ublas::matrix_column<M> mc1 (m1, 0), mc2 (m1, 0);
59 test_with (mc1, mc2, m1);
60
61#ifdef USE_RANGE
62 ublas::matrix_vector_range<M> mvr1 (m1, ublas::range (0, N), ublas::range (0, N)),
63 mvr2 (m1, ublas::range (0, N), ublas::range (0, N));
64 test_with (mvr1, mvr2, m1);
65#endif
66
67#ifdef USE_SLICE
68 ublas::matrix_vector_slice<M> mvs1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
69 mvs2 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N));
70 test_with (mvs1, mvs2, m1);
71#endif
72 }
73 }
74
75 void operator () (int) const {
76#ifdef USE_ADAPTOR
77 {
78 V v1 (N), v2 (N);
79 M m1 (N, N);
80 ublas::triangular_adaptor<M> tam1 (m1);
81 test_with (v1, v2, tam1);
82
83 ublas::matrix_row<ublas::triangular_adaptor<M> > mr1 (tam1, N - 1), mr2 (tam1, N - 1);
84 test_with (mr1, mr2, tam1);
85
86 ublas::matrix_column<ublas::triangular_adaptor<M> > mc1 (tam1, 0), mc2 (tam1, 0);
87 test_with (mc1, mc2, tam1);
88
89#ifdef USE_RANGE
90 ublas::matrix_vector_range<ublas::triangular_adaptor<M> > mvr1 (tam1, ublas::range (0, N), ublas::range (0, N)),
91 mvr2 (tam1, ublas::range (0, N), ublas::range (0, N));
92 test_with (mvr1, mvr2, tam1);
93#endif
94
95#ifdef USE_SLICE
96 ublas::matrix_vector_slice<ublas::triangular_adaptor<M> > mvs1 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
97 mvs2 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N));
98 test_with (mvs1, mvs2, tam1);
99#endif
100 }
101#endif
102 }
103};
104
105// Test matrix & vector
106void test_matrix_vector () {
107 std::cout << "test_matrix_vector" << std::endl;
108
109#ifdef USE_BOUNDED_ARRAY
110#ifdef USE_FLOAT
111 std::cout << "float, bounded_array" << std::endl;
112 test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >,
113 ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () ();
114 test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >,
115 ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () (0);
116#endif
117
118#ifdef USE_DOUBLE
119 std::cout << "double, bounded_array" << std::endl;
120 test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
121 ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () ();
122 test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
123 ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (0);
124#endif
125
126#ifdef USE_STD_COMPLEX
127#ifdef USE_FLOAT
128 std::cout << "std::complex<float>, bounded_array" << std::endl;
129 test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >,
130 ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () ();
131 test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >,
132 ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () (0);
133#endif
134
135#ifdef USE_DOUBLE
136 std::cout << "std::complex<double>, bounded_array" << std::endl;
137 test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
138 ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () ();
139 test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
140 ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (0);
141#endif
142#endif
143#endif
144
145#ifdef USE_UNBOUNDED_ARRAY
146#ifdef USE_FLOAT
147 std::cout << "float, unbounded_array" << std::endl;
148 test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >,
149 ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3> () ();
150 test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >,
151 ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3> () (0);
152#endif
153
154#ifdef USE_DOUBLE
155 std::cout << "double, unbounded_array" << std::endl;
156 test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
157 ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3> () ();
158 test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
159 ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3> () (0);
160#endif
161
162#ifdef USE_STD_COMPLEX
163#ifdef USE_FLOAT
164 std::cout << "std::complex<float>, unbounded_array" << std::endl;
165 test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >,
166 ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () ();
167 test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >,
168 ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () (0);
169#endif
170
171#ifdef USE_DOUBLE
172 std::cout << "std::complex<double>, unbounded_array" << std::endl;
173 test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
174 ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () ();
175 test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
176 ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (0);
177#endif
178#endif
179#endif
180
181#ifdef USE_STD_VECTOR
182#ifdef USE_FLOAT
183 std::cout << "float, std::vector" << std::endl;
184 test_my_matrix_vector<ublas::vector<float, std::vector<float> >,
185 ublas::triangular_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3> () ();
186 test_my_matrix_vector<ublas::vector<float, std::vector<float> >,
187 ublas::triangular_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3> () (0);
188#endif
189
190#ifdef USE_DOUBLE
191 std::cout << "double, std::vector" << std::endl;
192 test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
193 ublas::triangular_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3> () ();
194 test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
195 ublas::triangular_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3> () (0);
196#endif
197
198#ifdef USE_STD_COMPLEX
199#ifdef USE_FLOAT
200 std::cout << "std::complex<float>, std::vector" << std::endl;
201 test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >,
202 ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3> () ();
203 test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >,
204 ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3> () (0);
205
206 std::cout << "std::complex<double>, std::vector" << std::endl;
207 test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
208 ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3> () ();
209 test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
210 ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3> () (0);
211#endif
212#endif
213#endif
214}
215

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