Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / multiprecision / test / ublas_interop / test71.cpp
1 //  Copyright (c) 2000-2002
2 //  Joerg Walter, Mathias Koch
3 //
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)
7 //
8 //  The authors gratefully acknowledge the support of
9 //  GeNeSys mbH & Co. KG in producing this work.
10 //
11
12 //
13 // This file fails to compile - appears to be a known uBlas issue :-(
14 //
15
16 #if defined(__GNUC__) && (__GNUC__ >= 9)
17 #pragma GCC diagnostic ignored "-Wdeprecated-copy"
18 #endif
19
20 #include "test7.hpp"
21
22 // Test vector expression templates
23 template <class V, int N>
24 struct test_my_vector
25 {
26    typedef typename V::value_type                             value_type;
27    typedef typename V::size_type                              size_type;
28    typedef typename ublas::type_traits<value_type>::real_type real_type;
29
30    template <class VP>
31    void test_with(VP& v1, VP& v2, VP& v3) const
32    {
33       {
34          value_type t;
35          size_type  i;
36          real_type  n;
37
38          // Copy and swap
39          initialize_vector(v1);
40          initialize_vector(v2);
41          v1 = v2;
42          std::cout << "v1 = v2 = " << v1 << std::endl;
43          v1.assign_temporary(v2);
44          std::cout << "v1.assign_temporary (v2) = " << v1 << std::endl;
45          v1.swap(v2);
46          std::cout << "v1.swap (v2) = " << v1 << " " << v2 << std::endl;
47
48          // Zero assignment
49          v1 = ublas::zero_vector<value_type>(v1.size());
50          std::cout << "v1.zero_vector = " << v1 << std::endl;
51          v1 = v2;
52
53          // Unary vector operations resulting in a vector
54          initialize_vector(v1);
55          v2 = -v1;
56          std::cout << "- v1 = " << v2 << std::endl;
57          v2 = ublas::conj(v1);
58          std::cout << "conj (v1) = " << v2 << std::endl;
59
60          // Binary vector operations resulting in a vector
61          initialize_vector(v1);
62          initialize_vector(v2);
63          v3 = v1 + v2;
64          std::cout << "v1 + v2 = " << v3 << std::endl;
65
66          v3 = v1 - v2;
67          std::cout << "v1 - v2 = " << v3 << std::endl;
68
69          // Scaling a vector
70          t = value_type(N);
71          initialize_vector(v1);
72          v2 = value_type(1.) * v1;
73          std::cout << "1. * v1 = " << v2 << std::endl;
74          //            v2 = t * v1;
75          std::cout << "N * v1 = " << v2 << std::endl;
76          initialize_vector(v1);
77          //            v2 = v1 * value_type (1.);
78          std::cout << "v1 * 1. = " << v2 << std::endl;
79          //            v2 = v1 * t;
80          std::cout << "v1 * N = " << v2 << std::endl;
81
82          // Some assignments
83          initialize_vector(v1);
84          initialize_vector(v2);
85          v2 += v1;
86          std::cout << "v2 += v1 = " << v2 << std::endl;
87          v2 -= v1;
88          std::cout << "v2 -= v1 = " << v2 << std::endl;
89          v2 = v2 + v1;
90          std::cout << "v2 = v2 + v1 = " << v2 << std::endl;
91          v2 = v2 - v1;
92          std::cout << "v2 = v2 - v1 = " << v2 << std::endl;
93          v1 *= value_type(1.);
94          std::cout << "v1 *= 1. = " << v1 << std::endl;
95          v1 *= t;
96          std::cout << "v1 *= N = " << v1 << std::endl;
97
98          // Unary vector operations resulting in a scalar
99          initialize_vector(v1);
100          t = ublas::sum(v1);
101          std::cout << "sum (v1) = " << t << std::endl;
102          n = ublas::norm_1(v1);
103          std::cout << "norm_1 (v1) = " << n << std::endl;
104          n = ublas::norm_2(v1);
105          std::cout << "norm_2 (v1) = " << n << std::endl;
106          n = ublas::norm_inf(v1);
107          std::cout << "norm_inf (v1) = " << n << std::endl;
108
109          i = ublas::index_norm_inf(v1);
110          std::cout << "index_norm_inf (v1) = " << i << std::endl;
111
112          // Binary vector operations resulting in a scalar
113          initialize_vector(v1);
114          initialize_vector(v2);
115          t = ublas::inner_prod(v1, v2);
116          std::cout << "inner_prod (v1, v2) = " << t << std::endl;
117       }
118    }
119    void operator()() const
120    {
121       {
122          V v1(N), v2(N), v3(N);
123          test_with(v1, v2, v3);
124
125 #ifdef USE_RANGE
126          ublas::vector_range<V> vr1(v1, ublas::range(0, N)),
127              vr2(v2, ublas::range(0, N)),
128              vr3(v3, ublas::range(0, N));
129          test_with(vr1, vr2, vr3);
130 #endif
131
132 #ifdef USE_SLICE
133          ublas::vector_slice<V> vs1(v1, ublas::slice(0, 1, N)),
134              vs2(v2, ublas::slice(0, 1, N)),
135              vs3(v3, ublas::slice(0, 1, N));
136          test_with(vs1, vs2, vs3);
137 #endif
138       }
139    }
140 };
141
142 // Test vector
143 void test_vector()
144 {
145    std::cout << "test_vector" << std::endl;
146
147 #ifdef USE_BOUNDED_ARRAY
148 #ifdef USE_FLOAT
149    std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl;
150    test_my_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3> >, 3>()();
151 #endif
152
153 #ifdef USE_DOUBLE
154    std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
155    test_my_vector<ublas::vector<boost::numeric::interval<double>, ublas::bounded_array<boost::numeric::interval<double>, 3> >, 3>()();
156 #endif
157 #endif
158
159 #ifdef USE_UNBOUNDED_ARRAY
160 #ifdef USE_FLOAT
161    std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl;
162    test_my_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >, 3>()();
163 #endif
164
165 #ifdef USE_DOUBLE
166    std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
167    test_my_vector<ublas::vector<boost::numeric::interval<double>, ublas::unbounded_array<boost::numeric::interval<double> > >, 3>()();
168 #endif
169 #endif
170
171 #ifdef USE_STD_VECTOR
172 #ifdef USE_FLOAT
173    std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl;
174    test_my_vector<ublas::vector<boost::numeric::interval<mp_test_type>, std::vector<boost::numeric::interval<mp_test_type> > >, 3>()();
175 #endif
176
177 #ifdef USE_DOUBLE
178    std::cout << "boost::numeric::interval<double>, std::vector" << std::endl;
179    test_my_vector<ublas::vector<boost::numeric::interval<double>, std::vector<boost::numeric::interval<double> > >, 3>()();
180 #endif
181 #endif
182 }