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