Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/numeric/ublas/test/test71.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 6.3 KB
Line 
1//  Copyright (c) 2000-2002
2//  Joerg Walter, Mathias Koch
3//
4//  Permission to use, copy, modify, distribute and sell this software
5//  and its documentation for any purpose is hereby granted without fee,
6//  provided that the above copyright notice appear in all copies and
7//  that both that copyright notice and this permission notice appear
8//  in supporting documentation.  The authors make no representations
9//  about the suitability of this software for any purpose.
10//  It is provided "as is" without express or implied warranty.
11//
12//  The authors gratefully acknowledge the support of
13//  GeNeSys mbH & Co. KG in producing this work.
14//
15
16#include "test7.hpp"
17
18// Test vector expression templates
19template<class V, int N>
20struct test_my_vector {
21    typedef typename V::value_type value_type;
22    typedef typename V::size_type size_type;
23    typedef typename ublas::type_traits<value_type>::real_type real_type;
24
25    template<class VP>
26    void test_with (VP &v1, VP &v2, VP &v3) const {
27        {
28            value_type t;
29            size_type i;
30            real_type n;
31
32            // Copy and swap
33            initialize_vector (v1);
34            initialize_vector (v2);
35            v1 = v2;
36            std::cout << "v1 = v2 = " << v1 << std::endl;
37            v1.assign_temporary (v2);
38            std::cout << "v1.assign_temporary (v2) = " << v1 << std::endl;
39            v1.swap (v2);
40            std::cout << "v1.swap (v2) = " << v1 << " " << v2 << std::endl;
41
42            // Zero assignment
43            v1 = ublas::zero_vector<> (v1.size ());
44            std::cout << "v1.zero_vector = " << v1 << std::endl;
45            v1 = v2;
46
47            // Unary vector operations resulting in a vector
48            initialize_vector (v1);
49            v2 = - v1;
50            std::cout << "- v1 = " << v2 << std::endl;
51            v2 = ublas::conj (v1);
52            std::cout << "conj (v1) = " << v2 << std::endl;
53
54            // Binary vector operations resulting in a vector
55            initialize_vector (v1);
56            initialize_vector (v2);
57            v3 = v1 + v2;
58            std::cout << "v1 + v2 = " << v3 << std::endl;
59
60            v3 = v1 - v2;
61            std::cout << "v1 - v2 = " << v3 << std::endl;
62
63            // Scaling a vector
64            t = value_type (N);
65            initialize_vector (v1);
66            v2 = value_type (1.) * v1;
67            std::cout << "1. * v1 = " << v2 << std::endl;
68//            v2 = t * v1;
69            std::cout << "N * v1 = " << v2 << std::endl;
70            initialize_vector (v1);
71//            v2 = v1 * value_type (1.);
72            std::cout << "v1 * 1. = " << v2 << std::endl;
73//            v2 = v1 * t;
74            std::cout << "v1 * N = " << v2 << std::endl;
75
76            // Some assignments
77            initialize_vector (v1);
78            initialize_vector (v2);
79            v2 += v1;
80            std::cout << "v2 += v1 = " << v2 << std::endl;
81            v2 -= v1;
82            std::cout << "v2 -= v1 = " << v2 << std::endl;
83            v2 = v2 + v1;
84            std::cout << "v2 = v2 + v1 = " << v2 << std::endl;
85            v2 = v2 - v1;
86            std::cout << "v2 = v2 - v1 = " << v2 << std::endl;
87            v1 *= value_type (1.);
88            std::cout << "v1 *= 1. = " << v1 << std::endl;
89            v1 *= t;
90            std::cout << "v1 *= N = " << v1 << std::endl;
91
92            // Unary vector operations resulting in a scalar
93            initialize_vector (v1);
94            t = ublas::sum (v1);
95            std::cout << "sum (v1) = " << t << std::endl;
96            n = ublas::norm_1 (v1);
97            std::cout << "norm_1 (v1) = " << n << std::endl;
98            n = ublas::norm_2 (v1);
99            std::cout << "norm_2 (v1) = " << n << std::endl;
100            n = ublas::norm_inf (v1);
101            std::cout << "norm_inf (v1) = " << n << std::endl;
102
103            i = ublas::index_norm_inf (v1);
104            std::cout << "index_norm_inf (v1) = " << i << std::endl;
105
106            // Binary vector operations resulting in a scalar
107            initialize_vector (v1);
108            initialize_vector (v2);
109            t = ublas::inner_prod (v1, v2);
110            std::cout << "inner_prod (v1, v2) = " << t << std::endl;
111        }
112    }
113    void operator () () const {
114        {
115            V v1 (N), v2 (N), v3 (N);
116            test_with (v1, v2, v3);
117
118#ifdef USE_RANGE
119            ublas::vector_range<V> vr1 (v1, ublas::range (0, N)),
120                                   vr2 (v2, ublas::range (0, N)),
121                                   vr3 (v3, ublas::range (0, N));
122            test_with (vr1, vr2, vr3);
123#endif
124
125#ifdef USE_SLICE
126            ublas::vector_slice<V> vs1 (v1, ublas::slice (0, 1, N)),
127                                   vs2 (v2, ublas::slice (0, 1, N)),
128                                   vs3 (v3, ublas::slice (0, 1, N));
129            test_with (vs1, vs2, vs3);
130#endif
131        }
132    }
133};
134
135// Test vector
136void test_vector () {
137    std::cout << "test_vector" << std::endl;
138
139#ifdef USE_BOUNDED_ARRAY
140#ifdef USE_FLOAT
141    std::cout << "boost::numeric::interval<float>, bounded_array" << std::endl;
142    test_my_vector<ublas::vector<boost::numeric::interval<float>, ublas::bounded_array<boost::numeric::interval<float>, 3> >, 3 > () ();
143#endif
144
145#ifdef USE_DOUBLE
146    std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
147    test_my_vector<ublas::vector<boost::numeric::interval<double>, ublas::bounded_array<boost::numeric::interval<double>, 3> >, 3 > () ();
148#endif
149#endif
150
151#ifdef USE_UNBOUNDED_ARRAY
152#ifdef USE_FLOAT
153    std::cout << "boost::numeric::interval<float>, unbounded_array" << std::endl;
154    test_my_vector<ublas::vector<boost::numeric::interval<float>, ublas::unbounded_array<boost::numeric::interval<float> > >, 3 > () ();
155#endif
156
157#ifdef USE_DOUBLE
158    std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
159    test_my_vector<ublas::vector<boost::numeric::interval<double>, ublas::unbounded_array<boost::numeric::interval<double> > >, 3 > () ();
160#endif
161#endif
162
163#ifdef USE_STD_VECTOR
164#ifdef USE_FLOAT
165    std::cout << "boost::numeric::interval<float>, std::vector" << std::endl;
166    test_my_vector<ublas::vector<boost::numeric::interval<float>, std::vector<boost::numeric::interval<float> > >, 3 > () ();
167#endif
168
169#ifdef USE_DOUBLE
170    std::cout << "boost::numeric::interval<double>, std::vector" << std::endl;
171    test_my_vector<ublas::vector<boost::numeric::interval<double>, std::vector<boost::numeric::interval<double> > >, 3 > () ();
172#endif
173#endif
174}
Note: See TracBrowser for help on using the repository browser.