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