Changeset 642 for trunk/psLib/src/math/psStats.c
- Timestamp:
- May 11, 2004, 2:40:23 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psStats.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psStats.c
r563 r642 4 4 #include <stdarg.h> 5 5 #include "pslib.h" 6 //#include "psMemory.h" 7 //#include "psTrace.h" 8 //#include "psString.h" 9 //#include "psError.h" 10 #include "psArray.h" 6 #include "psMemory.h" 7 #include "psTrace.h" 8 #include "psString.h" 9 #include "psError.h" 10 /****************************************************************************** 11 //#include "psArray.h" 12 *****************************************************************************/ 11 13 #include "psStats.h" 12 14 … … 65 67 numBins = 1 + ((upper - lower) / size); 66 68 newHist = (psHistogram *) psAlloc(sizeof(psHistogram)); 67 newHist->lower = ps FloatArrayAlloc(numBins);68 newHist->upper = ps FloatArrayAlloc(numBins);69 newHist->nums = psIntArrayAlloc(numBins);69 newHist->lower = psVectorAlloc(numBins, PS_TYPE_FLOAT); 70 newHist->upper = psVectorAlloc(numBins, PS_TYPE_FLOAT); 71 newHist->nums = psVectorAlloc(numBins, PS_TYPE_INT); 70 72 newHist->minVal = lower; 71 73 newHist->maxVal = upper; … … 76 78 } 77 79 78 psHistogram *psHistogramAllocGeneric(const ps FloatArray*restrict lower,79 const ps FloatArray*restrict upper,80 psHistogram *psHistogramAllocGeneric(const psVector *restrict lower, 81 const psVector *restrict upper, 80 82 float minVal, 81 83 float maxVal) … … 90 92 numBins = lower->n; 91 93 newHist = (psHistogram *) psAlloc(sizeof(psHistogram)); 92 newHist->lower = ps FloatArrayAlloc(numBins);93 newHist->upper = ps FloatArrayAlloc(numBins);94 newHist->lower = psVectorAlloc(numBins, PS_TYPE_FLOAT); 95 newHist->upper = psVectorAlloc(numBins, PS_TYPE_FLOAT); 94 96 for (i=0;i<numBins;i++) { 95 newHist->lower-> arr[i] = lower->arr[i];96 newHist->upper-> arr[i] = upper->arr[i];97 } 98 newHist->nums = ps IntArrayAlloc(numBins);97 newHist->lower->vec.vecF[i] = lower->vec.vecF[i]; 98 newHist->upper->vec.vecF[i] = upper->vec.vecF[i]; 99 } 100 newHist->nums = psVectorAlloc(numBins, PS_TYPE_INT); 99 101 newHist->minVal = minVal; 100 102 newHist->maxVal = maxVal; … … 124 126 myHist->maxNum 125 127 *****************************************************************************/ 126 psHistogram *psGetArrayHistogram( psHistogram *restrict myHist,127 const psFloatArray *restrict myArray)128 psHistogram *psGetArrayHistogram(psHistogram *restrict myHist, 129 const psVector *restrict myVector) 128 130 { 129 131 int i = 0; … … 132 134 133 135 binSize = (myHist->maxVal - myHist->minVal) / (float) myHist->nums->n; 134 for (i=0;i<my Array->n;i++) {135 if (my Array->arr[i] < myHist->minVal) {136 for (i=0;i<myVector->n;i++) { 137 if (myVector->vec.vecF[i] < myHist->minVal) { 136 138 myHist->minNum++; 137 } else if (my Array->arr[i] > myHist->maxVal) {139 } else if (myVector->vec.vecF[i] > myHist->maxVal) { 138 140 myHist->maxNum++; 139 141 } else { 140 binNum = (int) ((my Array->arr[i] - myHist->minVal) / binSize);141 if ((my Array->arr[i] >= myHist->lower->arr[i]) &&142 (my Array->arr[i] <= myHist->upper->arr[i])) {143 myHist->nums-> arr[i]++;142 binNum = (int) ((myVector->vec.vecF[i] - myHist->minVal) / binSize); 143 if ((myVector->vec.vecF[i] >= myHist->lower->vec.vecF[i]) && 144 (myVector->vec.vecF[i] <= myHist->upper->vec.vecF[i])) { 145 myHist->nums->vec.vecI[i]++; 144 146 } else { 145 147 psError(__func__, "data value was not within the bounds of the bin it should habe been in."); … … 153 155 MISC STATISTICAL FUNCTIONS 154 156 *****************************************************************************/ 155 float p_psArraySampleMean(const ps FloatArray *restrict myArray,156 const ps IntArray *restrict maskArray,157 float p_psArraySampleMean(const psVector *restrict myVector, 158 const psVector *restrict maskVector, 157 159 unsigned int maskVal) 158 160 { … … 160 162 float mean = 0.0; 161 163 162 if (mask Array!= NULL) {163 for (i=0;i<my Array->n;i++) {164 if (!(maskVal & mask Array->arr[i])) {165 mean+= mask Array->arr[i];164 if (maskVector != NULL) { 165 for (i=0;i<myVector->n;i++) { 166 if (!(maskVal & maskVector->vec.vecI[i])) { 167 mean+= maskVector->vec.vecI[i]; 166 168 } 167 169 } 168 170 } else { 169 for (i=0;i<my Array->n;i++) {170 mean+= mask Array->arr[i];171 for (i=0;i<myVector->n;i++) { 172 mean+= maskVector->vec.vecI[i]; 171 173 } 172 174 } … … 174 176 } 175 177 176 float p_psArrayMax(const ps FloatArray *restrict myArray,177 const ps IntArray *restrict maskArray,178 float p_psArrayMax(const psVector *restrict myVector, 179 const psVector *restrict maskVector, 178 180 unsigned int maskVal) 179 181 { … … 181 183 float max = -1e99; 182 184 183 if (mask Array!= NULL) {184 for (i=0;i<my Array->n;i++) {185 if (!(maskVal & mask Array->arr[i])) {186 if (my Array->arr[i] > max) {187 max = mask Array->arr[i];185 if (maskVector != NULL) { 186 for (i=0;i<myVector->n;i++) { 187 if (!(maskVal & maskVector->vec.vecI[i])) { 188 if (myVector->vec.vecF[i] > max) { 189 max = maskVector->vec.vecI[i]; 188 190 } 189 191 } 190 192 } 191 193 } else { 192 for (i=0;i<my Array->n;i++) {193 if (my Array->arr[i] > max) {194 max = mask Array->arr[i];194 for (i=0;i<myVector->n;i++) { 195 if (myVector->vec.vecF[i] > max) { 196 max = maskVector->vec.vecI[i]; 195 197 } 196 198 } … … 199 201 } 200 202 201 float p_psArrayMin(const ps FloatArray *restrict myArray,202 const ps IntArray *restrict maskArray,203 float p_psArrayMin(const psVector *restrict myVector, /* FLOATS */ 204 const psVector *restrict maskVector, /* INTS */ 203 205 unsigned int maskVal) 204 206 { … … 206 208 float min = 1e99; 207 209 208 if (mask Array!= NULL) {209 for (i=0;i<my Array->n;i++) {210 if (!(maskVal & mask Array->arr[i])) {211 if (my Array->arr[i] < min) {212 min = mask Array->arr[i];210 if (maskVector != NULL) { 211 for (i=0;i<myVector->n;i++) { 212 if (!(maskVal & maskVector->vec.vecI[i])) { 213 if (myVector->vec.vecF[i] < min) { 214 min = maskVector->vec.vecI[i]; 213 215 } 214 216 } 215 217 } 216 218 } else { 217 for (i=0;i<my Array->n;i++) {218 if (my Array->arr[i] < min) {219 min = mask Array->arr[i];219 for (i=0;i<myVector->n;i++) { 220 if (myVector->vec.vecF[i] < min) { 221 min = maskVector->vec.vecI[i]; 220 222 } 221 223 } … … 224 226 } 225 227 226 int p_psArrayNValues(const ps FloatArray *restrict myArray,227 const ps IntArray *restrict maskArray,228 int p_psArrayNValues(const psVector *restrict myVector, // float 229 const psVector *restrict maskVector, // ints 228 230 unsigned int maskVal) 229 231 { … … 231 233 int numData = 0; 232 234 233 if (mask Array!= NULL) {234 for (i=0;i<my Array->n;i++) {235 if (!(maskVal & mask Array->arr[i])) {235 if (maskVector != NULL) { 236 for (i=0;i<myVector->n;i++) { 237 if (!(maskVal & maskVector->vec.vecI[i])) { 236 238 numData++; 237 239 } 238 240 } 239 241 } else { 240 numData = my Array->n;242 numData = myVector->n; 241 243 } 242 244 return(numData); 243 245 } 244 246 245 psStats *psArrayStats(const ps FloatArray *restrict myArray,246 const ps IntArray *restrict maskArray,247 psStats *psArrayStats(const psVector *restrict myVector, // FLOAT 248 const psVector *restrict maskVector, // INT 247 249 unsigned int maskVal, 248 250 psStats *stats) … … 251 253 252 254 newStruct = psStatsAlloc(stats->options); 253 if (my Array== NULL) {255 if (myVector == NULL) { 254 256 psError(__func__, 255 "Input data array (my Array) was NULL.");256 } 257 258 if ((mask Array!= NULL) &&259 (my Array->n != maskArray->n)) {260 psError(__func__, " Array data and arraymask are of different sizes.");257 "Input data array (myVector) was NULL."); 258 } 259 260 if ((maskVector != NULL) && 261 (myVector->n != maskVector->n)) { 262 psError(__func__, "Vector data and vector mask are of different sizes."); 261 263 } 262 264 263 265 switch (stats->options) { 264 266 case PS_STAT_SAMPLE_MEAN: 265 newStruct->max = p_psArraySampleMean(my Array, maskArray, maskVal);267 newStruct->max = p_psArraySampleMean(myVector, maskVector, maskVal); 266 268 break; 267 269 case PS_STAT_SAMPLE_MEDIAN: … … 317 319 break; 318 320 case PS_STAT_MAX: 319 newStruct->max = p_psArrayMax(my Array, maskArray, maskVal);321 newStruct->max = p_psArrayMax(myVector, maskVector, maskVal); 320 322 break; 321 323 case PS_STAT_MIN: 322 newStruct->min = p_psArrayMin(my Array, maskArray, maskVal);324 newStruct->min = p_psArrayMin(myVector, maskVector, maskVal); 323 325 break; 324 326 case PS_STAT_NVALUES: 325 newStruct->nValues = p_psArrayNValues(my Array, maskArray, maskVal);327 newStruct->nValues = p_psArrayNValues(myVector, maskVector, maskVal); 326 328 break; 327 329 default:
Note:
See TracChangeset
for help on using the changeset viewer.
