Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/numeric/ublas/bench2/bench2.hpp @ 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: 4.6 KB
Line 
1//
2//  Copyright (c) 2000-2002
3//  Joerg Walter, Mathias Koch
4//
5//  Permission to use, copy, modify, distribute and sell this software
6//  and its documentation for any purpose is hereby granted without fee,
7//  provided that the above copyright notice appear in all copies and
8//  that both that copyright notice and this permission notice appear
9//  in supporting documentation.  The authors make no representations
10//  about the suitability of this software for any purpose.
11//  It is provided "as is" without express or implied warranty.
12//
13//  The authors gratefully acknowledge the support of
14//  GeNeSys mbH & Co. KG in producing this work.
15//
16
17#ifndef BENCH2_H
18#define BENCH2_H
19
20#include <iostream>
21#include <string>
22#include <valarray>
23
24#include <boost/numeric/ublas/vector.hpp>
25#include <boost/numeric/ublas/vector_sparse.hpp>
26#include <boost/numeric/ublas/matrix.hpp>
27#include <boost/numeric/ublas/matrix_sparse.hpp>
28
29#include <boost/timer.hpp>
30
31namespace ublas = boost::numeric::ublas;
32
33void header (std::string text);
34
35template<class T>
36struct footer {
37    void operator () (int multiplies, int plus, int runs, double elapsed) {
38        std::cout << "elapsed: " << elapsed << " s, "
39                  << (multiplies * ublas::type_traits<T>::multiplies_complexity +
40                      plus * ublas::type_traits<T>::plus_complexity) * runs /
41                     (1024 * 1024 * elapsed) << " Mflops" << std::endl;
42    }
43};
44
45template<class T, int N>
46struct c_vector_traits {
47    typedef T type [N];
48};
49template<class T, int N, int M>
50struct c_matrix_traits {
51    typedef T type [N] [M];
52};
53
54template<class T, int N>
55struct initialize_c_vector  {
56    void operator () (typename c_vector_traits<T, N>::type &v) {
57        for (int i = 0; i < N; ++ i)
58            v [i] = std::rand () * 1.f;
59//            v [i] = 0.f;
60        }
61};
62template<class V>
63BOOST_UBLAS_INLINE
64void initialize_vector (V &v) {
65    int size = v.size ();
66    for (int i = 0; i < size; ++ i)
67        v [i] = std::rand () * 1.f;
68//        v [i] = 0.f;
69}
70
71template<class T, int N, int M>
72struct initialize_c_matrix  {
73    void operator () (typename c_matrix_traits<T, N, M>::type &m) {
74        for (int i = 0; i < N; ++ i)
75            for (int j = 0; j < M; ++ j)
76                m [i] [j] = std::rand () * 1.f;
77//                m [i] [j] = 0.f;
78    }
79};
80template<class M>
81BOOST_UBLAS_INLINE
82void initialize_matrix (M &m, ublas::row_major_tag) {
83    int size1 = m.size1 ();
84    int size2 = m.size2 ();
85    for (int i = 0; i < size1; ++ i)
86        for (int j = 0; j < size2; ++ j)
87            m (i, j) = std::rand () * 1.f;
88//            m (i, j) = 0.f;
89}
90template<class M>
91BOOST_UBLAS_INLINE
92void initialize_matrix (M &m, ublas::column_major_tag) {
93    int size1 = m.size1 ();
94    int size2 = m.size2 ();
95    for (int j = 0; j < size2; ++ j)
96        for (int i = 0; i < size1; ++ i)
97            m (i, j) = std::rand () * 1.f;
98//            m (i, j) = 0.f;
99}
100template<class M>
101BOOST_UBLAS_INLINE
102void initialize_matrix (M &m) {
103    typedef typename M::orientation_category orientation_category;
104    initialize_matrix (m, orientation_category ());
105}
106
107template<class T>
108BOOST_UBLAS_INLINE
109void sink_scalar (const T &s) {
110    static T g_s = s;
111}
112
113template<class T, int N>
114struct sink_c_vector {
115    void operator () (const typename c_vector_traits<T, N>::type &v) {
116        static typename c_vector_traits<T, N>::type g_v;
117        for (int i = 0; i < N; ++ i)
118            g_v [i] = v [i];
119    }
120};
121template<class V>
122BOOST_UBLAS_INLINE
123void sink_vector (const V &v) {
124    static V g_v (v);
125}
126
127template<class T, int N, int M>
128struct sink_c_matrix {
129    void operator () (const typename c_matrix_traits<T, N, M>::type &m) {
130    static typename c_matrix_traits<T, N, M>::type g_m;
131    for (int i = 0; i < N; ++ i)
132        for (int j = 0; j < M; ++ j)
133            g_m [i] [j] = m [i] [j];
134    }
135};
136template<class M>
137BOOST_UBLAS_INLINE
138void sink_matrix (const M &m) {
139    static M g_m (m);
140}
141
142template<class T>
143struct peak {
144    void operator () (int runs);
145};
146
147template<class T, int N>
148struct bench_1 {
149    void operator () (int runs);
150};
151
152template<class T, int N>
153struct bench_2 {
154    void operator () (int runs);
155};
156
157template<class T, int N>
158struct bench_3 {
159    void operator () (int runs);
160};
161
162struct safe_tag {};
163struct fast_tag {};
164
165// #define USE_FLOAT
166#define USE_DOUBLE
167// #define USE_STD_COMPLEX
168
169#define USE_MAP_ARRAY
170// #define USE_STD_MAP
171// #define USE_STD_VALARRAY
172
173#define USE_MAPPED_VECTOR
174#define USE_COMPRESSED_VECTOR
175#define USE_COORDINATE_VECTOR
176
177#define USE_MAPPED_MATRIX
178// #define USE_SPARSE_VECTOR_OF_SPARSE_VECTOR
179#define USE_COMPRESSED_MATRIX
180#define USE_COORDINATE_MATRIX
181
182#endif
Note: See TracBrowser for help on using the repository browser.