Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
stat-util.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #ifndef IMPALA_UTIL_STAT_UTIL_H
17 #define IMPALA_UTIL_STAT_UTIL_H
18 
19 #include <math.h>
20 
21 namespace impala {
22 
23 class StatUtil {
24  public:
26  template <typename T>
27  static void ComputeMeanStddev(const T* values, int N, double* mean, double* stddev) {
28  *mean = 0;
29  *stddev = 0;
30 
31  for (int i = 0; i < N; ++i) {
32  *mean += values[i];
33  }
34  *mean /= N;
35 
36  for (int i = 0; i < N; ++i) {
37  double d = values[i] - *mean;
38  *stddev += d*d;
39  }
40 
41  *stddev /= N;
42  *stddev = sqrt(*stddev);
43  }
44 };
45 
46 }
47 
48 #endif
static void ComputeMeanStddev(const T *values, int N, double *mean, double *stddev)
Computes mean and standard deviation.
Definition: stat-util.h:27