]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multiprecision/test/ublas_interop/test43.cpp
49d9fed39a772e3fdd0f795ed84a3442be90a074
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_with(MP
& m1
, MP
& m2
, MP
& m3
) const
32 default_construct
<MP
>::test();
35 initialize_matrix(m1
);
36 initialize_matrix(m2
);
38 std::cout
<< "m1 = m2 = " << m1
<< std::endl
;
39 m1
.assign_temporary(m2
);
40 std::cout
<< "m1.assign_temporary (m2) = " << m1
<< std::endl
;
42 std::cout
<< "m1.swap (m2) = " << m1
<< " " << m2
<< std::endl
;
45 m1
= ublas::zero_matrix
<>(m1
.size1(), m1
.size2());
46 std::cout
<< "m1.zero_matrix = " << m1
<< std::endl
;
49 // Unary matrix operations resulting in a matrix
50 initialize_matrix(m1
);
52 std::cout
<< "- m1 = " << m2
<< std::endl
;
54 std::cout
<< "conj (m1) = " << m2
<< std::endl
;
56 // Binary matrix operations resulting in a matrix
57 initialize_matrix(m1
);
58 initialize_matrix(m2
);
60 std::cout
<< "m1 + m2 = " << m3
<< std::endl
;
62 std::cout
<< "m1 - m2 = " << m3
<< std::endl
;
66 initialize_matrix(m1
);
67 m2
= value_type(1.) * m1
;
68 std::cout
<< "1. * m1 = " << m2
<< std::endl
;
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
;
75 std::cout
<< "m1 * N = " << m2
<< std::endl
;
78 initialize_matrix(m1
);
79 initialize_matrix(m2
);
81 std::cout
<< "m2 += m1 = " << m2
<< std::endl
;
83 std::cout
<< "m2 -= m1 = " << m2
<< std::endl
;
85 std::cout
<< "m2 = m2 + m1 = " << m2
<< std::endl
;
87 std::cout
<< "m2 = m2 - m1 = " << m2
<< std::endl
;
89 std::cout
<< "m1 *= 1. = " << m1
<< std::endl
;
91 std::cout
<< "m1 *= N = " << m1
<< std::endl
;
94 initialize_matrix(m1
);
95 m2
= ublas::trans(m1
);
96 std::cout
<< "trans (m1) = " << m2
<< std::endl
;
99 initialize_matrix(m1
);
100 m2
= ublas::herm(m1
);
101 std::cout
<< "herm (m1) = " << m2
<< std::endl
;
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
;
110 void operator()() const
114 M
m1(N
, N
, 1, 1), m2(N
, N
, 1, 1), m3(N
, N
, 1, 1);
117 M
m1(N
, N
), m2(N
, N
), m3(N
, N
);
119 test_with(m1
, m2
, m3
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
184 std::cout
<< "test_matrix" << std::endl
;
187 #ifdef USE_BOUNDED_ARRAY
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>()();
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>()();
198 #ifdef USE_STD_COMPLEX
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>()();
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>()();
211 #ifdef USE_UNBOUNDED_ARRAY
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>()();
218 std::cout
<< "double, unbounded_array" << std::endl
;
219 test_my_matrix
<ublas::banded_matrix
<double, ublas::row_major
, ublas::unbounded_array
<double> >, 3>()();
222 #ifdef USE_STD_COMPLEX
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>()();
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>()();
235 #ifdef USE_STD_VECTOR
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>()();
242 std::cout
<< "double, std::vector" << std::endl
;
243 test_my_matrix
<ublas::banded_matrix
<double, ublas::row_major
, std::vector
<double> >, 3>()();
246 #ifdef USE_STD_COMPLEX
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>()();
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>()();
261 #ifdef USE_BOUNDED_ARRAY
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>()();
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>()();
272 #ifdef USE_STD_COMPLEX
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>()();
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>()();
285 #ifdef USE_UNBOUNDED_ARRAY
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>()();
292 std::cout
<< "double, unbounded_array" << std::endl
;
293 test_my_matrix
<ublas::diagonal_matrix
<double, ublas::row_major
, ublas::unbounded_array
<double> >, 3>()();
296 #ifdef USE_STD_COMPLEX
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>()();
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>()();
309 #ifdef USE_STD_VECTOR
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>()();
316 std::cout
<< "double, std::vector" << std::endl
;
317 test_my_matrix
<ublas::diagonal_matrix
<double, ublas::row_major
, std::vector
<double> >, 3>()();
320 #ifdef USE_STD_COMPLEX
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>()();
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>()();