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 | #include "test6.hpp" |
14 | |
15 | // Test matrix & vector expression templates |
16 | template<class V, class M, int N> |
17 | struct test_my_matrix_vector { |
18 | typedef typename V::value_type value_type; |
19 | |
20 | template<class VP, class MP> |
21 | void test_with (VP &v1, VP &v2, MP &m1) const { |
22 | { |
23 | // Rows and columns |
24 | initialize_matrix (m1); |
25 | for (int i = 0; i < N; ++ i) { |
26 | v2 = ublas::row (m1, i); |
27 | std::cout << "row (m, " << i << ") = " << v2 << std::endl; |
28 | v2 = ublas::column (m1, i); |
29 | std::cout << "column (m, " << i << ") = " << v2 << std::endl; |
30 | } |
31 | |
32 | // Outer product |
33 | initialize_vector (v1); |
34 | initialize_vector (v2); |
35 | v1 (0) = 0; |
36 | v1 (N - 1) = 0; |
37 | v2 (0) = 0; |
38 | v2 (N - 1) = 0; |
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, N - 1), mr2 (m1, N - 1); |
58 | test_with (mr1, mr2, m1); |
59 | |
60 | ublas::matrix_column<M> mc1 (m1, 0), mc2 (m1, 0); |
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 | void operator () (int) const { |
78 | #ifdef USE_ADAPTOR |
79 | { |
80 | V v1 (N), v2 (N); |
81 | M m1 (N, N); |
82 | ublas::symmetric_adaptor<M> tam1 (m1); |
83 | test_with (v1, v2, tam1); |
84 | |
85 | ublas::matrix_row<ublas::symmetric_adaptor<M> > mr1 (tam1, N - 1), mr2 (tam1, N - 1); |
86 | test_with (mr1, mr2, tam1); |
87 | |
88 | ublas::matrix_column<ublas::symmetric_adaptor<M> > mc1 (tam1, 0), mc2 (tam1, 0); |
89 | test_with (mc1, mc2, tam1); |
90 | |
91 | #ifdef USE_RANGE |
92 | ublas::matrix_vector_range<ublas::symmetric_adaptor<M> > mvr1 (tam1, ublas::range (0, N), ublas::range (0, N)), |
93 | mvr2 (tam1, ublas::range (0, N), ublas::range (0, N)); |
94 | test_with (mvr1, mvr2, tam1); |
95 | #endif |
96 | |
97 | #ifdef USE_SLICE |
98 | ublas::matrix_vector_slice<ublas::symmetric_adaptor<M> > mvs1 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), |
99 | mvs2 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); |
100 | test_with (mvs1, mvs2, tam1); |
101 | #endif |
102 | } |
103 | #endif |
104 | } |
105 | }; |
106 | |
107 | // Test matrix & vector |
108 | void test_matrix_vector () { |
109 | std::cout << "test_matrix_vector" << std::endl; |
110 | |
111 | #ifdef USE_BOUNDED_ARRAY |
112 | #ifdef USE_FLOAT |
113 | std::cout << "float, bounded_array" << std::endl; |
114 | test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >, |
115 | ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () (); |
116 | test_my_matrix_vector<ublas::vector<float, ublas::bounded_array<float, 3> >, |
117 | ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3> () (0); |
118 | #endif |
119 | |
120 | #ifdef USE_DOUBLE |
121 | std::cout << "double, bounded_array" << std::endl; |
122 | test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, |
123 | ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (); |
124 | test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, |
125 | ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (0); |
126 | #endif |
127 | |
128 | #ifdef USE_STD_COMPLEX |
129 | #ifdef USE_FLOAT |
130 | std::cout << "std::complex<float>, bounded_array" << std::endl; |
131 | test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >, |
132 | ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () (); |
133 | test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::bounded_array<std::complex<float>, 3> >, |
134 | ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3> () (0); |
135 | #endif |
136 | |
137 | #ifdef USE_DOUBLE |
138 | std::cout << "std::complex<double>, bounded_array" << std::endl; |
139 | test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, |
140 | ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (); |
141 | test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, |
142 | ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (0); |
143 | #endif |
144 | #endif |
145 | #endif |
146 | |
147 | #ifdef USE_UNBOUNDED_ARRAY |
148 | #ifdef USE_FLOAT |
149 | std::cout << "float, unbounded_array" << std::endl; |
150 | test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >, |
151 | ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3> () (); |
152 | test_my_matrix_vector<ublas::vector<float, ublas::unbounded_array<float> >, |
153 | ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3> () (0); |
154 | #endif |
155 | |
156 | #ifdef USE_DOUBLE |
157 | std::cout << "double, unbounded_array" << std::endl; |
158 | test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, |
159 | ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3> () (); |
160 | test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, |
161 | ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3> () (0); |
162 | #endif |
163 | |
164 | #ifdef USE_STD_COMPLEX |
165 | #ifdef USE_FLOAT |
166 | std::cout << "std::complex<float>, unbounded_array" << std::endl; |
167 | test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >, |
168 | ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () (); |
169 | test_my_matrix_vector<ublas::vector<std::complex<float>, ublas::unbounded_array<std::complex<float> > >, |
170 | ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3> () (0); |
171 | #endif |
172 | |
173 | #ifdef USE_DOUBLE |
174 | std::cout << "std::complex<double>, unbounded_array" << std::endl; |
175 | test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, |
176 | ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (); |
177 | test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, |
178 | ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (0); |
179 | #endif |
180 | #endif |
181 | #endif |
182 | |
183 | #ifdef USE_STD_VECTOR |
184 | #ifdef USE_FLOAT |
185 | std::cout << "float, std::vector" << std::endl; |
186 | test_my_matrix_vector<ublas::vector<float, std::vector<float> >, |
187 | ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3> () (); |
188 | test_my_matrix_vector<ublas::vector<float, std::vector<float> >, |
189 | ublas::symmetric_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3> () (0); |
190 | #endif |
191 | |
192 | #ifdef USE_DOUBLE |
193 | std::cout << "double, std::vector" << std::endl; |
194 | test_my_matrix_vector<ublas::vector<double, std::vector<double> >, |
195 | ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3> () (); |
196 | test_my_matrix_vector<ublas::vector<double, std::vector<double> >, |
197 | ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3> () (0); |
198 | #endif |
199 | |
200 | #ifdef USE_STD_COMPLEX |
201 | #ifdef USE_FLOAT |
202 | std::cout << "std::complex<float>, std::vector" << std::endl; |
203 | test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >, |
204 | ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3> () (); |
205 | test_my_matrix_vector<ublas::vector<std::complex<float>, std::vector<std::complex<float> > >, |
206 | ublas::symmetric_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3> () (0); |
207 | #endif |
208 | |
209 | #ifdef USE_DOUBLE |
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::symmetric_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::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3> () (0); |
215 | #endif |
216 | #endif |
217 | #endif |
218 | } |
219 | |