]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/ublas/test/test31.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 vector expression templates
16 template<class V
, int N
>
17 struct test_my_vector
{
18 typedef typename
V::value_type value_type
;
19 typedef typename
V::size_type size_type
;
20 typedef typename
ublas::type_traits
<value_type
>::real_type real_type
;
23 void test_with (VP
&v1
, VP
&v2
, VP
&v3
) const {
30 default_construct
<VP
>::test ();
33 initialize_vector (v1
);
34 initialize_vector (v2
);
36 std::cout
<< "v1 = v2 = " << v1
<< std::endl
;
37 v1
.assign_temporary (v2
);
38 std::cout
<< "v1.assign_temporary (v2) = " << v1
<< std::endl
;
40 std::cout
<< "v1.swap (v2) = " << v1
<< " " << v2
<< std::endl
;
43 v1
= ublas::zero_vector
<> (v1
.size ());
44 std::cout
<< "v1.zero_vector = " << v1
<< std::endl
;
47 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
48 // Project range and slice
49 initialize_vector (v1
);
50 initialize_vector (v2
);
51 project (v1
, ublas::range(0,1)) = project (v2
, ublas::range(0,1));
52 project (v1
, ublas::range(0,1)) = project (v2
, ublas::slice(0,1,1));
53 project (v1
, ublas::slice(2,-1,2)) = project (v2
, ublas::slice(0,1,2));
54 project (v1
, ublas::slice(2,-1,2)) = project (v2
, ublas::range(0,2));
55 std::cout
<< "v1 = range/slice " << v1
<< std::endl
;
58 // Unary vector operations resulting in a vector
59 initialize_vector (v1
);
61 std::cout
<< "- v1 = " << v2
<< std::endl
;
62 v2
= ublas::conj (v1
);
63 std::cout
<< "conj (v1) = " << v2
<< std::endl
;
65 // Binary vector operations resulting in a vector
66 initialize_vector (v1
);
67 initialize_vector (v2
);
68 initialize_vector (v3
);
70 std::cout
<< "v1 + v2 = " << v3
<< std::endl
;
73 std::cout
<< "v1 - v2 = " << v3
<< std::endl
;
77 initialize_vector (v1
);
78 v2
= value_type (1.) * v1
;
79 std::cout
<< "1. * v1 = " << v2
<< std::endl
;
81 std::cout
<< "N * v1 = " << v2
<< std::endl
;
82 initialize_vector (v1
);
83 v2
= v1
* value_type (1.);
84 std::cout
<< "v1 * 1. = " << v2
<< std::endl
;
86 std::cout
<< "v1 * N = " << v2
<< std::endl
;
89 initialize_vector (v1
);
90 initialize_vector (v2
);
92 std::cout
<< "v2 += v1 = " << v2
<< std::endl
;
94 std::cout
<< "v2 -= v1 = " << v2
<< std::endl
;
96 std::cout
<< "v2 = v2 + v1 = " << v2
<< std::endl
;
98 std::cout
<< "v2 = v2 - v1 = " << v2
<< std::endl
;
99 v1
*= value_type (1.);
100 std::cout
<< "v1 *= 1. = " << v1
<< std::endl
;
102 std::cout
<< "v1 *= N = " << v1
<< std::endl
;
104 // Unary vector operations resulting in a scalar
105 initialize_vector (v1
);
107 std::cout
<< "sum (v1) = " << t
<< std::endl
;
108 n
= ublas::norm_1 (v1
);
109 std::cout
<< "norm_1 (v1) = " << n
<< std::endl
;
110 n
= ublas::norm_2 (v1
);
111 std::cout
<< "norm_2 (v1) = " << n
<< std::endl
;
112 n
= ublas::norm_inf (v1
);
113 std::cout
<< "norm_inf (v1) = " << n
<< std::endl
;
115 i
= ublas::index_norm_inf (v1
);
116 std::cout
<< "index_norm_inf (v1) = " << i
<< std::endl
;
118 // Binary vector operations resulting in a scalar
119 initialize_vector (v1
);
120 initialize_vector (v2
);
121 t
= ublas::inner_prod (v1
, v2
);
122 std::cout
<< "inner_prod (v1, v2) = " << t
<< std::endl
;
125 void operator () () const {
127 V
v1 (N
, N
), v2 (N
, N
), v3 (N
, N
);
128 test_with (v1
, v2
, v3
);
131 ublas::vector_range
<V
> vr1 (v1
, ublas::range (0, N
)),
132 vr2 (v2
, ublas::range (0, N
)),
133 vr3 (v3
, ublas::range (0, N
));
134 test_with (vr1
, vr2
, vr3
);
138 ublas::vector_slice
<V
> vs1 (v1
, ublas::slice (0, 1, N
)),
139 vs2 (v2
, ublas::slice (0, 1, N
)),
140 vs3 (v3
, ublas::slice (0, 1, N
));
141 test_with (vs1
, vs2
, vs3
);
148 void test_vector () {
149 std::cout
<< "test_vector" << std::endl
;
151 #ifdef USE_SPARSE_VECTOR
154 std::cout
<< "float, map_array" << std::endl
;
155 test_my_vector
<ublas::mapped_vector
<float, ublas::map_array
<std::size_t, float> >, 3 > () ();
159 std::cout
<< "double, map_array" << std::endl
;
160 test_my_vector
<ublas::mapped_vector
<double, ublas::map_array
<std::size_t, double> >, 3 > () ();
163 #ifdef USE_STD_COMPLEX
165 std::cout
<< "std::complex<float>, map_array" << std::endl
;
166 test_my_vector
<ublas::mapped_vector
<std::complex<float>, ublas::map_array
<std::size_t, std::complex<float> > >, 3 > () ();
170 std::cout
<< "std::complex<double>, map_array" << std::endl
;
171 test_my_vector
<ublas::mapped_vector
<std::complex<double>, ublas::map_array
<std::size_t, std::complex<double> > >, 3 > () ();
178 std::cout
<< "float, std::map" << std::endl
;
179 test_my_vector
<ublas::mapped_vector
<float, std::map
<std::size_t, float> >, 3 > () ();
183 std::cout
<< "double, std::map" << std::endl
;
184 test_my_vector
<ublas::mapped_vector
<double, std::map
<std::size_t, double> >, 3 > () ();
187 #ifdef USE_STD_COMPLEX
189 std::cout
<< "std::complex<float>, std::map" << std::endl
;
190 test_my_vector
<ublas::mapped_vector
<std::complex<float>, std::map
<std::size_t, std::complex<float> > >, 3 > () ();
194 std::cout
<< "std::complex<double>, std::map" << std::endl
;
195 test_my_vector
<ublas::mapped_vector
<std::complex<double>, std::map
<std::size_t, std::complex<double> > > , 3 > () ();
201 #ifdef USE_COMPRESSED_VECTOR
203 std::cout
<< "float compressed" << std::endl
;
204 test_my_vector
<ublas::compressed_vector
<float>, 3 > () ();
208 std::cout
<< "double compressed" << std::endl
;
209 test_my_vector
<ublas::compressed_vector
<double>, 3 > () ();
212 #ifdef USE_STD_COMPLEX
214 std::cout
<< "std::complex<float> compressed" << std::endl
;
215 test_my_vector
<ublas::compressed_vector
<std::complex<float> >, 3 > () ();
219 std::cout
<< "std::complex<double> compressed" << std::endl
;
220 test_my_vector
<ublas::compressed_vector
<std::complex<double> >, 3 > () ();
225 #ifdef USE_COORDINATE_VECTOR
227 std::cout
<< "float coordinate" << std::endl
;
228 test_my_vector
<ublas::coordinate_vector
<float>, 3 > () ();
232 std::cout
<< "double coordinate" << std::endl
;
233 test_my_vector
<ublas::coordinate_vector
<double>, 3 > () ();
236 #ifdef USE_STD_COMPLEX
238 std::cout
<< "std::complex<float> coordinate" << std::endl
;
239 test_my_vector
<ublas::coordinate_vector
<std::complex<float> >, 3 > () ();
243 std::cout
<< "std::complex<double> coordinate" << std::endl
;
244 test_my_vector
<ublas::coordinate_vector
<std::complex<double> >, 3 > () ();