Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / multiprecision / test / ublas_interop / test63.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 "test6.hpp"
18
19 // Test matrix expression templates
20 template <class M, int N>
21 struct 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          // Default Construct
32          default_construct<MP>::test();
33
34          // Copy and swap
35          initialize_matrix(m1);
36          initialize_matrix(m2);
37          m1 = m2;
38          std::cout << "m1 = m2 = " << m1 << std::endl;
39          m1.assign_temporary(m2);
40          std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl;
41          m1.swap(m2);
42          std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl;
43
44          // Zero assignment
45          m1 = ublas::zero_matrix<>(m1.size1(), m1.size2());
46          std::cout << "m1.zero_matrix = " << m1 << std::endl;
47          m1 = m2;
48
49          // Unary matrix operations resulting in a matrix
50          initialize_matrix(m1);
51          m2 = -m1;
52          std::cout << "- m1 = " << m2 << std::endl;
53          m2 = ublas::conj(m1);
54          std::cout << "conj (m1) = " << m2 << std::endl;
55
56          // Binary matrix operations resulting in a matrix
57          initialize_matrix(m1);
58          initialize_matrix(m2);
59          m3 = m1 + m2;
60          std::cout << "m1 + m2 = " << m3 << std::endl;
61          m3 = m1 - m2;
62          std::cout << "m1 - m2 = " << m3 << std::endl;
63
64          // Scaling a matrix
65          t = N;
66          initialize_matrix(m1);
67          m2 = value_type(1.) * m1;
68          std::cout << "1. * m1 = " << m2 << std::endl;
69          m2 = t * m1;
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;
74          m2 = m1 * t;
75          std::cout << "m1 * N = " << m2 << std::endl;
76
77          // Some assignments
78          initialize_matrix(m1);
79          initialize_matrix(m2);
80          m2 += m1;
81          std::cout << "m2 += m1 = " << m2 << std::endl;
82          m2 -= m1;
83          std::cout << "m2 -= m1 = " << m2 << std::endl;
84          m2 = m2 + m1;
85          std::cout << "m2 = m2 + m1 = " << m2 << std::endl;
86          m2 = m2 - m1;
87          std::cout << "m2 = m1 - m1 = " << m2 << std::endl;
88          m1 *= value_type(1.);
89          std::cout << "m1 *= 1. = " << m1 << std::endl;
90          m1 *= t;
91          std::cout << "m1 *= N = " << m1 << std::endl;
92
93          // Transpose
94          initialize_matrix(m1);
95          m2 = ublas::trans(m1);
96          std::cout << "trans (m1) = " << m2 << std::endl;
97
98          // Hermitean
99          initialize_matrix(m1);
100          m2 = ublas::herm(m1);
101          std::cout << "herm (m1) = " << m2 << std::endl;
102
103          // Matrix multiplication
104          initialize_matrix(m1);
105          initialize_matrix(m2);
106          m3 = ublas::prod(m1, m2);
107          std::cout << "prod (m1, m2) = " << m3 << std::endl;
108       }
109    }
110    void operator()() const
111    {
112       {
113          M m1(N, N), m2(N, N), m3(N, N);
114          test_with(m1, m2, m3);
115
116 #ifdef USE_RANGE
117          ublas::matrix_range<M> mr1(m1, ublas::range(0, N), ublas::range(0, N)),
118              mr2(m2, ublas::range(0, N), ublas::range(0, N)),
119              mr3(m3, ublas::range(0, N), ublas::range(0, N));
120          test_with(mr1, mr2, mr3);
121 #endif
122
123 #ifdef USE_SLICE
124          ublas::matrix_slice<M> ms1(m1, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
125              ms2(m2, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
126              ms3(m3, ublas::slice(0, 1, N), ublas::slice(0, 1, N));
127          test_with(ms1, ms2, ms3);
128 #endif
129       }
130
131 #ifdef USE_ADAPTOR
132       {
133          M                           m1(N, N), m2(N, N), m3(N, N);
134          ublas::symmetric_adaptor<M> sam1(m1), sam2(m2), sam3(m3);
135          test_with(sam1, sam2, sam3);
136
137 #ifdef USE_RANGE
138          ublas::matrix_range<ublas::symmetric_adaptor<M> > mr1(sam1, ublas::range(0, N), ublas::range(0, N)),
139              mr2(sam2, ublas::range(0, N), ublas::range(0, N)),
140              mr3(sam3, ublas::range(0, N), ublas::range(0, N));
141          test_with(mr1, mr2, mr3);
142 #endif
143
144 #ifdef USE_SLICE
145          ublas::matrix_slice<ublas::symmetric_adaptor<M> > ms1(sam1, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
146              ms2(sam2, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
147              ms3(sam3, ublas::slice(0, 1, N), ublas::slice(0, 1, N));
148          test_with(ms1, ms2, ms3);
149 #endif
150       }
151 #endif
152    }
153 };
154
155 // Test matrix
156 void test_matrix()
157 {
158    std::cout << "test_matrix" << std::endl;
159
160 #ifdef USE_BOUNDED_ARRAY
161 #ifdef USE_FLOAT
162    std::cout << "mp_test_type, bounded_array" << std::endl;
163    test_my_matrix<ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3>()();
164 #endif
165
166 #ifdef USE_DOUBLE
167    std::cout << "double, bounded_array" << std::endl;
168    test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3>()();
169 #endif
170
171 #ifdef USE_STD_COMPLEX
172 #ifdef USE_FLOAT
173    std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl;
174    test_my_matrix<ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3>()();
175 #endif
176
177 #ifdef USE_DOUBLE
178    std::cout << "std::complex<double>, bounded_array" << std::endl;
179    test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3>()();
180 #endif
181 #endif
182 #endif
183
184 #ifdef USE_UNBOUNDED_ARRAY
185 #ifdef USE_FLOAT
186    std::cout << "mp_test_type, unbounded_array" << std::endl;
187    test_my_matrix<ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3>()();
188 #endif
189
190 #ifdef USE_DOUBLE
191    std::cout << "double, unbounded_array" << std::endl;
192    test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3>()();
193 #endif
194
195 #ifdef USE_STD_COMPLEX
196 #ifdef USE_FLOAT
197    std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl;
198    test_my_matrix<ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3>()();
199 #endif
200
201 #ifdef USE_DOUBLE
202    std::cout << "std::complex<double>, unbounded_array" << std::endl;
203    test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3>()();
204 #endif
205 #endif
206 #endif
207
208 #ifdef USE_STD_VECTOR
209 #ifdef USE_FLOAT
210    std::cout << "mp_test_type, std::vector" << std::endl;
211    test_my_matrix<ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, std::vector<mp_test_type> >, 3>()();
212 #endif
213
214 #ifdef USE_DOUBLE
215    std::cout << "double, std::vector" << std::endl;
216    test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3>()();
217 #endif
218
219 #ifdef USE_STD_COMPLEX
220 #ifdef USE_FLOAT
221    std::cout << "std::complex<mp_test_type>, std::vector" << std::endl;
222    test_my_matrix<ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3>()();
223 #endif
224
225 #ifdef USE_DOUBLE
226    std::cout << "std::complex<double>, std::vector" << std::endl;
227    test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3>()();
228 #endif
229 #endif
230 #endif
231 }