Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / multiprecision / test / ublas_interop / test12.cpp
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 #if defined(__GNUC__) && (__GNUC__ >= 9)
14 #pragma GCC diagnostic ignored "-Wdeprecated-copy"
15 #endif
16
17 #include "test1.hpp"
18
19 // Test matrix & vector expression templates
20 template <class V, class M, int N>
21 struct test_my_matrix_vector
22 {
23    typedef typename V::value_type value_type;
24
25    template <class VP, class MP>
26    void test_with(VP& v1, VP& v2, MP& m1) const
27    {
28       {
29          // Rows and columns
30          initialize_matrix(m1);
31          for (int i = 0; i < N; ++i)
32          {
33             v1 = ublas::row(m1, i);
34             std::cout << "row (m, " << i << ") = " << v1 << std::endl;
35             v1 = ublas::column(m1, i);
36             std::cout << "column (m, " << i << ") = " << v1 << std::endl;
37          }
38
39          // Outer product
40          initialize_vector(v1);
41          initialize_vector(v2);
42          m1 = ublas::outer_prod(v1, v2);
43          std::cout << "outer_prod (v1, v2) = " << m1 << std::endl;
44
45          // Matrix vector product
46          initialize_matrix(m1);
47          initialize_vector(v1);
48          v2 = ublas::prod(m1, v1);
49          std::cout << "prod (m1, v1) = " << v2 << std::endl;
50          v2 = ublas::prod(v1, m1);
51          std::cout << "prod (v1, m1) = " << v2 << std::endl;
52       }
53    }
54    void operator()() const
55    {
56       {
57          V v1(N), v2(N);
58          M m1(N, N);
59          test_with(v1, v2, m1);
60
61          ublas::matrix_row<M> mr1(m1, 0), mr2(m1, 1);
62          test_with(mr1, mr2, m1);
63
64          ublas::matrix_column<M> mc1(m1, 0), mc2(m1, 1);
65          test_with(mc1, mc2, m1);
66
67 #ifdef USE_RANGE
68          ublas::matrix_vector_range<M> mvr1(m1, ublas::range(0, N), ublas::range(0, N)),
69              mvr2(m1, ublas::range(0, N), ublas::range(0, N));
70          test_with(mvr1, mvr2, m1);
71 #endif
72
73 #ifdef USE_SLICE
74          ublas::matrix_vector_slice<M> mvs1(m1, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
75              mvs2(m1, ublas::slice(0, 1, N), ublas::slice(0, 1, N));
76          test_with(mvs1, mvs2, m1);
77 #endif
78       }
79    }
80 };
81
82 // Test matrix & vector
83 void test_matrix_vector()
84 {
85    std::cout << "test_matrix_vector" << std::endl;
86
87 #ifdef USE_MATRIX
88 #ifdef USE_BOUNDED_ARRAY
89 #ifdef USE_FLOAT
90    std::cout << "mp_test_type, bounded_array" << std::endl;
91    test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >,
92                          ublas::matrix<mp_test_type, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3>()();
93 #endif
94
95 #ifdef USE_DOUBLE
96    std::cout << "double, bounded_array" << std::endl;
97    test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
98                          ublas::matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3>()();
99 #endif
100
101 #ifdef USE_STD_COMPLEX
102 #ifdef USE_FLOAT
103    std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl;
104    test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >,
105                          ublas::matrix<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3>()();
106 #endif
107
108 #ifdef USE_DOUBLE
109    std::cout << "std::complex<double>, bounded_array" << std::endl;
110    test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
111                          ublas::matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3>()();
112 #endif
113 #endif
114 #endif
115
116 #ifdef USE_UNBOUNDED_ARRAY
117 #ifdef USE_FLOAT
118    std::cout << "mp_test_type, unbounded_array" << std::endl;
119    test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >,
120                          ublas::matrix<mp_test_type, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3>()();
121 #endif
122
123 #ifdef USE_DOUBLE
124    std::cout << "double, unbounded_array" << std::endl;
125    test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
126                          ublas::matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3>()();
127 #endif
128
129 #ifdef USE_STD_COMPLEX
130 #ifdef USE_FLOAT
131    std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl;
132    test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >,
133                          ublas::matrix<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3>()();
134 #endif
135
136 #ifdef USE_DOUBLE
137    std::cout << "std::complex<double>, unbounded_array" << std::endl;
138    test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
139                          ublas::matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3>()();
140 #endif
141 #endif
142 #endif
143
144 #ifdef USE_STD_VECTOR
145 #ifdef USE_FLOAT
146    std::cout << "mp_test_type, std::vector" << std::endl;
147    test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >,
148                          ublas::matrix<mp_test_type, ublas::row_major, std::vector<mp_test_type> >, 3>()();
149 #endif
150
151 #ifdef USE_DOUBLE
152    std::cout << "double, std::vector" << std::endl;
153    test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
154                          ublas::matrix<double, ublas::row_major, std::vector<double> >, 3>()();
155 #endif
156
157 #ifdef USE_STD_COMPLEX
158 #ifdef USE_FLOAT
159    std::cout << "std::complex<mp_test_type>, std::vector" << std::endl;
160    test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >,
161                          ublas::matrix<std::complex<mp_test_type>, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3>()();
162 #endif
163
164 #ifdef USE_DOUBLE
165    std::cout << "std::complex<double>, std::vector" << std::endl;
166    test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
167                          ublas::matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3>()();
168 #endif
169 #endif
170 #endif
171 #endif
172
173 #ifdef USE_BOUNDED_MATRIX
174 #ifdef USE_FLOAT
175    std::cout << "mp_test_type, bounded" << std::endl;
176    test_my_matrix_vector<ublas::bounded_vector<mp_test_type, 3>,
177                          ublas::bounded_matrix<mp_test_type, 3, 3>, 3>()();
178 #endif
179
180 #ifdef USE_DOUBLE
181    std::cout << "double, bounded" << std::endl;
182    test_my_matrix_vector<ublas::bounded_vector<double, 3>,
183                          ublas::bounded_matrix<double, 3, 3>, 3>()();
184 #endif
185
186 #ifdef USE_STD_COMPLEX
187 #ifdef USE_FLOAT
188    std::cout << "std::complex<mp_test_type>, bounded" << std::endl;
189    test_my_matrix_vector<ublas::bounded_vector<std::complex<mp_test_type>, 3>,
190                          ublas::bounded_matrix<std::complex<mp_test_type>, 3, 3>, 3>()();
191 #endif
192
193 #ifdef USE_DOUBLE
194    std::cout << "std::complex<double>, bounded" << std::endl;
195    test_my_matrix_vector<ublas::bounded_vector<std::complex<double>, 3>,
196                          ublas::bounded_matrix<std::complex<double>, 3, 3>, 3>()();
197 #endif
198 #endif
199 #endif
200
201 #ifdef USE_VECTOR_OF_VECTOR
202 #ifdef USE_BOUNDED_ARRAY
203 #ifdef USE_FLOAT
204    std::cout << "mp_test_type, bounded_array" << std::endl;
205    test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >,
206                          ublas::vector_of_vector<mp_test_type, ublas::row_major, ublas::bounded_array<ublas::bounded_array<mp_test_type, 3>, 3 + 1> >, 3>()();
207 #endif
208
209 #ifdef USE_DOUBLE
210    std::cout << "double, bounded_array" << std::endl;
211    test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
212                          ublas::vector_of_vector<double, ublas::row_major, ublas::bounded_array<ublas::bounded_array<double, 3>, 3 + 1> >, 3>()();
213 #endif
214
215 #ifdef USE_STD_COMPLEX
216 #ifdef USE_FLOAT
217    std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl;
218    test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >,
219                          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>()();
220 #endif
221
222 #ifdef USE_DOUBLE
223    std::cout << "std::complex<double>, bounded_array" << std::endl;
224    test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
225                          ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<double>, 3>, 3 + 1> >, 3>()();
226 #endif
227 #endif
228 #endif
229
230 #ifdef USE_UNBOUNDED_ARRAY
231 #ifdef USE_FLOAT
232    std::cout << "mp_test_type, unbounded_array" << std::endl;
233    test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >,
234                          ublas::vector_of_vector<mp_test_type, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<mp_test_type> > >, 3>()();
235 #endif
236
237 #ifdef USE_DOUBLE
238    std::cout << "double, unbounded_array" << std::endl;
239    test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
240                          ublas::vector_of_vector<double, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<double> > >, 3>()();
241 #endif
242
243 #ifdef USE_STD_COMPLEX
244 #ifdef USE_FLOAT
245    std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl;
246    test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >,
247                          ublas::vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<mp_test_type> > > >, 3>()();
248 #endif
249
250 #ifdef USE_DOUBLE
251    std::cout << "std::complex<double>, unbounded_array" << std::endl;
252    test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
253                          ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<double> > > >, 3>()();
254 #endif
255 #endif
256 #endif
257
258 #ifdef USE_STD_VECTOR
259 #ifdef USE_FLOAT
260    std::cout << "mp_test_type, std::vector" << std::endl;
261    test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >,
262                          ublas::vector_of_vector<mp_test_type, ublas::row_major, std::vector<std::vector<mp_test_type> > >, 3>()();
263 #endif
264
265 #ifdef USE_DOUBLE
266    std::cout << "double, std::vector" << std::endl;
267    test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
268                          ublas::vector_of_vector<double, ublas::row_major, std::vector<std::vector<double> > >, 3>()();
269 #endif
270
271 #ifdef USE_STD_COMPLEX
272 #ifdef USE_FLOAT
273    std::cout << "std::complex<mp_test_type>, std::vector" << std::endl;
274    test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >,
275                          ublas::vector_of_vector<std::complex<mp_test_type>, ublas::row_major, std::vector<std::vector<std::complex<mp_test_type> > > >, 3>()();
276 #endif
277
278 #ifdef USE_DOUBLE
279    std::cout << "std::complex<double>, std::vector" << std::endl;
280    test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
281                          ublas::vector_of_vector<std::complex<double>, ublas::row_major, std::vector<std::vector<std::complex<double> > > >, 3>()();
282 #endif
283 #endif
284 #endif
285 #endif
286 }