Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/numeric/ublas/test/test12.cpp @ 29

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

updated boost from 1_33_1 to 1_34_1

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