]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multiprecision/test/ublas_interop/test13.cpp
2 // Copyright (c) 2000-2002
3 // Joerg Walter, Mathias Koch
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)
9 // The authors gratefully acknowledge the support of
10 // GeNeSys mbH & Co. KG in producing this work.
13 #if defined(__GNUC__) && (__GNUC__ >= 9)
14 #pragma GCC diagnostic ignored "-Wdeprecated-copy"
19 // Test matrix expression templates
20 template <class M
, int N
>
23 typedef typename
M::value_type value_type
;
26 void test_container_with(VP
& v1
) const
28 // Container type tests in addition to expression types
30 v1
.insert_element(0, 0, 55);
31 v1
.erase_element(1, 1);
36 void test_expression_with(MP
& m1
, MP
& m2
, MP
& m3
) const
41 default_construct
<MP
>::test();
44 initialize_matrix(m1
);
45 initialize_matrix(m2
);
47 std::cout
<< "m1 = m2 = " << m1
<< std::endl
;
48 m1
.assign_temporary(m2
);
49 std::cout
<< "m1.assign_temporary (m2) = " << m1
<< std::endl
;
51 std::cout
<< "m1.swap (m2) = " << m1
<< " " << m2
<< std::endl
;
54 m1
= ublas::zero_matrix
<>(m1
.size1(), m1
.size2());
55 std::cout
<< "m1.zero_matrix = " << m1
<< std::endl
;
58 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
59 // Project range and slice
60 initialize_matrix(m1
);
61 initialize_matrix(m2
);
62 project(m1
, ublas::range(0, 1), ublas::range(0, 1)) = project(m2
, ublas::range(0, 1), ublas::range(0, 1));
63 project(m1
, ublas::range(0, 1), ublas::range(0, 1)) = project(m2
, ublas::slice(0, 1, 1), ublas::slice(0, 1, 1));
64 project(m1
, ublas::slice(2, -1, 2), ublas::slice(2, -1, 2)) = project(m2
, ublas::slice(0, 1, 2), ublas::slice(0, 1, 2));
65 project(m1
, ublas::slice(2, -1, 2), ublas::slice(2, -1, 2)) = project(m2
, ublas::range(0, 2), ublas::range(0, 2));
66 std::cout
<< "m1 = range/slice " << m1
<< std::endl
;
69 // Unary matrix operations resulting in a matrix
70 initialize_matrix(m1
);
72 std::cout
<< "- m1 = " << m2
<< std::endl
;
74 std::cout
<< "conj (m1) = " << m2
<< std::endl
;
76 // Binary matrix operations resulting in a matrix
77 initialize_matrix(m1
);
78 initialize_matrix(m2
);
80 std::cout
<< "m1 + m2 = " << m3
<< std::endl
;
82 std::cout
<< "m1 - m2 = " << m3
<< std::endl
;
83 m3
= ublas::element_prod(m1
, m2
);
84 std::cout
<< "element_prod (m1, m2) = " << m3
<< std::endl
;
88 initialize_matrix(m1
);
89 m2
= value_type(1.) * m1
;
90 std::cout
<< "1. * m1 = " << m2
<< std::endl
;
92 std::cout
<< "N * m1 = " << m2
<< std::endl
;
93 initialize_matrix(m1
);
94 m2
= m1
* value_type(1.);
95 std::cout
<< "m1 * 1. = " << m2
<< std::endl
;
97 std::cout
<< "m1 * N = " << m2
<< std::endl
;
100 initialize_matrix(m1
);
101 initialize_matrix(m2
);
103 std::cout
<< "m2 += m1 = " << m2
<< std::endl
;
105 std::cout
<< "m2 -= m1 = " << m2
<< std::endl
;
107 std::cout
<< "m2 = m2 + m1 = " << m2
<< std::endl
;
109 std::cout
<< "m2 = m2 - m1 = " << m2
<< std::endl
;
110 m1
*= value_type(1.);
111 std::cout
<< "m1 *= 1. = " << m1
<< std::endl
;
113 std::cout
<< "m1 *= N = " << m1
<< std::endl
;
116 initialize_matrix(m1
);
117 m2
= ublas::trans(m1
);
118 std::cout
<< "trans (m1) = " << m2
<< std::endl
;
121 initialize_matrix(m1
);
122 m2
= ublas::herm(m1
);
123 std::cout
<< "herm (m1) = " << m2
<< std::endl
;
125 // Matrix multiplication
126 initialize_matrix(m1
);
127 initialize_matrix(m2
);
128 m3
= ublas::prod(m1
, m2
);
129 std::cout
<< "prod (m1, m2) = " << m3
<< std::endl
;
132 void operator()() const
134 M
m1(N
, N
), m2(N
, N
), m3(N
, N
);
135 test_expression_with(m1
, m2
, m3
);
136 test_container_with(m1
);
139 ublas::matrix_range
<M
> mr1(m1
, ublas::range(0, N
), ublas::range(0, N
)),
140 mr2(m2
, ublas::range(0, N
), ublas::range(0, N
)),
141 mr3(m3
, ublas::range(0, N
), ublas::range(0, N
));
142 test_expression_with(mr1
, mr2
, mr3
);
146 ublas::matrix_slice
<M
> ms1(m1
, ublas::slice(0, 1, N
), ublas::slice(0, 1, N
)),
147 ms2(m2
, ublas::slice(0, 1, N
), ublas::slice(0, 1, N
)),
148 ms3(m3
, ublas::slice(0, 1, N
), ublas::slice(0, 1, N
));
149 test_expression_with(ms1
, ms2
, ms3
);
157 std::cout
<< "test_matrix" << std::endl
;
160 #ifdef USE_BOUNDED_ARRAY
162 std::cout
<< "mp_test_type, bounded_array" << std::endl
;
163 test_my_matrix
<ublas::matrix
<mp_test_type
, ublas::row_major
, ublas::bounded_array
<mp_test_type
, 3 * 3> >, 3>()();
167 std::cout
<< "double, bounded_array" << std::endl
;
168 test_my_matrix
<ublas::matrix
<double, ublas::row_major
, ublas::bounded_array
<double, 3 * 3> >, 3>()();
171 #ifdef USE_STD_COMPLEX
173 std::cout
<< "std::complex<mp_test_type>, bounded_array" << std::endl
;
174 test_my_matrix
<ublas::matrix
<std::complex<mp_test_type
>, ublas::row_major
, ublas::bounded_array
<std::complex<mp_test_type
>, 3 * 3> >, 3>()();
178 std::cout
<< "std::complex<double>, bounded_array" << std::endl
;
179 test_my_matrix
<ublas::matrix
<std::complex<double>, ublas::row_major
, ublas::bounded_array
<std::complex<double>, 3 * 3> >, 3>()();
184 #ifdef USE_UNBOUNDED_ARRAY
186 std::cout
<< "mp_test_type, unbounded_array" << std::endl
;
187 test_my_matrix
<ublas::matrix
<mp_test_type
, ublas::row_major
, ublas::unbounded_array
<mp_test_type
> >, 3>()();
191 std::cout
<< "double, unbounded_array" << std::endl
;
192 test_my_matrix
<ublas::matrix
<double, ublas::row_major
, ublas::unbounded_array
<double> >, 3>()();
195 #ifdef USE_STD_COMPLEX
197 std::cout
<< "std::complex<mp_test_type>, unbounded_array" << std::endl
;
198 test_my_matrix
<ublas::matrix
<std::complex<mp_test_type
>, ublas::row_major
, ublas::unbounded_array
<std::complex<mp_test_type
> > >, 3>()();
202 std::cout
<< "std::complex<double>, unbounded_array" << std::endl
;
203 test_my_matrix
<ublas::matrix
<std::complex<double>, ublas::row_major
, ublas::unbounded_array
<std::complex<double> > >, 3>()();
208 #ifdef USE_STD_VECTOR
210 std::cout
<< "mp_test_type, std::vector" << std::endl
;
211 test_my_matrix
<ublas::matrix
<mp_test_type
, ublas::row_major
, std::vector
<mp_test_type
> >, 3>()();
215 std::cout
<< "double, std::vector" << std::endl
;
216 test_my_matrix
<ublas::matrix
<double, ublas::row_major
, std::vector
<double> >, 3>()();
219 #ifdef USE_STD_COMPLEX
221 std::cout
<< "std::complex<mp_test_type>, std::vector" << std::endl
;
222 test_my_matrix
<ublas::matrix
<std::complex<mp_test_type
>, ublas::row_major
, std::vector
<std::complex<mp_test_type
> > >, 3>()();
226 std::cout
<< "std::complex<double>, std::vector" << std::endl
;
227 test_my_matrix
<ublas::matrix
<std::complex<double>, ublas::row_major
, std::vector
<std::complex<double> > >, 3>()();
233 #ifdef USE_BOUNDED_MATRIX
235 std::cout
<< "mp_test_type, bounded" << std::endl
;
236 test_my_matrix
<ublas::bounded_matrix
<mp_test_type
, 3, 3>, 3>()();
240 std::cout
<< "double, bounded" << std::endl
;
241 test_my_matrix
<ublas::bounded_matrix
<double, 3, 3>, 3>()();
244 #ifdef USE_STD_COMPLEX
246 std::cout
<< "std::complex<mp_test_type>, bounded" << std::endl
;
247 test_my_matrix
<ublas::bounded_matrix
<std::complex<mp_test_type
>, 3, 3>, 3>()();
251 std::cout
<< "std::complex<double>, bounded" << std::endl
;
252 test_my_matrix
<ublas::bounded_matrix
<std::complex<double>, 3, 3>, 3>()();
257 #ifdef USE_VECTOR_OF_VECTOR
258 #ifdef USE_BOUNDED_ARRAY
260 std::cout
<< "mp_test_type, bounded_array" << std::endl
;
261 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>()();
265 std::cout
<< "double, bounded_array" << std::endl
;
266 test_my_matrix
<ublas::vector_of_vector
<double, ublas::row_major
, ublas::bounded_array
<ublas::bounded_array
<double, 3>, 3 + 1> >, 3>()();
269 #ifdef USE_STD_COMPLEX
271 std::cout
<< "std::complex<mp_test_type>, bounded_array" << std::endl
;
272 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>()();
276 std::cout
<< "std::complex<double>, bounded_array" << std::endl
;
277 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>()();
282 #ifdef USE_UNBOUNDED_ARRAY
284 std::cout
<< "mp_test_type, unbounded_array" << std::endl
;
285 test_my_matrix
<ublas::vector_of_vector
<mp_test_type
, ublas::row_major
, ublas::unbounded_array
<ublas::unbounded_array
<mp_test_type
> > >, 3>()();
289 std::cout
<< "double, unbounded_array" << std::endl
;
290 test_my_matrix
<ublas::vector_of_vector
<double, ublas::row_major
, ublas::unbounded_array
<ublas::unbounded_array
<double> > >, 3>()();
293 #ifdef USE_STD_COMPLEX
295 std::cout
<< "std::complex<mp_test_type>, unbounded_array" << std::endl
;
296 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>()();
300 std::cout
<< "std::complex<double>, unbounded_array" << std::endl
;
301 test_my_matrix
<ublas::vector_of_vector
<std::complex<double>, ublas::row_major
, ublas::unbounded_array
<ublas::unbounded_array
<std::complex<double> > > >, 3>()();
306 #ifdef USE_STD_VECTOR
308 std::cout
<< "mp_test_type, std::vector" << std::endl
;
309 test_my_matrix
<ublas::vector_of_vector
<mp_test_type
, ublas::row_major
, std::vector
<std::vector
<mp_test_type
> > >, 3>()();
313 std::cout
<< "double, std::vector" << std::endl
;
314 test_my_matrix
<ublas::vector_of_vector
<double, ublas::row_major
, std::vector
<std::vector
<double> > >, 3>()();
317 #ifdef USE_STD_COMPLEX
319 std::cout
<< "std::complex<mp_test_type>, std::vector" << std::endl
;
320 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>()();
324 std::cout
<< "std::complex<double>, std::vector" << std::endl
;
325 test_my_matrix
<ublas::vector_of_vector
<std::complex<double>, ublas::row_major
, std::vector
<std::vector
<std::complex<double> > > >, 3>()();