Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/numeric/ublas/test/test4/test43.cpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 12.0 KB
Line 
1//
2//  Copyright (c) 2000-2002
3//  Joerg Walter, Mathias Koch
4//
5//  Permission to use, copy, modify, distribute and sell this software
6//  and its documentation for any purpose is hereby granted without fee,
7//  provided that the above copyright notice appear in all copies and
8//  that both that copyright notice and this permission notice appear
9//  in supporting documentation.  The authors make no representations
10//  about the suitability of this software for any purpose.
11//  It is provided "as is" without express or implied warranty.
12//
13//  The authors gratefully acknowledge the support of
14//  GeNeSys mbH & Co. KG in producing this work.
15//
16
17#include "test4.hpp"
18
19// Test matrix expression templates
20template<class M, int N>
21struct test_my_matrix {
22    typedef typename M::value_type value_type;
23
24    template<class MP>
25    void test_with (MP &m1, MP &m2, MP &m3) const {
26        {
27            value_type t;
28
29            // Default Construct
30            default_construct<MP>::test ();
31           
32            // Copy and swap
33            initialize_matrix (m1);
34            initialize_matrix (m2);
35            m1 = m2;
36            std::cout << "m1 = m2 = " << m1 << std::endl;
37            m1.assign_temporary (m2);
38            std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl;
39            m1.swap (m2);
40            std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl;
41
42            // Unary matrix operations resulting in a matrix
43            initialize_matrix (m1);
44            m2 = - m1;
45            std::cout << "- m1 = " << m2 << std::endl;
46            m2 = ublas::conj (m1);
47            std::cout << "conj (m1) = " << m2 << std::endl;
48
49            // Binary matrix operations resulting in a matrix
50            initialize_matrix (m1);
51            initialize_matrix (m2);
52            m3 = m1 + m2;
53            std::cout << "m1 + m2 = " << m3 << std::endl;
54            m3 = m1 - m2;
55            std::cout << "m1 - m2 = " << m3 << std::endl;
56
57            // Scaling a matrix
58            t = N;
59            initialize_matrix (m1);
60            m2 = value_type (1.) * m1;
61            std::cout << "1. * m1 = " << m2 << std::endl;
62            m2 = t * m1;
63            std::cout << "N * m1 = " << m2 << std::endl;
64            initialize_matrix (m1);
65            m2 = m1 * value_type (1.);
66            std::cout << "m1 * 1. = " << m2 << std::endl;
67            m2 = m1 * t;
68            std::cout << "m1 * N = " << m2 << std::endl;
69
70            // Some assignments
71            initialize_matrix (m1);
72            initialize_matrix (m2);
73            m2 += m1;
74            std::cout << "m2 += m1 = " << m2 << std::endl;
75            m2 -= m1;
76            std::cout << "m2 -= m1 = " << m2 << std::endl;
77            m2 = m2 + m1;
78            std::cout << "m2 = m2 + m1 = " << m2 << std::endl;
79            m2 = m2 - m1;
80            std::cout << "m2 = m2 - m1 = " << m2 << std::endl;
81            m1 *= value_type (1.);
82            std::cout << "m1 *= 1. = " << m1 << std::endl;
83            m1 *= t;
84            std::cout << "m1 *= N = " << m1 << std::endl;
85
86            // Transpose
87            initialize_matrix (m1);
88            m2 = ublas::trans (m1);
89            std::cout << "trans (m1) = " << m2 << std::endl;
90
91            // Hermitean
92            initialize_matrix (m1);
93            m2 = ublas::herm (m1);
94            std::cout << "herm (m1) = " << m2 << std::endl;
95
96            // Matrix multiplication
97            initialize_matrix (m1);
98            initialize_matrix (m2);
99            // Banded times banded isn't banded
100            std::cout << "prod (m1, m2) = " << ublas::prod (m1, m2) << std::endl;
101        }
102    }
103    void operator () () const {
104        {
105#ifdef USE_BANDED
106            M m1 (N, N, 1, 1), m2 (N, N, 1, 1), m3 (N, N, 1, 1);
107#endif
108#ifdef USE_DIAGONAL
109            M m1 (N, N), m2 (N, N), m3 (N, N);
110#endif
111            test_with (m1, m2, m3);
112
113#ifdef USE_RANGE
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);
118#endif
119
120#ifdef USE_SLICE
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);
125#endif
126        }
127
128#ifdef USE_ADAPTOR
129        {
130#ifdef USE_BANDED
131            M m1 (N, N, 1, 1), m2 (N, N, 1, 1), m3 (N, N, 1, 1);
132            ublas::banded_adaptor<M> bam1 (m1, 1, 1), bam2 (m2, 1, 1), bam3 (m3, 1, 1);
133            test_with (bam1, bam2, bam3);
134
135#ifdef USE_RANGE
136            ublas::matrix_range<ublas::banded_adaptor<M> > mr1 (bam1, ublas::range (0, N), ublas::range (0, N)),
137                                                           mr2 (bam2, ublas::range (0, N), ublas::range (0, N)),
138                                                           mr3 (bam3, ublas::range (0, N), ublas::range (0, N));
139            test_with (mr1, mr2, mr3);
140#endif
141
142#ifdef USE_SLICE
143            ublas::matrix_slice<ublas::banded_adaptor<M> > ms1 (bam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
144                                                           ms2 (bam2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
145                                                           ms3 (bam3, ublas::slice (0, 1, N), ublas::slice (0, 1, N));
146            test_with (ms1, ms2, ms3);
147#endif
148#endif
149#ifdef USE_DIAGONAL
150            M m1 (N, N), m2 (N, N), m3 (N, N);
151            ublas::diagonal_adaptor<M> dam1 (m1), dam2 (m2), dam3 (m3);
152            test_with (dam1, dam2, dam3);
153
154#ifdef USE_RANGE
155            ublas::matrix_range<ublas::diagonal_adaptor<M> > mr1 (dam1, ublas::range (0, N), ublas::range (0, N)),
156                                                             mr2 (dam2, ublas::range (0, N), ublas::range (0, N)),
157                                                             mr3 (dam3, ublas::range (0, N), ublas::range (0, N));
158            test_with (mr1, mr2, mr3);
159#endif
160
161#ifdef USE_SLICE
162            ublas::matrix_slice<ublas::diagonal_adaptor<M> > ms1 (dam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
163                                                             ms2 (dam2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
164                                                             ms3 (dam3, ublas::slice (0, 1, N), ublas::slice (0, 1, N));
165            test_with (ms1, ms2, ms3);
166#endif
167#endif
168        }
169#endif
170
171    }
172};
173
174// Test matrix
175void test_matrix () {
176    std::cout << "test_matrix" << std::endl;
177
178#ifdef USE_BANDED
179#ifdef USE_BOUNDED_ARRAY
180#ifdef USE_FLOAT
181    std::cout << "float, bounded_array" << std::endl;
182    test_my_matrix<ublas::banded_matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3 > () ();
183#endif
184
185#ifdef USE_DOUBLE
186    std::cout << "double, bounded_array" << std::endl;
187    test_my_matrix<ublas::banded_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () ();
188#endif
189
190#ifdef USE_STD_COMPLEX
191#ifdef USE_FLOAT
192    std::cout << "std::complex<float>, bounded_array" << std::endl;
193    test_my_matrix<ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3 > () ();
194#endif
195
196#ifdef USE_DOUBLE
197    std::cout << "std::complex<double>, bounded_array" << std::endl;
198    test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () ();
199#endif
200#endif
201#endif
202
203#ifdef USE_UNBOUNDED_ARRAY
204#ifdef USE_FLOAT
205    std::cout << "float, unbounded_array" << std::endl;
206    test_my_matrix<ublas::banded_matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3 > () ();
207#endif
208
209#ifdef USE_DOUBLE
210    std::cout << "double, unbounded_array" << std::endl;
211    test_my_matrix<ublas::banded_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3 > () ();
212#endif
213
214#ifdef USE_STD_COMPLEX
215#ifdef USE_FLOAT
216    std::cout << "std::complex<float>, unbounded_array" << std::endl;
217    test_my_matrix<ublas::banded_matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3 > () ();
218#endif
219
220#ifdef USE_DOUBLE
221    std::cout << "std::complex<double>, unbounded_array" << std::endl;
222    test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () ();
223#endif
224#endif
225#endif
226
227#ifdef USE_STD_VECTOR
228#ifdef USE_FLOAT
229    std::cout << "float, std::vector" << std::endl;
230    test_my_matrix<ublas::banded_matrix<float, ublas::row_major, std::vector<float> >, 3 > () ();
231#endif
232
233#ifdef USE_DOUBLE
234    std::cout << "double, std::vector" << std::endl;
235    test_my_matrix<ublas::banded_matrix<double, ublas::row_major, std::vector<double> >, 3 > () ();
236#endif
237
238#ifdef USE_STD_COMPLEX
239#ifdef USE_FLOAT
240    std::cout << "std::complex<float>, std::vector" << std::endl;
241    test_my_matrix<ublas::banded_matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3 > () ();
242#endif
243
244#ifdef USE_DOUBLE
245    std::cout << "std::complex<double>, std::vector" << std::endl;
246    test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3 > () ();
247#endif
248#endif
249#endif
250#endif
251
252#ifdef USE_DIAGONAL
253#ifdef USE_BOUNDED_ARRAY
254#ifdef USE_FLOAT
255    std::cout << "float, bounded_array" << std::endl;
256    test_my_matrix<ublas::diagonal_matrix<float, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3 > () ();
257#endif
258
259#ifdef USE_DOUBLE
260    std::cout << "double, bounded_array" << std::endl;
261    test_my_matrix<ublas::diagonal_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () ();
262#endif
263
264#ifdef USE_STD_COMPLEX
265#ifdef USE_FLOAT
266    std::cout << "std::complex<float>, bounded_array" << std::endl;
267    test_my_matrix<ublas::diagonal_matrix<std::complex<float>, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3 > () ();
268#endif
269
270#ifdef USE_DOUBLE
271    std::cout << "std::complex<double>, bounded_array" << std::endl;
272    test_my_matrix<ublas::diagonal_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () ();
273#endif
274#endif
275#endif
276
277#ifdef USE_UNBOUNDED_ARRAY
278#ifdef USE_FLOAT
279    std::cout << "float, unbounded_array" << std::endl;
280    test_my_matrix<ublas::diagonal_matrix<float, ublas::row_major, ublas::unbounded_array<float> >, 3 > () ();
281#endif
282
283#ifdef USE_DOUBLE
284    std::cout << "double, unbounded_array" << std::endl;
285    test_my_matrix<ublas::diagonal_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3 > () ();
286#endif
287
288#ifdef USE_STD_COMPLEX
289#ifdef USE_FLOAT
290    std::cout << "std::complex<float>, unbounded_array" << std::endl;
291    test_my_matrix<ublas::diagonal_matrix<std::complex<float>, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3 > () ();
292#endif
293
294#ifdef USE_DOUBLE
295    std::cout << "std::complex<double>, unbounded_array" << std::endl;
296    test_my_matrix<ublas::diagonal_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () ();
297#endif
298#endif
299#endif
300
301#ifdef USE_STD_VECTOR
302#ifdef USE_FLOAT
303    std::cout << "float, std::vector" << std::endl;
304    test_my_matrix<ublas::diagonal_matrix<float, ublas::row_major, std::vector<float> >, 3 > () ();
305#endif
306
307#ifdef USE_DOUBLE
308    std::cout << "double, std::vector" << std::endl;
309    test_my_matrix<ublas::diagonal_matrix<double, ublas::row_major, std::vector<double> >, 3 > () ();
310#endif
311
312#ifdef USE_STD_COMPLEX
313#ifdef USE_FLOAT
314    std::cout << "std::complex<float>, std::vector" << std::endl;
315    test_my_matrix<ublas::diagonal_matrix<std::complex<float>, ublas::row_major, std::vector<std::complex<float> > >, 3 > () ();
316#endif
317
318#ifdef USE_DOUBLE
319    std::cout << "std::complex<double>, std::vector" << std::endl;
320    test_my_matrix<ublas::diagonal_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3 > () ();
321#endif
322#endif
323#endif
324#endif
325}
Note: See TracBrowser for help on using the repository browser.