]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/multiprecision/test/ublas_interop/test73.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / multiprecision / test / ublas_interop / test73.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 "test7.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 // Copy and swap
32 initialize_matrix(m1);
33 initialize_matrix(m2);
34 m1 = m2;
35 std::cout << "m1 = m2 = " << m1 << std::endl;
36 m1.assign_temporary(m2);
37 std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl;
38 m1.swap(m2);
39 std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl;
40
41 // Zero assignment
42 m1 = ublas::zero_matrix<value_type>(m1.size1(), m1.size2());
43 std::cout << "m1.zero_matrix = " << m1 << std::endl;
44 m1 = m2;
45
46 // Unary matrix operations resulting in a matrix
47 initialize_matrix(m1);
48 m2 = -m1;
49 std::cout << "- m1 = " << m2 << std::endl;
50 m2 = ublas::conj(m1);
51 std::cout << "conj (m1) = " << m2 << std::endl;
52
53 // Binary matrix operations resulting in a matrix
54 initialize_matrix(m1);
55 initialize_matrix(m2);
56 m3 = m1 + m2;
57 std::cout << "m1 + m2 = " << m3 << std::endl;
58 m3 = m1 - m2;
59 std::cout << "m1 - m2 = " << m3 << std::endl;
60
61 // Scaling a matrix
62 t = N;
63 initialize_matrix(m1);
64 m2 = value_type(1.) * m1;
65 std::cout << "1. * m1 = " << m2 << std::endl;
66 m2 = t * m1;
67 std::cout << "N * m1 = " << m2 << std::endl;
68 initialize_matrix(m1);
69 m2 = m1 * value_type(1.);
70 std::cout << "m1 * 1. = " << m2 << std::endl;
71 m2 = m1 * t;
72 std::cout << "m1 * N = " << m2 << std::endl;
73
74 // Some assignments
75 initialize_matrix(m1);
76 initialize_matrix(m2);
77 m2 += m1;
78 std::cout << "m2 += m1 = " << m2 << std::endl;
79 m2 -= m1;
80 std::cout << "m2 -= m1 = " << m2 << std::endl;
81 m2 = m2 + m1;
82 std::cout << "m2 = m2 + m1 = " << m2 << std::endl;
83 m2 = m2 - m1;
84 std::cout << "m2 = m1 - m1 = " << m2 << std::endl;
85 m1 *= value_type(1.);
86 std::cout << "m1 *= 1. = " << m1 << std::endl;
87 m1 *= t;
88 std::cout << "m1 *= N = " << m1 << std::endl;
89
90 // Transpose
91 initialize_matrix(m1);
92 m2 = ublas::trans(m1);
93 std::cout << "trans (m1) = " << m2 << std::endl;
94
95 // Hermitean
96 initialize_matrix(m1);
97 m2 = ublas::herm(m1);
98 std::cout << "herm (m1) = " << m2 << std::endl;
99
100 // Matrix multiplication
101 initialize_matrix(m1);
102 initialize_matrix(m2);
103 m3 = ublas::prod(m1, m2);
104 std::cout << "prod (m1, m2) = " << m3 << std::endl;
105 }
106 }
107 void operator()() const
108 {
109 {
110 M m1(N, N), m2(N, N), m3(N, N);
111 test_with(m1, m2, m3);
7c673cae
FG
112
113#ifdef USE_RANGE
92f5a8d4
TL
114 ublas::matrix_range<M> mr1(m1, ublas::range(0, N), ublas::range(0, N)),
115 mr2(m2, ublas::range(0, N), ublas::range(0, N)),
116 mr3(m3, ublas::range(0, N), ublas::range(0, N));
117 test_with(mr1, mr2, mr3);
7c673cae
FG
118#endif
119
120#ifdef USE_SLICE
92f5a8d4
TL
121 ublas::matrix_slice<M> ms1(m1, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
122 ms2(m2, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
123 ms3(m3, ublas::slice(0, 1, N), ublas::slice(0, 1, N));
124 test_with(ms1, ms2, ms3);
7c673cae 125#endif
92f5a8d4
TL
126 }
127 }
7c673cae
FG
128};
129
130// Test matrix
92f5a8d4
TL
131void test_matrix()
132{
133 std::cout << "test_matrix" << std::endl;
7c673cae
FG
134
135#ifdef USE_MATRIX
136#ifdef USE_BOUNDED_ARRAY
137#ifdef USE_FLOAT
92f5a8d4
TL
138 std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl;
139 test_my_matrix<ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3 * 3> >, 3>()();
7c673cae
FG
140#endif
141
142#ifdef USE_DOUBLE
92f5a8d4
TL
143 std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
144 test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<double>, 3 * 3> >, 3>()();
7c673cae
FG
145#endif
146#endif
147
148#ifdef USE_UNBOUNDED_ARRAY
149#ifdef USE_FLOAT
92f5a8d4
TL
150 std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl;
151 test_my_matrix<ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >, 3>()();
7c673cae
FG
152#endif
153
154#ifdef USE_DOUBLE
92f5a8d4
TL
155 std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
156 test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<double> > >, 3>()();
7c673cae
FG
157#endif
158#endif
159
160#ifdef USE_STD_VECTOR
161#ifdef USE_FLOAT
92f5a8d4
TL
162 std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl;
163 test_my_matrix<ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, std::vector<boost::numeric::interval<mp_test_type> > >, 3>()();
7c673cae
FG
164#endif
165
166#ifdef USE_DOUBLE
92f5a8d4
TL
167 std::cout << "boost::numeric::interval<double>, std::vector" << std::endl;
168 test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, std::vector<boost::numeric::interval<double> > >, 3>()();
7c673cae
FG
169#endif
170#endif
171#endif
172
173#ifdef USE_VECTOR_OF_VECTOR
174#ifdef USE_BOUNDED_ARRAY
175#ifdef USE_FLOAT
92f5a8d4
TL
176 std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl;
177 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3>, 3 + 1> >, 3>()();
7c673cae
FG
178#endif
179
180#ifdef USE_DOUBLE
92f5a8d4
TL
181 std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
182 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<boost::numeric::interval<double>, 3>, 3 + 1> >, 3>()();
7c673cae
FG
183#endif
184#endif
185
186#ifdef USE_UNBOUNDED_ARRAY
187#ifdef USE_FLOAT
92f5a8d4
TL
188 std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl;
189 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<boost::numeric::interval<mp_test_type> > > >, 3>()();
7c673cae
FG
190#endif
191
192#ifdef USE_DOUBLE
92f5a8d4
TL
193 std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
194 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<boost::numeric::interval<double> > > >, 3>()();
7c673cae
FG
195#endif
196#endif
197
198#ifdef USE_STD_VECTOR
199#ifdef USE_FLOAT
92f5a8d4
TL
200 std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl;
201 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<mp_test_type> > > >, 3>()();
7c673cae
FG
202#endif
203
204#ifdef USE_DOUBLE
92f5a8d4
TL
205 std::cout << "boost::numeric::interval<double>, std::vector" << std::endl;
206 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<double> > > >, 3>()();
7c673cae
FG
207#endif
208#endif
209#endif
210}