Mercurial > hg > qm-dsp
comparison maths/MathUtilities.cpp @ 414:7e8d1f26b098
Fix compiler warnings with -Wall -Wextra
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Mon, 28 Sep 2015 12:33:17 +0100 |
parents | a694700f71d8 |
children | d583feeeed7a |
comparison
equal
deleted
inserted
replaced
413:ec7318974497 | 414:7e8d1f26b098 |
---|---|
36 ValOut = mod( ang + M_PI, -2 * M_PI ) + M_PI; | 36 ValOut = mod( ang + M_PI, -2 * M_PI ) + M_PI; |
37 | 37 |
38 return ValOut; | 38 return ValOut; |
39 } | 39 } |
40 | 40 |
41 void MathUtilities::getAlphaNorm(const double *data, unsigned int len, unsigned int alpha, double* ANorm) | 41 void MathUtilities::getAlphaNorm(const double *data, int len, int alpha, double* ANorm) |
42 { | 42 { |
43 unsigned int i; | 43 int i; |
44 double temp = 0.0; | 44 double temp = 0.0; |
45 double a=0.0; | 45 double a=0.0; |
46 | 46 |
47 for( i = 0; i < len; i++) | 47 for( i = 0; i < len; i++) |
48 { | 48 { |
54 a = ::pow( a, ( 1.0 / (double) alpha ) ); | 54 a = ::pow( a, ( 1.0 / (double) alpha ) ); |
55 | 55 |
56 *ANorm = a; | 56 *ANorm = a; |
57 } | 57 } |
58 | 58 |
59 double MathUtilities::getAlphaNorm( const std::vector <double> &data, unsigned int alpha ) | 59 double MathUtilities::getAlphaNorm( const std::vector <double> &data, int alpha ) |
60 { | 60 { |
61 unsigned int i; | 61 int i; |
62 unsigned int len = data.size(); | 62 int len = data.size(); |
63 double temp = 0.0; | 63 double temp = 0.0; |
64 double a=0.0; | 64 double a=0.0; |
65 | 65 |
66 for( i = 0; i < len; i++) | 66 for( i = 0; i < len; i++) |
67 { | 67 { |
82 } else { | 82 } else { |
83 return floor(x + 0.5); | 83 return floor(x + 0.5); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 double MathUtilities::median(const double *src, unsigned int len) | 87 double MathUtilities::median(const double *src, int len) |
88 { | 88 { |
89 if (len == 0) return 0; | 89 if (len == 0) return 0; |
90 | 90 |
91 std::vector<double> scratch; | 91 std::vector<double> scratch; |
92 for (int i = 0; i < len; ++i) scratch.push_back(src[i]); | 92 for (int i = 0; i < len; ++i) scratch.push_back(src[i]); |
98 } else { | 98 } else { |
99 return scratch[middle]; | 99 return scratch[middle]; |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 double MathUtilities::sum(const double *src, unsigned int len) | 103 double MathUtilities::sum(const double *src, int len) |
104 { | 104 { |
105 unsigned int i ; | 105 int i ; |
106 double retVal =0.0; | 106 double retVal =0.0; |
107 | 107 |
108 for( i = 0; i < len; i++) | 108 for( i = 0; i < len; i++) |
109 { | 109 { |
110 retVal += src[ i ]; | 110 retVal += src[ i ]; |
111 } | 111 } |
112 | 112 |
113 return retVal; | 113 return retVal; |
114 } | 114 } |
115 | 115 |
116 double MathUtilities::mean(const double *src, unsigned int len) | 116 double MathUtilities::mean(const double *src, int len) |
117 { | 117 { |
118 double retVal =0.0; | 118 double retVal =0.0; |
119 | 119 |
120 if (len == 0) return 0; | 120 if (len == 0) return 0; |
121 | 121 |
125 | 125 |
126 return retVal; | 126 return retVal; |
127 } | 127 } |
128 | 128 |
129 double MathUtilities::mean(const std::vector<double> &src, | 129 double MathUtilities::mean(const std::vector<double> &src, |
130 unsigned int start, | 130 int start, |
131 unsigned int count) | 131 int count) |
132 { | 132 { |
133 double sum = 0.; | 133 double sum = 0.; |
134 | 134 |
135 if (count == 0) return 0; | 135 if (count == 0) return 0; |
136 | 136 |
140 } | 140 } |
141 | 141 |
142 return sum / count; | 142 return sum / count; |
143 } | 143 } |
144 | 144 |
145 void MathUtilities::getFrameMinMax(const double *data, unsigned int len, double *min, double *max) | 145 void MathUtilities::getFrameMinMax(const double *data, int len, double *min, double *max) |
146 { | 146 { |
147 unsigned int i; | 147 int i; |
148 double temp = 0.0; | 148 double temp = 0.0; |
149 | 149 |
150 if (len == 0) { | 150 if (len == 0) { |
151 *min = *max = 0; | 151 *min = *max = 0; |
152 return; | 152 return; |
169 } | 169 } |
170 | 170 |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 int MathUtilities::getMax( double* pData, unsigned int Length, double* pMax ) | 174 int MathUtilities::getMax( double* pData, int Length, double* pMax ) |
175 { | 175 { |
176 unsigned int index = 0; | 176 int index = 0; |
177 unsigned int i; | 177 int i; |
178 double temp = 0.0; | 178 double temp = 0.0; |
179 | 179 |
180 double max = pData[0]; | 180 double max = pData[0]; |
181 | 181 |
182 for( i = 0; i < Length; i++) | 182 for( i = 0; i < Length; i++) |
197 return index; | 197 return index; |
198 } | 198 } |
199 | 199 |
200 int MathUtilities::getMax( const std::vector<double> & data, double* pMax ) | 200 int MathUtilities::getMax( const std::vector<double> & data, double* pMax ) |
201 { | 201 { |
202 unsigned int index = 0; | 202 int index = 0; |
203 unsigned int i; | 203 int i; |
204 double temp = 0.0; | 204 double temp = 0.0; |
205 | 205 |
206 double max = data[0]; | 206 double max = data[0]; |
207 | 207 |
208 for( i = 0; i < data.size(); i++) | 208 for( i = 0; i < int(data.size()); i++) |
209 { | 209 { |
210 temp = data[ i ]; | 210 temp = data[ i ]; |
211 | 211 |
212 if( temp > max ) | 212 if( temp > max ) |
213 { | 213 { |