Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/numeric/ublas/test/test5/test52.cpp @ 12

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

added boost

File size: 10.7 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 "test5.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                v2 = ublas::row (m1, i);
31                std::cout << "row (m, " << i << ") = " << v2 << std::endl;
32                v2 = ublas::column (m1, i);
33                std::cout << "column (m, " << i << ") = " << v2 << std::endl;
34            }
35
36            // Outer product
37            initialize_vector (v1);
38            initialize_vector (v2);
39            v1 (0) = 0;
40            v2 (N - 1) = 0;
41            m1 = ublas::outer_prod (v1, v2);
42            std::cout << "outer_prod (v1, v2) = " << m1 << std::endl;
43
44            // Matrix vector product
45            initialize_matrix (m1);
46            initialize_vector (v1);
47            v2 = ublas::prod (m1, v1);
48            std::cout << "prod (m1, v1) = " << v2 << std::endl;
49            v2 = ublas::prod (v1, m1);
50            std::cout << "prod (v1, m1) = " << v2 << std::endl;
51        }
52    }
53    void operator () () const {
54        {
55            V v1 (N), v2 (N);
56            M m1 (N, N);
57            test_with (v1, v2, m1);
58
59            ublas::matrix_row<M> mr1 (m1, N - 1), mr2 (m1, N - 1);
60            test_with (mr1, mr2, m1);
61
62            ublas::matrix_column<M> mc1 (m1, 0), mc2 (m1, 0);
63            test_with (mc1, mc2, m1);
64
65#ifdef USE_RANGE
66            ublas::matrix_vector_range<M> mvr1 (m1, ublas::range (0, N), ublas::range (0, N)),
67                                          mvr2 (m1, ublas::range (0, N), ublas::range (0, N));
68            test_with (mvr1, mvr2, m1);
69#endif
70
71#ifdef USE_SLICE
72            ublas::matrix_vector_slice<M> mvs1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
73                                          mvs2 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N));
74            test_with (mvs1, mvs2, m1);
75#endif
76        }
77    }
78
79    void operator () (int) const {
80#ifdef USE_ADAPTOR
81        {
82            V v1 (N), v2 (N);
83            M m1 (N, N);
84            ublas::triangular_adaptor<M> tam1 (m1);
85            test_with (v1, v2, tam1);
86
87            ublas::matrix_row<ublas::triangular_adaptor<M> > mr1 (tam1, N - 1), mr2 (tam1, N - 1);
88            test_with (mr1, mr2, tam1);
89
90            ublas::matrix_column<ublas::triangular_adaptor<M> > mc1 (tam1, 0), mc2 (tam1, 0);
91            test_with (mc1, mc2, tam1);
92
93#ifdef USE_RANGE
94            ublas::matrix_vector_range<ublas::triangular_adaptor<M> > mvr1 (tam1, ublas::range (0, N), ublas::range (0, N)),
95                                                                      mvr2 (tam1, ublas::range (0, N), ublas::range (0, N));
96            test_with (mvr1, mvr2, tam1);
97#endif
98
99#ifdef USE_SLICE
100            ublas::matrix_vector_slice<ublas::triangular_adaptor<M> > mvs1 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
101                                                                      mvs2 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N));
102            test_with (mvs1, mvs2, tam1);
103#endif
104        }
105#endif
106    }
107};
108
109// Test matrix & vector
110void test_matrix_vector () {
111    std::cout << "test_matrix_vector" << std::endl;
112
113#ifdef USE_BOUNDED_ARRAY
114#ifdef USE_FLOAT
115    std::cout << "float, bounded_array" << std::endl;
116    test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >,
117                          ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () ();
118    test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >,
119                          ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () (0);
120#endif
121
122#ifdef USE_DOUBLE
123    std::cout << "double, bounded_array" << std::endl;
124    test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
125                          ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () ();
126    test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
127                          ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (0);
128#endif
129
130#ifdef USE_STD_COMPLEX
131#ifdef USE_FLOAT
132    std::cout << "std::complex<float>, bounded_array" << std::endl;
133    test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >,
134                          ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () ();
135    test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >,
136                          ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () (0);
137#endif
138
139#ifdef USE_DOUBLE
140    std::cout << "std::complex<double>, bounded_array" << std::endl;
141    test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
142                          ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () ();
143    test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
144                          ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (0);
145#endif
146#endif
147#endif
148
149#ifdef USE_UNBOUNDED_ARRAY
150#ifdef USE_FLOAT
151    std::cout << "float, unbounded_array" << std::endl;
152    test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >,
153                          ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3> () ();
154    test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >,
155                          ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3> () (0);
156#endif
157
158#ifdef USE_DOUBLE
159    std::cout << "double, unbounded_array" << std::endl;
160    test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
161                          ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3> () ();
162    test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
163                          ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3> () (0);
164#endif
165
166#ifdef USE_STD_COMPLEX
167#ifdef USE_FLOAT
168    std::cout << "std::complex<float>, unbounded_array" << std::endl;
169    test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >,
170                          ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () ();
171    test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >,
172                          ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () (0);
173#endif
174
175#ifdef USE_DOUBLE
176    std::cout << "std::complex<double>, unbounded_array" << std::endl;
177    test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
178                          ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () ();
179    test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
180                          ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (0);
181#endif
182#endif
183#endif
184
185#ifdef USE_STD_VECTOR
186#ifdef USE_FLOAT
187    std::cout << "float, std::vector" << std::endl;
188    test_my_matrix_vector<ublas::vector<float, std::vector<float> >,
189                          ublas::triangular_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3> () ();
190    test_my_matrix_vector<ublas::vector<float, std::vector<float> >,
191                          ublas::triangular_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3> () (0);
192#endif
193
194#ifdef USE_DOUBLE
195    std::cout << "double, std::vector" << std::endl;
196    test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
197                          ublas::triangular_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3> () ();
198    test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
199                          ublas::triangular_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3> () (0);
200#endif
201
202#ifdef USE_STD_COMPLEX
203#ifdef USE_FLOAT
204    std::cout << "std::complex<float>, std::vector" << std::endl;
205    test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >,
206                          ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3> () ();
207    test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >,
208                          ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3> () (0);
209
210    std::cout << "std::complex<double>, std::vector" << std::endl;
211    test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
212                          ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3> () ();
213    test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
214                          ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3> () (0);
215#endif
216#endif
217#endif
218}
Note: See TracBrowser for help on using the repository browser.