IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 11, 2004, 2:40:23 PM (22 years ago)
Author:
gusciora
Message:

I removed psImage.o temporarily (since it was not compiling).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psStats.c

    r563 r642  
    44#include <stdarg.h>
    55#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 *****************************************************************************/
    1113#include "psStats.h"
    1214
     
    6567    numBins = 1 + ((upper - lower) / size);
    6668    newHist = (psHistogram *) psAlloc(sizeof(psHistogram));
    67     newHist->lower = psFloatArrayAlloc(numBins);
    68     newHist->upper = psFloatArrayAlloc(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);
    7072    newHist->minVal = lower;
    7173    newHist->maxVal = upper;
     
    7678}
    7779
    78 psHistogram *psHistogramAllocGeneric(const psFloatArray *restrict lower,
    79                                      const psFloatArray *restrict upper,
     80psHistogram *psHistogramAllocGeneric(const psVector *restrict lower,
     81                                     const psVector *restrict upper,
    8082                                     float minVal,
    8183                                     float maxVal)
     
    9092    numBins = lower->n;
    9193    newHist = (psHistogram *) psAlloc(sizeof(psHistogram));
    92     newHist->lower = psFloatArrayAlloc(numBins);
    93     newHist->upper = psFloatArrayAlloc(numBins);
     94    newHist->lower = psVectorAlloc(numBins, PS_TYPE_FLOAT);
     95    newHist->upper = psVectorAlloc(numBins, PS_TYPE_FLOAT);
    9496    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 = psIntArrayAlloc(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);
    99101    newHist->minVal = minVal;
    100102    newHist->maxVal = maxVal;
     
    124126        myHist->maxNum
    125127 *****************************************************************************/
    126 psHistogram *psGetArrayHistogram(       psHistogram *restrict myHist,
    127                                         const psFloatArray *restrict myArray)
     128psHistogram *psGetArrayHistogram(psHistogram *restrict myHist,
     129                                 const psVector *restrict myVector)
    128130{
    129131    int i = 0;
     
    132134
    133135    binSize = (myHist->maxVal - myHist->minVal) / (float) myHist->nums->n;
    134     for (i=0;i<myArray->n;i++) {
    135         if (myArray->arr[i] < myHist->minVal) {
     136    for (i=0;i<myVector->n;i++) {
     137        if (myVector->vec.vecF[i] < myHist->minVal) {
    136138            myHist->minNum++;
    137         } else if (myArray->arr[i] > myHist->maxVal) {
     139        } else if (myVector->vec.vecF[i] > myHist->maxVal) {
    138140            myHist->maxNum++;
    139141        } else {
    140             binNum = (int) ((myArray->arr[i] - myHist->minVal) / binSize);
    141             if ((myArray->arr[i] >= myHist->lower->arr[i]) &&
    142                     (myArray->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]++;
    144146            } else {
    145147                psError(__func__, "data value was not within the bounds of the bin it should habe been in.");
     
    153155    MISC STATISTICAL FUNCTIONS
    154156 *****************************************************************************/
    155 float p_psArraySampleMean(const psFloatArray *restrict myArray,
    156                           const psIntArray *restrict maskArray,
     157float p_psArraySampleMean(const psVector *restrict myVector,
     158                          const psVector *restrict maskVector,
    157159                          unsigned int maskVal)
    158160{
     
    160162    float mean = 0.0;
    161163
    162     if (maskArray != NULL) {
    163         for (i=0;i<myArray->n;i++) {
    164             if (!(maskVal & maskArray->arr[i])) {
    165                 mean+= maskArray->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];
    166168            }
    167169        }
    168170    } else {
    169         for (i=0;i<myArray->n;i++) {
    170             mean+= maskArray->arr[i];
     171        for (i=0;i<myVector->n;i++) {
     172            mean+= maskVector->vec.vecI[i];
    171173        }
    172174    }
     
    174176}
    175177
    176 float p_psArrayMax(const psFloatArray *restrict myArray,
    177                    const psIntArray *restrict maskArray,
     178float p_psArrayMax(const psVector *restrict myVector,
     179                   const psVector *restrict maskVector,
    178180                   unsigned int maskVal)
    179181{
     
    181183    float max = -1e99;
    182184
    183     if (maskArray != NULL) {
    184         for (i=0;i<myArray->n;i++) {
    185             if (!(maskVal & maskArray->arr[i])) {
    186                 if (myArray->arr[i] > max) {
    187                     max = maskArray->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];
    188190                }
    189191            }
    190192        }
    191193    } else {
    192         for (i=0;i<myArray->n;i++) {
    193             if (myArray->arr[i] > max) {
    194                 max = maskArray->arr[i];
     194        for (i=0;i<myVector->n;i++) {
     195            if (myVector->vec.vecF[i] > max) {
     196                max = maskVector->vec.vecI[i];
    195197            }
    196198        }
     
    199201}
    200202
    201 float p_psArrayMin(const psFloatArray *restrict myArray,
    202                    const psIntArray *restrict maskArray,
     203float p_psArrayMin(const psVector *restrict myVector, /* FLOATS */
     204                   const psVector *restrict maskVector, /* INTS */
    203205                   unsigned int maskVal)
    204206{
     
    206208    float min = 1e99;
    207209
    208     if (maskArray != NULL) {
    209         for (i=0;i<myArray->n;i++) {
    210             if (!(maskVal & maskArray->arr[i])) {
    211                 if (myArray->arr[i] < min) {
    212                     min = maskArray->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];
    213215                }
    214216            }
    215217        }
    216218    } else {
    217         for (i=0;i<myArray->n;i++) {
    218             if (myArray->arr[i] < min) {
    219                 min = maskArray->arr[i];
     219        for (i=0;i<myVector->n;i++) {
     220            if (myVector->vec.vecF[i] < min) {
     221                min = maskVector->vec.vecI[i];
    220222            }
    221223        }
     
    224226}
    225227
    226 int p_psArrayNValues(const psFloatArray *restrict myArray,
    227                      const psIntArray *restrict maskArray,
     228int p_psArrayNValues(const psVector *restrict myVector, // float
     229                     const psVector *restrict maskVector, // ints
    228230                     unsigned int maskVal)
    229231{
     
    231233    int numData = 0;
    232234
    233     if (maskArray != NULL) {
    234         for (i=0;i<myArray->n;i++) {
    235             if (!(maskVal & maskArray->arr[i])) {
     235    if (maskVector != NULL) {
     236        for (i=0;i<myVector->n;i++) {
     237            if (!(maskVal & maskVector->vec.vecI[i])) {
    236238                numData++;
    237239            }
    238240        }
    239241    } else {
    240         numData = myArray->n;
     242        numData = myVector->n;
    241243    }
    242244    return(numData);
    243245}
    244246
    245 psStats *psArrayStats(const psFloatArray *restrict myArray,
    246                       const psIntArray *restrict maskArray,
     247psStats *psArrayStats(const psVector *restrict myVector, // FLOAT
     248                      const psVector *restrict maskVector, // INT
    247249                      unsigned int maskVal,
    248250                      psStats *stats)
     
    251253
    252254    newStruct = psStatsAlloc(stats->options);
    253     if (myArray == NULL) {
     255    if (myVector == NULL) {
    254256        psError(__func__,
    255                 "Input data array (myArray) was NULL.");
    256     }
    257 
    258     if ((maskArray != NULL) &&
    259             (myArray->n != maskArray->n)) {
    260         psError(__func__, "Array data and array mask 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.");
    261263    }
    262264
    263265    switch (stats->options) {
    264266    case PS_STAT_SAMPLE_MEAN:
    265         newStruct->max = p_psArraySampleMean(myArray, maskArray, maskVal);
     267        newStruct->max = p_psArraySampleMean(myVector, maskVector, maskVal);
    266268        break;
    267269    case PS_STAT_SAMPLE_MEDIAN:
     
    317319        break;
    318320    case PS_STAT_MAX:
    319         newStruct->max = p_psArrayMax(myArray, maskArray, maskVal);
     321        newStruct->max = p_psArrayMax(myVector, maskVector, maskVal);
    320322        break;
    321323    case PS_STAT_MIN:
    322         newStruct->min = p_psArrayMin(myArray, maskArray, maskVal);
     324        newStruct->min = p_psArrayMin(myVector, maskVector, maskVal);
    323325        break;
    324326    case PS_STAT_NVALUES:
    325         newStruct->nValues = p_psArrayNValues(myArray, maskArray, maskVal);
     327        newStruct->nValues = p_psArrayNValues(myVector, maskVector, maskVal);
    326328        break;
    327329    default:
Note: See TracChangeset for help on using the changeset viewer.