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