]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multiprecision/test/ublas_interop/test11.cpp
1 // Copyright (c) 2000-2002
2 // Joerg Walter, Mathias Koch
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // The authors gratefully acknowledge the support of
9 // GeNeSys mbH & Co. KG in producing this work.
13 // Test vector expression templates
14 template<class V
, int N
>
15 struct test_my_vector
{
16 typedef typename
V::value_type value_type
;
17 typedef typename
V::size_type size_type
;
18 typedef typename
ublas::type_traits
<value_type
>::real_type real_type
;
21 void test_container_with (VP
&v1
) const {
22 // Container type tests in addition to expression types
24 v1
.insert_element (0, 55);
30 void test_expression_with (VP
&v1
, VP
&v2
, VP
&v3
) const {
31 // Expression type tests
37 default_construct
<VP
>::test ();
40 initialize_vector (v1
);
41 initialize_vector (v2
);
43 std::cout
<< "v1 = v2 = " << v1
<< std::endl
;
44 v1
.assign_temporary (v2
);
45 std::cout
<< "v1.assign_temporary (v2) = " << v1
<< std::endl
;
47 std::cout
<< "v1.swap (v2) = " << v1
<< " " << v2
<< std::endl
;
50 v1
= ublas::zero_vector
<> (v1
.size ());
51 std::cout
<< "v1.zero_vector = " << v1
<< std::endl
;
54 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
55 // Project range and slice
56 initialize_vector (v1
);
57 initialize_vector (v2
);
58 project (v1
, ublas::range(0,1)) = project (v2
, ublas::range(0,1));
59 project (v1
, ublas::range(0,1)) = project (v2
, ublas::slice(0,1,1));
60 project (v1
, ublas::slice(2,-1,2)) = project (v2
, ublas::slice(0,1,2));
61 project (v1
, ublas::slice(2,-1,2)) = project (v2
, ublas::range(0,2));
62 std::cout
<< "v1 = range/slice " << v1
<< std::endl
;
65 // Unary vector operations resulting in a vector
66 initialize_vector (v1
);
68 std::cout
<< "- v1 = " << v2
<< std::endl
;
69 v2
= ublas::conj (v1
);
70 std::cout
<< "conj (v1) = " << v2
<< std::endl
;
72 // Binary vector operations resulting in a vector
73 initialize_vector (v1
);
74 initialize_vector (v2
);
76 std::cout
<< "v1 + v2 = " << v3
<< std::endl
;
78 std::cout
<< "v1 - v2 = " << v3
<< std::endl
;
79 v3
= ublas::element_prod (v1
, v2
);
80 std::cout
<< "element_prod (v1, v2) = " << v3
<< std::endl
;
84 initialize_vector (v1
);
85 v2
= value_type (1.) * v1
;
86 std::cout
<< "1. * v1 = " << v2
<< std::endl
;
88 std::cout
<< "N * v1 = " << v2
<< std::endl
;
89 initialize_vector (v1
);
90 v2
= v1
* value_type (1.);
91 std::cout
<< "v1 * 1. = " << v2
<< std::endl
;
93 std::cout
<< "v1 * value_type(N) = " << v2
<< std::endl
;
94 // test interop with integer
97 std::cout
<< "v1 * N = " << v2
<< std::endl
;
100 initialize_vector (v1
);
101 initialize_vector (v2
);
103 std::cout
<< "v2 += v1 = " << v2
<< std::endl
;
105 std::cout
<< "v2 -= v1 = " << v2
<< std::endl
;
107 std::cout
<< "v2 = v2 + v1 = " << v2
<< std::endl
;
109 std::cout
<< "v2 = v2 - v1 = " << v2
<< std::endl
;
110 v1
*= value_type (1.);
111 std::cout
<< "v1 *= 1. = " << v1
<< std::endl
;
113 std::cout
<< "v1 *= value_type(N) = " << v1
<< std::endl
;
114 // test interop with integer
116 std::cout
<< "v1 *= N = " << v1
<< std::endl
;
118 // Unary vector operations resulting in a scalar
119 initialize_vector (v1
);
121 std::cout
<< "sum (v1) = " << t
<< std::endl
;
122 n
= ublas::norm_1 (v1
);
123 std::cout
<< "norm_1 (v1) = " << n
<< std::endl
;
124 n
= ublas::norm_2 (v1
);
125 std::cout
<< "norm_2 (v1) = " << n
<< std::endl
;
126 n
= ublas::norm_inf (v1
);
127 std::cout
<< "norm_inf (v1) = " << n
<< std::endl
;
129 i
= ublas::index_norm_inf (v1
);
130 std::cout
<< "index_norm_inf (v1) = " << i
<< std::endl
;
132 // Binary vector operations resulting in a scalar
133 initialize_vector (v1
);
134 initialize_vector (v2
);
135 t
= ublas::inner_prod (v1
, v2
);
136 std::cout
<< "inner_prod (v1, v2) = " << t
<< std::endl
;
138 // Scalar and Binary vector expression resulting in a vector
139 initialize_vector (v1
);
140 initialize_vector (v2
);
141 v1
= v1
* ublas::inner_prod (v1
, v2
);
142 std::cout
<< "v1 * inner_prod (v1, v2) = " << v1
<< std::endl
;
145 void operator () () const {
146 V
v1 (N
), v2 (N
), v3 (N
);
147 test_expression_with (v1
, v2
, v3
);
148 test_container_with (v1
);
151 ublas::vector_range
<V
> vr1 (v1
, ublas::range (0, N
)),
152 vr2 (v2
, ublas::range (0, N
)),
153 vr3 (v3
, ublas::range (0, N
));
154 test_expression_with (vr1
, vr2
, vr3
);
158 ublas::vector_slice
<V
> vs1 (v1
, ublas::slice (0, 1, N
)),
159 vs2 (v2
, ublas::slice (0, 1, N
)),
160 vs3 (v3
, ublas::slice (0, 1, N
));
161 test_expression_with (vs1
, vs2
, vs3
);
167 void test_vector () {
168 std::cout
<< "test_vector" << std::endl
;
170 #ifdef USE_BOUNDED_ARRAY
172 std::cout
<< "mp_test_type, bounded_array" << std::endl
;
173 test_my_vector
<ublas::vector
<mp_test_type
, ublas::bounded_array
<mp_test_type
, 3> >, 3 > () ();
177 std::cout
<< "double, bounded_array" << std::endl
;
178 test_my_vector
<ublas::vector
<double, ublas::bounded_array
<double, 3> >, 3 > () ();
181 #ifdef USE_STD_COMPLEX
183 std::cout
<< "std::complex<mp_test_type>, bounded_array" << std::endl
;
184 test_my_vector
<ublas::vector
<std::complex<mp_test_type
>, ublas::bounded_array
<std::complex<mp_test_type
>, 3> >, 3 > () ();
188 std::cout
<< "std::complex<double>, bounded_array" << std::endl
;
189 test_my_vector
<ublas::vector
<std::complex<double>, ublas::bounded_array
<std::complex<double>, 3> >, 3 > () ();
194 #ifdef USE_UNBOUNDED_ARRAY
196 std::cout
<< "mp_test_type, unbounded_array" << std::endl
;
197 test_my_vector
<ublas::vector
<mp_test_type
, ublas::unbounded_array
<mp_test_type
> >, 3 > () ();
201 std::cout
<< "double, unbounded_array" << std::endl
;
202 test_my_vector
<ublas::vector
<double, ublas::unbounded_array
<double> >, 3 > () ();
205 #ifdef USE_STD_COMPLEX
207 std::cout
<< "std::complex<mp_test_type>, unbounded_array" << std::endl
;
208 test_my_vector
<ublas::vector
<std::complex<mp_test_type
>, ublas::unbounded_array
<std::complex<mp_test_type
> > >, 3 > () ();
212 std::cout
<< "std::complex<double>, unbounded_array" << std::endl
;
213 test_my_vector
<ublas::vector
<std::complex<double>, ublas::unbounded_array
<std::complex<double> > >, 3 > () ();
218 #ifdef USE_STD_VECTOR
220 std::cout
<< "mp_test_type, std::vector" << std::endl
;
221 test_my_vector
<ublas::vector
<mp_test_type
, std::vector
<mp_test_type
> >, 3 > () ();
225 std::cout
<< "double, std::vector" << std::endl
;
226 test_my_vector
<ublas::vector
<double, std::vector
<double> >, 3 > () ();
229 #ifdef USE_STD_COMPLEX
231 std::cout
<< "std::complex<mp_test_type>, std::vector" << std::endl
;
232 test_my_vector
<ublas::vector
<std::complex<mp_test_type
>, std::vector
<std::complex<mp_test_type
> > >, 3 > () ();
236 std::cout
<< "std::complex<double>, std::vector" << std::endl
;
237 test_my_vector
<ublas::vector
<std::complex<double>, std::vector
<std::complex<double> > >, 3 > () ();
242 #ifdef USE_BOUNDED_VECTOR
244 std::cout
<< "mp_test_type, bounded" << std::endl
;
245 test_my_vector
<ublas::bounded_vector
<mp_test_type
, 3>, 3> () ();
249 std::cout
<< "double, bounded" << std::endl
;
250 test_my_vector
<ublas::bounded_vector
<double, 3>, 3> () ();
253 #ifdef USE_STD_COMPLEX
255 std::cout
<< "std::complex<mp_test_type>, bounded" << std::endl
;
256 test_my_vector
<ublas::bounded_vector
<std::complex<mp_test_type
>, 3>, 3> () ();
260 std::cout
<< "std::complex<double>, bounded" << std::endl
;
261 test_my_vector
<ublas::bounded_vector
<std::complex<double>, 3>, 3> () ();