]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/ublas/test/test43.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / numeric / ublas / test / test43.cpp
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
15 // Test matrix expression templates
16 template<class M, int N>
17 struct test_my_matrix {
18 typedef typename M::value_type value_type;
19
20 template<class MP>
21 void test_with (MP &m1, MP &m2, MP &m3) const {
22 {
23 value_type t;
24
25 // Default Construct
26 default_construct<MP>::test ();
27
28 // Copy and swap
29 initialize_matrix (m1);
30 initialize_matrix (m2);
31 m1 = m2;
32 std::cout << "m1 = m2 = " << m1 << std::endl;
33 m1.assign_temporary (m2);
34 std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl;
35 m1.swap (m2);
36 std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl;
37
38 // Zero assignment
39 m1 = ublas::zero_matrix<> (m1.size1 (), m1.size2 ());
40 std::cout << "m1.zero_matrix = " << m1 << std::endl;
41 m1 = m2;
42
43 // Unary matrix operations resulting in a matrix
44 initialize_matrix (m1);
45 m2 = - m1;
46 std::cout << "- m1 = " << m2 << std::endl;
47 m2 = ublas::conj (m1);
48 std::cout << "conj (m1) = " << m2 << std::endl;
49
50 // Binary matrix operations resulting in a matrix
51 initialize_matrix (m1);
52 initialize_matrix (m2);
53 m3 = m1 + m2;
54 std::cout << "m1 + m2 = " << m3 << std::endl;
55 m3 = m1 - m2;
56 std::cout << "m1 - m2 = " << m3 << std::endl;
57
58 // Scaling a matrix
59 t = N;
60 initialize_matrix (m1);
61 m2 = value_type (1.) * m1;
62 std::cout << "1. * m1 = " << m2 << std::endl;
63 m2 = t * m1;
64 std::cout << "N * m1 = " << m2 << std::endl;
65 initialize_matrix (m1);
66 m2 = m1 * value_type (1.);
67 std::cout << "m1 * 1. = " << m2 << std::endl;
68 m2 = m1 * t;
69 std::cout << "m1 * N = " << m2 << std::endl;
70
71 // Some assignments
72 initialize_matrix (m1);
73 initialize_matrix (m2);
74 m2 += m1;
75 std::cout << "m2 += m1 = " << m2 << std::endl;
76 m2 -= m1;
77 std::cout << "m2 -= m1 = " << m2 << std::endl;
78 m2 = m2 + m1;
79 std::cout << "m2 = m2 + m1 = " << m2 << std::endl;
80 m2 = m2 - m1;
81 std::cout << "m2 = m2 - m1 = " << m2 << std::endl;
82 m1 *= value_type (1.);
83 std::cout << "m1 *= 1. = " << m1 << std::endl;
84 m1 *= t;
85 std::cout << "m1 *= N = " << m1 << std::endl;
86
87 // Transpose
88 initialize_matrix (m1);
89 m2 = ublas::trans (m1);
90 std::cout << "trans (m1) = " << m2 << std::endl;
91
92 // Hermitean
93 initialize_matrix (m1);
94 m2 = ublas::herm (m1);
95 std::cout << "herm (m1) = " << m2 << std::endl;
96
97 // Matrix multiplication
98 initialize_matrix (m1);
99 initialize_matrix (m2);
100 // Banded times banded isn't banded
101 std::cout << "prod (m1, m2) = " << ublas::prod (m1, m2) << std::endl;
102 }
103 }
104 void operator () () const {
105 {
106 #ifdef USE_BANDED
107 M m1 (N, N, 1, 1), m2 (N, N, 1, 1), m3 (N, N, 1, 1);
108 #endif
109 #ifdef USE_DIAGONAL
110 M m1 (N, N), m2 (N, N), m3 (N, N);
111 #endif
112 test_with (m1, m2, m3);
113
114 #ifdef USE_RANGE
115 ublas::matrix_range<M> mr1 (m1, ublas::range (0, N), ublas::range (0, N)),
116 mr2 (m2, ublas::range (0, N), ublas::range (0, N)),
117 mr3 (m3, ublas::range (0, N), ublas::range (0, N));
118 test_with (mr1, mr2, mr3);
119 #endif
120
121 #ifdef USE_SLICE
122 ublas::matrix_slice<M> ms1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
123 ms2 (m2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
124 ms3 (m3, ublas::slice (0, 1, N), ublas::slice (0, 1, N));
125 test_with (ms1, ms2, ms3);
126 #endif
127 }
128
129 #ifdef USE_ADAPTOR
130 {
131 #ifdef USE_BANDED
132 M m1 (N, N, 1, 1), m2 (N, N, 1, 1), m3 (N, N, 1, 1);
133 ublas::banded_adaptor<M> bam1 (m1, 1, 1), bam2 (m2, 1, 1), bam3 (m3, 1, 1);
134 test_with (bam1, bam2, bam3);
135
136 #ifdef USE_RANGE
137 ublas::matrix_range<ublas::banded_adaptor<M> > mr1 (bam1, ublas::range (0, N), ublas::range (0, N)),
138 mr2 (bam2, ublas::range (0, N), ublas::range (0, N)),
139 mr3 (bam3, ublas::range (0, N), ublas::range (0, N));
140 test_with (mr1, mr2, mr3);
141 #endif
142
143 #ifdef USE_SLICE
144 ublas::matrix_slice<ublas::banded_adaptor<M> > ms1 (bam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
145 ms2 (bam2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
146 ms3 (bam3, ublas::slice (0, 1, N), ublas::slice (0, 1, N));
147 test_with (ms1, ms2, ms3);
148 #endif
149 #endif
150 #ifdef USE_DIAGONAL
151 M m1 (N, N), m2 (N, N), m3 (N, N);
152 ublas::diagonal_adaptor<M> dam1 (m1), dam2 (m2), dam3 (m3);
153 test_with (dam1, dam2, dam3);
154
155 #ifdef USE_RANGE
156 ublas::matrix_range<ublas::diagonal_adaptor<M> > mr1 (dam1, ublas::range (0, N), ublas::range (0, N)),
157 mr2 (dam2, ublas::range (0, N), ublas::range (0, N)),
158 mr3 (dam3, ublas::range (0, N), ublas::range (0, N));
159 test_with (mr1, mr2, mr3);
160 #endif
161
162 #ifdef USE_SLICE
163 ublas::matrix_slice<ublas::diagonal_adaptor<M> > ms1 (dam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
164 ms2 (dam2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
165 ms3 (dam3, ublas::slice (0, 1, N), ublas::slice (0, 1, N));
166 test_with (ms1, ms2, ms3);
167 #endif
168 #endif
169 }
170 #endif
171
172 }
173 };
174
175 // Test matrix
176 void test_matrix () {
177 std::cout << "test_matrix" << std::endl;
178
179 #ifdef USE_BANDED
180 #ifdef USE_BOUNDED_ARRAY
181 #ifdef USE_FLOAT
182 std::cout << "float, bounded_array" << std::endl;
183 test_my_matrix<ublas::banded_matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3 > () ();
184 #endif
185
186 #ifdef USE_DOUBLE
187 std::cout << "double, bounded_array" << std::endl;
188 test_my_matrix<ublas::banded_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () ();
189 #endif
190
191 #ifdef USE_STD_COMPLEX
192 #ifdef USE_FLOAT
193 std::cout << "std::complex<float>, bounded_array" << std::endl;
194 test_my_matrix<ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3 > () ();
195 #endif
196
197 #ifdef USE_DOUBLE
198 std::cout << "std::complex<double>, bounded_array" << std::endl;
199 test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () ();
200 #endif
201 #endif
202 #endif
203
204 #ifdef USE_UNBOUNDED_ARRAY
205 #ifdef USE_FLOAT
206 std::cout << "float, unbounded_array" << std::endl;
207 test_my_matrix<ublas::banded_matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3 > () ();
208 #endif
209
210 #ifdef USE_DOUBLE
211 std::cout << "double, unbounded_array" << std::endl;
212 test_my_matrix<ublas::banded_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3 > () ();
213 #endif
214
215 #ifdef USE_STD_COMPLEX
216 #ifdef USE_FLOAT
217 std::cout << "std::complex<float>, unbounded_array" << std::endl;
218 test_my_matrix<ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3 > () ();
219 #endif
220
221 #ifdef USE_DOUBLE
222 std::cout << "std::complex<double>, unbounded_array" << std::endl;
223 test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () ();
224 #endif
225 #endif
226 #endif
227
228 #ifdef USE_STD_VECTOR
229 #ifdef USE_FLOAT
230 std::cout << "float, std::vector" << std::endl;
231 test_my_matrix<ublas::banded_matrix<float, ublas::row_major, std::vector<float> >, 3 > () ();
232 #endif
233
234 #ifdef USE_DOUBLE
235 std::cout << "double, std::vector" << std::endl;
236 test_my_matrix<ublas::banded_matrix<double, ublas::row_major, std::vector<double> >, 3 > () ();
237 #endif
238
239 #ifdef USE_STD_COMPLEX
240 #ifdef USE_FLOAT
241 std::cout << "std::complex<float>, std::vector" << std::endl;
242 test_my_matrix<ublas::banded_matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3 > () ();
243 #endif
244
245 #ifdef USE_DOUBLE
246 std::cout << "std::complex<double>, std::vector" << std::endl;
247 test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3 > () ();
248 #endif
249 #endif
250 #endif
251 #endif
252
253 #ifdef USE_DIAGONAL
254 #ifdef USE_BOUNDED_ARRAY
255 #ifdef USE_FLOAT
256 std::cout << "float, bounded_array" << std::endl;
257 test_my_matrix<ublas::diagonal_matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3 > () ();
258 #endif
259
260 #ifdef USE_DOUBLE
261 std::cout << "double, bounded_array" << std::endl;
262 test_my_matrix<ublas::diagonal_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () ();
263 #endif
264
265 #ifdef USE_STD_COMPLEX
266 #ifdef USE_FLOAT
267 std::cout << "std::complex<float>, bounded_array" << std::endl;
268 test_my_matrix<ublas::diagonal_matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3 > () ();
269 #endif
270
271 #ifdef USE_DOUBLE
272 std::cout << "std::complex<double>, bounded_array" << std::endl;
273 test_my_matrix<ublas::diagonal_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () ();
274 #endif
275 #endif
276 #endif
277
278 #ifdef USE_UNBOUNDED_ARRAY
279 #ifdef USE_FLOAT
280 std::cout << "float, unbounded_array" << std::endl;
281 test_my_matrix<ublas::diagonal_matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3 > () ();
282 #endif
283
284 #ifdef USE_DOUBLE
285 std::cout << "double, unbounded_array" << std::endl;
286 test_my_matrix<ublas::diagonal_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3 > () ();
287 #endif
288
289 #ifdef USE_STD_COMPLEX
290 #ifdef USE_FLOAT
291 std::cout << "std::complex<float>, unbounded_array" << std::endl;
292 test_my_matrix<ublas::diagonal_matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3 > () ();
293 #endif
294
295 #ifdef USE_DOUBLE
296 std::cout << "std::complex<double>, unbounded_array" << std::endl;
297 test_my_matrix<ublas::diagonal_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () ();
298 #endif
299 #endif
300 #endif
301
302 #ifdef USE_STD_VECTOR
303 #ifdef USE_FLOAT
304 std::cout << "float, std::vector" << std::endl;
305 test_my_matrix<ublas::diagonal_matrix<float, ublas::row_major, std::vector<float> >, 3 > () ();
306 #endif
307
308 #ifdef USE_DOUBLE
309 std::cout << "double, std::vector" << std::endl;
310 test_my_matrix<ublas::diagonal_matrix<double, ublas::row_major, std::vector<double> >, 3 > () ();
311 #endif
312
313 #ifdef USE_STD_COMPLEX
314 #ifdef USE_FLOAT
315 std::cout << "std::complex<float>, std::vector" << std::endl;
316 test_my_matrix<ublas::diagonal_matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3 > () ();
317 #endif
318
319 #ifdef USE_DOUBLE
320 std::cout << "std::complex<double>, std::vector" << std::endl;
321 test_my_matrix<ublas::diagonal_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3 > () ();
322 #endif
323 #endif
324 #endif
325 #endif
326 }