]>
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.
15 // Test matrix expression templates
16 template<class M
, int N
>
17 struct test_my_matrix
{
18 typedef typename
M::value_type value_type
;
21 void test_container_with (VP
&v1
) const {
22 // Container type tests in addition to expression types
24 v1
.insert_element (0,0, 55);
25 v1
.erase_element (1,1);
30 void test_expression_with (MP
&m1
, MP
&m2
, MP
&m3
) const {
34 default_construct
<MP
>::test ();
37 initialize_matrix (m1
);
38 initialize_matrix (m2
);
40 std::cout
<< "m1 = m2 = " << m1
<< std::endl
;
41 m1
.assign_temporary (m2
);
42 std::cout
<< "m1.assign_temporary (m2) = " << m1
<< std::endl
;
44 std::cout
<< "m1.swap (m2) = " << m1
<< " " << m2
<< std::endl
;
47 m1
= ublas::zero_matrix
<> (m1
.size1 (), m1
.size2 ());
48 std::cout
<< "m1.zero_matrix = " << m1
<< std::endl
;
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
;
62 // Unary matrix operations resulting in a matrix
63 initialize_matrix (m1
);
65 std::cout
<< "- m1 = " << m2
<< std::endl
;
66 m2
= ublas::conj (m1
);
67 std::cout
<< "conj (m1) = " << m2
<< std::endl
;
69 // Binary matrix operations resulting in a matrix
70 initialize_matrix (m1
);
71 initialize_matrix (m2
);
73 std::cout
<< "m1 + m2 = " << m3
<< std::endl
;
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
;
81 initialize_matrix (m1
);
82 m2
= value_type (1.) * m1
;
83 std::cout
<< "1. * m1 = " << m2
<< std::endl
;
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
;
90 std::cout
<< "m1 * N = " << m2
<< std::endl
;
93 initialize_matrix (m1
);
94 initialize_matrix (m2
);
96 std::cout
<< "m2 += m1 = " << m2
<< std::endl
;
98 std::cout
<< "m2 -= m1 = " << m2
<< std::endl
;
100 std::cout
<< "m2 = m2 + m1 = " << m2
<< std::endl
;
102 std::cout
<< "m2 = m2 - m1 = " << m2
<< std::endl
;
103 m1
*= value_type (1.);
104 std::cout
<< "m1 *= 1. = " << m1
<< std::endl
;
106 std::cout
<< "m1 *= N = " << m1
<< std::endl
;
109 initialize_matrix (m1
);
110 m2
= ublas::trans (m1
);
111 std::cout
<< "trans (m1) = " << m2
<< std::endl
;
114 initialize_matrix (m1
);
115 m2
= ublas::herm (m1
);
116 std::cout
<< "herm (m1) = " << m2
<< std::endl
;
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
;
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
);
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
);
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
);
147 void test_matrix () {
148 std::cout
<< "test_matrix" << std::endl
;
151 #ifdef USE_BOUNDED_ARRAY
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> () ();
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> () ();
162 #ifdef USE_STD_COMPLEX
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> () ();
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> () ();
175 #ifdef USE_UNBOUNDED_ARRAY
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> () ();
182 std::cout
<< "double, unbounded_array" << std::endl
;
183 test_my_matrix
<ublas::matrix
<double, ublas::row_major
, ublas::unbounded_array
<double> >, 3> () ();
186 #ifdef USE_STD_COMPLEX
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> () ();
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> () ();
199 #ifdef USE_STD_VECTOR
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> () ();
206 std::cout
<< "double, std::vector" << std::endl
;
207 test_my_matrix
<ublas::matrix
<double, ublas::row_major
, std::vector
<double> >, 3> () ();
210 #ifdef USE_STD_COMPLEX
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> () ();
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> () ();
224 #ifdef USE_BOUNDED_MATRIX
226 std::cout
<< "mp_test_type, bounded" << std::endl
;
227 test_my_matrix
<ublas::bounded_matrix
<mp_test_type
, 3, 3>, 3> () ();
231 std::cout
<< "double, bounded" << std::endl
;
232 test_my_matrix
<ublas::bounded_matrix
<double, 3, 3>, 3> () ();
235 #ifdef USE_STD_COMPLEX
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> () ();
242 std::cout
<< "std::complex<double>, bounded" << std::endl
;
243 test_my_matrix
<ublas::bounded_matrix
<std::complex<double>, 3, 3>, 3> () ();
248 #ifdef USE_VECTOR_OF_VECTOR
249 #ifdef USE_BOUNDED_ARRAY
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> () ();
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> () ();
260 #ifdef USE_STD_COMPLEX
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> () ();
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> () ();
273 #ifdef USE_UNBOUNDED_ARRAY
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> () ();
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> () ();
284 #ifdef USE_STD_COMPLEX
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> () ();
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> () ();
297 #ifdef USE_STD_VECTOR
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> () ();
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> () ();
308 #ifdef USE_STD_COMPLEX
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> () ();
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> () ();