Add more structure constructor tests.
[piglit/hramrach.git] / tests / glean / stats.h
blobd9eb019f6906ae3f4b056af381ed353d3e6ac94c
1 // BEGIN_COPYRIGHT
2 //
3 // Copyright (C) 1999 Allen Akin All Rights Reserved.
4 //
5 // Permission is hereby granted, free of charge, to any person
6 // obtaining a copy of this software and associated documentation
7 // files (the "Software"), to deal in the Software without
8 // restriction, including without limitation the rights to use,
9 // copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following
12 // conditions:
13 //
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the
16 // Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
26 //
27 // END_COPYRIGHT
32 // stats.h: simple statistics-gathering utilities for glean
34 // These are rather simplistic. For more robust implementations, consider
35 // using Numerical Recipes.
37 #ifndef __stats_h__
38 #define __stats_h__
40 #include <vector>
42 #ifdef __WIN__
43 using namespace std;
44 #endif
46 #if defined( __WIN__ )
48 #undef min
49 #undef max
51 #endif
53 namespace GLEAN {
55 class BasicStats {
56 int _n;
57 double _min;
58 double _max;
59 double _sum;
60 double _sum2;
61 public:
62 void init();
63 inline int n() const {return _n;}
64 inline double min() const {return _min;}
65 inline double max() const {return _max;}
66 inline double sum() const {return _sum;}
67 inline double sum2() const {return _sum2;}
68 double mean() const;
69 double variance() const;
70 double deviation() const;
71 inline void sample(double d) {
72 ++_n;
73 if (d < _min)
74 _min = d;
75 if (d > _max)
76 _max = d;
77 _sum += d;
78 _sum2 += d*d;
81 BasicStats() {init();}
82 template<class T> BasicStats(std::vector<T>& v) {
83 init();
84 for (typename std::vector<T>::const_iterator p = v.begin(); p < v.end(); ++p)
85 sample(*p);
87 }; // class BasicStats
89 } // namespace GLEAN
91 #endif // __stats_h__