]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/multiprecision/test/ublas_interop/test33.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / multiprecision / test / ublas_interop / test33.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 "test3.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;
7c673cae
FG
48
49#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
92f5a8d4
TL
50 // Project range and slice
51 initialize_matrix(m1);
52 initialize_matrix(m2);
53 project(m1, ublas::range(0, 1), ublas::range(0, 1)) = project(m2, ublas::range(0, 1), ublas::range(0, 1));
54 project(m1, ublas::range(0, 1), ublas::range(0, 1)) = project(m2, ublas::slice(0, 1, 1), ublas::slice(0, 1, 1));
55 project(m1, ublas::slice(2, -1, 2), ublas::slice(2, -1, 2)) = project(m2, ublas::slice(0, 1, 2), ublas::slice(0, 1, 2));
56 project(m1, ublas::slice(2, -1, 2), ublas::slice(2, -1, 2)) = project(m2, ublas::range(0, 2), ublas::range(0, 2));
57 std::cout << "m1 = range/slice " << m1 << std::endl;
58#endif
59
60 // Unary matrix operations resulting in a matrix
61 initialize_matrix(m1);
62 m2 = -m1;
63 std::cout << "- m1 = " << m2 << std::endl;
64 m2 = ublas::conj(m1);
65 std::cout << "conj (m1) = " << m2 << std::endl;
66
67 // Binary matrix operations resulting in a matrix
68 initialize_matrix(m1);
69 initialize_matrix(m2);
70 initialize_matrix(m3);
71 m3 = m1 + m2;
72 std::cout << "m1 + m2 = " << m3 << std::endl;
73 m3 = m1 - m2;
74 std::cout << "m1 - m2 = " << m3 << std::endl;
75
76 // Scaling a matrix
77 t = N;
78 initialize_matrix(m1);
79 m2 = value_type(1.) * m1;
80 std::cout << "1. * m1 = " << m2 << std::endl;
81 m2 = t * m1;
82 std::cout << "N * m1 = " << m2 << std::endl;
83 initialize_matrix(m1);
84 m2 = m1 * value_type(1.);
85 std::cout << "m1 * 1. = " << m2 << std::endl;
86 m2 = m1 * t;
87 std::cout << "m1 * N = " << m2 << std::endl;
88
89 // Some assignments
90 initialize_matrix(m1);
91 initialize_matrix(m2);
92 m2 += m1;
93 std::cout << "m2 += m1 = " << m2 << std::endl;
94 m2 -= m1;
95 std::cout << "m2 -= m1 = " << m2 << std::endl;
96 m2 = m2 + m1;
97 std::cout << "m2 = m2 + m1 = " << m2 << std::endl;
98 m2 = m2 - m1;
99 std::cout << "m2 = m2 - m1 = " << m2 << std::endl;
100 m1 *= value_type(1.);
101 std::cout << "m1 *= 1. = " << m1 << std::endl;
102 m1 *= t;
103 std::cout << "m1 *= N = " << m1 << std::endl;
104
105 // Transpose
106 initialize_matrix(m1);
107 m2 = ublas::trans(m1);
108 std::cout << "trans (m1) = " << m2 << std::endl;
109
110 // Hermitean
111 initialize_matrix(m1);
112 m2 = ublas::herm(m1);
113 std::cout << "herm (m1) = " << m2 << std::endl;
114
115 // Matrix multiplication
116 initialize_matrix(m1);
117 initialize_matrix(m2);
118 m3 = ublas::prod(m1, m2);
119 std::cout << "prod (m1, m2) = " << m3 << std::endl;
120 }
121 }
122 void operator()() const
123 {
124 {
125 M m1(N, N, N * N), m2(N, N, N * N), m3(N, N, N * N);
126 test_with(m1, m2, m3);
7c673cae
FG
127
128#ifdef USE_RANGE
92f5a8d4
TL
129 ublas::matrix_range<M> mr1(m1, ublas::range(0, N), ublas::range(0, N)),
130 mr2(m2, ublas::range(0, N), ublas::range(0, N)),
131 mr3(m3, ublas::range(0, N), ublas::range(0, N));
132 test_with(mr1, mr2, mr3);
7c673cae
FG
133#endif
134
135#ifdef USE_SLICE
92f5a8d4
TL
136 ublas::matrix_slice<M> ms1(m1, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
137 ms2(m2, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
138 ms3(m3, ublas::slice(0, 1, N), ublas::slice(0, 1, N));
139 test_with(ms1, ms2, ms3);
7c673cae 140#endif
92f5a8d4
TL
141 }
142 }
7c673cae
FG
143};
144
145// Test matrix
92f5a8d4
TL
146void test_matrix()
147{
148 std::cout << "test_matrix" << std::endl;
7c673cae
FG
149
150#ifdef USE_SPARSE_MATRIX
151#ifdef USE_MAP_ARRAY
152#ifdef USE_FLOAT
92f5a8d4
TL
153 std::cout << "mp_test_type, mapped_matrix map_array" << std::endl;
154 test_my_matrix<ublas::mapped_matrix<mp_test_type, ublas::row_major, ublas::map_array<std::size_t, mp_test_type> >, 3>()();
7c673cae
FG
155#endif
156
157#ifdef USE_DOUBLE
92f5a8d4
TL
158 std::cout << "double, mapped_matrix map_array" << std::endl;
159 test_my_matrix<ublas::mapped_matrix<double, ublas::row_major, ublas::map_array<std::size_t, double> >, 3>()();
7c673cae
FG
160#endif
161
162#ifdef USE_STD_COMPLEX
163#ifdef USE_FLOAT
92f5a8d4
TL
164 std::cout << "std::complex<mp_test_type>, mapped_matrix map_array" << std::endl;
165 test_my_matrix<ublas::mapped_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::map_array<std::size_t, std::complex<mp_test_type> > >, 3>()();
7c673cae
FG
166#endif
167
168#ifdef USE_DOUBLE
92f5a8d4
TL
169 std::cout << "std::complex<double>, mapped_matrix map_array" << std::endl;
170 test_my_matrix<ublas::mapped_matrix<std::complex<double>, ublas::row_major, ublas::map_array<std::size_t, std::complex<double> > >, 3>()();
7c673cae
FG
171#endif
172#endif
173#endif
174
175#ifdef USE_STD_MAP
176#ifdef USE_FLOAT
92f5a8d4
TL
177 std::cout << "mp_test_type, mapped_matrix std::map" << std::endl;
178 test_my_matrix<ublas::mapped_matrix<mp_test_type, ublas::row_major, std::map<std::size_t, mp_test_type> >, 3>()();
7c673cae
FG
179#endif
180
181#ifdef USE_DOUBLE
92f5a8d4
TL
182 std::cout << "double, mapped_matrix std::map" << std::endl;
183 test_my_matrix<ublas::mapped_matrix<double, ublas::row_major, std::map<std::size_t, double> >, 3>()();
7c673cae
FG
184#endif
185
186#ifdef USE_STD_COMPLEX
187#ifdef USE_FLOAT
92f5a8d4
TL
188 std::cout << "std::complex<mp_test_type>, mapped_matrix std::map" << std::endl;
189 test_my_matrix<ublas::mapped_matrix<std::complex<mp_test_type>, ublas::row_major, std::map<std::size_t, std::complex<mp_test_type> > >, 3>()();
7c673cae
FG
190#endif
191
192#ifdef USE_DOUBLE
92f5a8d4
TL
193 std::cout << "std::complex<double>, mapped_matrix std::map" << std::endl;
194 test_my_matrix<ublas::mapped_matrix<std::complex<double>, ublas::row_major, std::map<std::size_t, std::complex<double> > >, 3>()();
7c673cae
FG
195#endif
196#endif
197#endif
198#endif
199
200#ifdef USE_SPARSE_VECTOR_OF_SPARSE_VECTOR
201#ifdef USE_MAP_ARRAY
202#ifdef USE_FLOAT
92f5a8d4
TL
203 std::cout << "mp_test_type, mapped_vector_of_mapped_vector map_array" << std::endl;
204 test_my_matrix<ublas::mapped_vector_of_mapped_vector<mp_test_type, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, mp_test_type> > >, 3>()();
7c673cae
FG
205#endif
206
207#ifdef USE_DOUBLE
92f5a8d4
TL
208 std::cout << "double, mapped_vector_of_mapped_vector map_array" << std::endl;
209 test_my_matrix<ublas::mapped_vector_of_mapped_vector<double, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, double> > >, 3>()();
7c673cae
FG
210#endif
211
212#ifdef USE_STD_COMPLEX
213#ifdef USE_FLOAT
92f5a8d4
TL
214 std::cout << "std::complex<mp_test_type>, mapped_vector_of_mapped_vector map_array" << std::endl;
215 test_my_matrix<ublas::mapped_vector_of_mapped_vector<std::complex<mp_test_type>, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, std::complex<mp_test_type> > > >, 3>()();
7c673cae
FG
216#endif
217
218#ifdef USE_DOUBLE
92f5a8d4
TL
219 std::cout << "std::complex<double>, mapped_vector_of_mapped_vectormap_array" << std::endl;
220 test_my_matrix<ublas::mapped_vector_of_mapped_vector<std::complex<double>, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, std::complex<double> > > >, 3>()();
7c673cae
FG
221#endif
222#endif
223#endif
224
225#ifdef USE_STD_MAP
226#ifdef USE_FLOAT
92f5a8d4
TL
227 std::cout << "mp_test_type, mapped_vector_of_mapped_vector std::map" << std::endl;
228 test_my_matrix<ublas::mapped_vector_of_mapped_vector<mp_test_type, ublas::row_major, std::map<std::size_t, std::map<std::size_t, mp_test_type> > >, 3>()();
7c673cae
FG
229#endif
230
231#ifdef USE_DOUBLE
92f5a8d4
TL
232 std::cout << "double, mapped_vector_of_mapped_vector std::map" << std::endl;
233 test_my_matrix<ublas::mapped_vector_of_mapped_vector<double, ublas::row_major, std::map<std::size_t, std::map<std::size_t, double> > >, 3>()();
7c673cae
FG
234#endif
235
236#ifdef USE_STD_COMPLEX
237#ifdef USE_FLOAT
92f5a8d4
TL
238 std::cout << "std::complex<mp_test_type>, mapped_vector_of_mapped_vector std::map" << std::endl;
239 test_my_matrix<ublas::mapped_vector_of_mapped_vector<std::complex<mp_test_type>, ublas::row_major, std::map<std::size_t, std::map<std::size_t, std::complex<mp_test_type> > > >, 3>()();
7c673cae
FG
240#endif
241
242#ifdef USE_DOUBLE
92f5a8d4
TL
243 std::cout << "std::complex<double>, mapped_vector_of_mapped_vector std::map" << std::endl;
244 test_my_matrix<ublas::mapped_vector_of_mapped_vector<std::complex<double>, ublas::row_major, std::map<std::size_t, std::map<std::size_t, std::complex<double> > > >, 3>()();
7c673cae
FG
245#endif
246#endif
247#endif
248#endif
249
250#ifdef USE_GENERALIZED_VECTOR_OF_VECTOR
251#ifdef USE_MAP_ARRAY
252#ifdef USE_FLOAT
92f5a8d4
TL
253 std::cout << "mp_test_type,generalized_vector_of_vector map_array" << std::endl;
254 test_my_matrix<ublas::generalized_vector_of_vector<mp_test_type, ublas::row_major, ublas::vector<ublas::mapped_vector<mp_test_type, ublas::map_array<std::size_t, mp_test_type> > > >, 3>()();
255 test_my_matrix<ublas::generalized_vector_of_vector<mp_test_type, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<mp_test_type, ublas::map_array<std::size_t, mp_test_type> >, ublas::map_array<std::size_t, ublas::mapped_vector<mp_test_type, ublas::map_array<std::size_t, mp_test_type> > > > >, 3>()();
7c673cae
FG
256#endif
257
258#ifdef USE_DOUBLE
92f5a8d4
TL
259 std::cout << "double, generalized_vector_of_vector map_array" << std::endl;
260 test_my_matrix<ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> > > >, 3>()();
261 test_my_matrix<ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> >, ublas::map_array<std::size_t, ublas::mapped_vector<double, ublas::map_array<std::size_t, double> > > > >, 3>()();
7c673cae
FG
262#endif
263
264#ifdef USE_STD_COMPLEX
265#ifdef USE_FLOAT
92f5a8d4
TL
266 std::cout << "std::complex<mp_test_type>, generalized_vector_of_vector map_array" << std::endl;
267 test_my_matrix<ublas::generalized_vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<mp_test_type>, ublas::map_array<std::size_t, std::complex<mp_test_type> > > > >, 3>()();
268 test_my_matrix<ublas::generalized_vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<mp_test_type>, ublas::map_array<std::size_t, std::complex<mp_test_type> > >, ublas::map_array<std::size_t, ublas::mapped_vector<std::complex<mp_test_type>, ublas::map_array<std::size_t, std::complex<mp_test_type> > > > > >, 3>()();
7c673cae
FG
269#endif
270
271#ifdef USE_DOUBLE
92f5a8d4
TL
272 std::cout << "std::complex<double>, generalized_vector_of_vector map_array" << std::endl;
273 test_my_matrix<ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > > > >, 3>()();
274 test_my_matrix<ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >, ublas::map_array<std::size_t, ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > > > > >, 3>()();
7c673cae
FG
275#endif
276#endif
277#endif
278
279#ifdef USE_STD_MAP
280#ifdef USE_FLOAT
92f5a8d4
TL
281 std::cout << "mp_test_type, generalized_vector_of_vector std::map" << std::endl;
282 test_my_matrix<ublas::generalized_vector_of_vector<mp_test_type, ublas::row_major, ublas::vector<ublas::mapped_vector<mp_test_type, std::map<std::size_t, mp_test_type> > > >, 3>()();
283 test_my_matrix<ublas::generalized_vector_of_vector<mp_test_type, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<mp_test_type, std::map<std::size_t, mp_test_type> >, std::map<std::size_t, ublas::mapped_vector<mp_test_type, std::map<std::size_t, mp_test_type> > > > >, 3>()();
7c673cae
FG
284#endif
285
286#ifdef USE_DOUBLE
92f5a8d4
TL
287 std::cout << "double, generalized_vector_of_vector std::map" << std::endl;
288 test_my_matrix<ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::vector<ublas::mapped_vector<double, std::map<std::size_t, double> > > >, 3>()();
289 test_my_matrix<ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<double, std::map<std::size_t, double> >, std::map<std::size_t, ublas::mapped_vector<double, std::map<std::size_t, double> > > > >, 3>()();
7c673cae
FG
290#endif
291
292#ifdef USE_STD_COMPLEX
293#ifdef USE_FLOAT
92f5a8d4
TL
294 std::cout << "std::complex<mp_test_type>, generalized_vector_of_vector std::map" << std::endl;
295 test_my_matrix<ublas::generalized_vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<mp_test_type>, std::map<std::size_t, std::complex<mp_test_type> > > > >, 3>()();
296 test_my_matrix<ublas::generalized_vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<mp_test_type>, std::map<std::size_t, std::complex<mp_test_type> > >, std::map<std::size_t, ublas::mapped_vector<std::complex<mp_test_type>, std::map<std::size_t, std::complex<mp_test_type> > > > > >, 3>()();
7c673cae
FG
297#endif
298
299#ifdef USE_DOUBLE
92f5a8d4
TL
300 std::cout << "std::complex<double>, generalized_vector_of_vector std::map" << std::endl;
301 test_my_matrix<ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > > > >, 3>()();
302 test_my_matrix<ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > >, std::map<std::size_t, ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > > > > >, 3>()();
7c673cae
FG
303#endif
304#endif
305#endif
306#endif
307
308#ifdef USE_COMPRESSED_MATRIX
309#ifdef USE_FLOAT
92f5a8d4
TL
310 std::cout << "mp_test_type compressed_matrix" << std::endl;
311 test_my_matrix<ublas::compressed_matrix<mp_test_type>, 3>()();
7c673cae
FG
312#endif
313
314#ifdef USE_DOUBLE
92f5a8d4
TL
315 std::cout << "double compressed_matrix" << std::endl;
316 test_my_matrix<ublas::compressed_matrix<double>, 3>()();
7c673cae
FG
317#endif
318
319#ifdef USE_STD_COMPLEX
320#ifdef USE_FLOAT
92f5a8d4
TL
321 std::cout << "std::complex<mp_test_type> compressed_matrix" << std::endl;
322 test_my_matrix<ublas::compressed_matrix<std::complex<mp_test_type> >, 3>()();
7c673cae
FG
323#endif
324
325#ifdef USE_DOUBLE
92f5a8d4
TL
326 std::cout << "std::complex<double> compressed_matrix" << std::endl;
327 test_my_matrix<ublas::compressed_matrix<std::complex<double> >, 3>()();
7c673cae
FG
328#endif
329#endif
330#endif
331
332#ifdef USE_COORDINATE_MATRIX
333#ifdef USE_FLOAT
92f5a8d4
TL
334 std::cout << "mp_test_type coordinate_matrix" << std::endl;
335 test_my_matrix<ublas::coordinate_matrix<mp_test_type>, 3>()();
7c673cae
FG
336#endif
337
338#ifdef USE_DOUBLE
92f5a8d4
TL
339 std::cout << "double coordinate_matrix" << std::endl;
340 test_my_matrix<ublas::coordinate_matrix<double>, 3>()();
7c673cae
FG
341#endif
342
343#ifdef USE_STD_COMPLEX
344#ifdef USE_FLOAT
92f5a8d4
TL
345 std::cout << "std::complex<mp_test_type> coordinate_matrix" << std::endl;
346 test_my_matrix<ublas::coordinate_matrix<std::complex<mp_test_type> >, 3>()();
7c673cae
FG
347#endif
348
349#ifdef USE_DOUBLE
92f5a8d4
TL
350 std::cout << "std::complex<double> coordinate_matrix" << std::endl;
351 test_my_matrix<ublas::coordinate_matrix<std::complex<double> >, 3>()();
7c673cae
FG
352#endif
353#endif
354#endif
355}