]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/ublas/test/test62.cpp
2 // Copyright (c) 2000-2002
3 // Joerg Walter, Mathias Koch
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)
9 // The authors gratefully acknowledge the support of
10 // GeNeSys mbH & Co. KG in producing this work.
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
;
20 template<class VP
, class MP
>
21 void test_with (VP
&v1
, VP
&v2
, MP
&m1
) const {
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
;
33 initialize_vector (v1
);
34 initialize_vector (v2
);
39 m1
= ublas::outer_prod (v1
, v2
);
40 std::cout
<< "outer_prod (v1, v2) = " << m1
<< std::endl
;
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
;
51 void operator () () const {
55 test_with (v1
, v2
, m1
);
57 ublas::matrix_row
<M
> mr1 (m1
, N
- 1), mr2 (m1
, N
- 1);
58 test_with (mr1
, mr2
, m1
);
60 ublas::matrix_column
<M
> mc1 (m1
, 0), mc2 (m1
, 0);
61 test_with (mc1
, mc2
, m1
);
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
);
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
);
77 void operator () (int) const {
82 ublas::symmetric_adaptor
<M
> tam1 (m1
);
83 test_with (v1
, v2
, tam1
);
85 ublas::matrix_row
<ublas::symmetric_adaptor
<M
> > mr1 (tam1
, N
- 1), mr2 (tam1
, N
- 1);
86 test_with (mr1
, mr2
, tam1
);
88 ublas::matrix_column
<ublas::symmetric_adaptor
<M
> > mc1 (tam1
, 0), mc2 (tam1
, 0);
89 test_with (mc1
, mc2
, tam1
);
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
);
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
);
107 // Test matrix & vector
108 void test_matrix_vector () {
109 std::cout
<< "test_matrix_vector" << std::endl
;
111 #ifdef USE_BOUNDED_ARRAY
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);
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);
128 #ifdef USE_STD_COMPLEX
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);
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);
147 #ifdef USE_UNBOUNDED_ARRAY
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);
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);
164 #ifdef USE_STD_COMPLEX
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);
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);
183 #ifdef USE_STD_VECTOR
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);
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);
200 #ifdef USE_STD_COMPLEX
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);
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);