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