IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18876


Ignore:
Timestamp:
Aug 3, 2008, 10:55:09 AM (18 years ago)
Author:
eugene
Message:

added a tmpData and tmpMask element to psStats for multithreading improvements

Location:
trunk/psLib/src/math
Files:
2 edited

Legend:

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

    r18493 r18876  
    1313 * use ->min and ->max (PS_STAT_USE_RANGE)
    1414 *
    15  *  @version $Revision: 1.227 $ $Name: not supported by cvs2svn $
    16  *  @date $Date: 2008-07-12 21:08:14 $
     15 *  @version $Revision: 1.228 $ $Name: not supported by cvs2svn $
     16 *  @date $Date: 2008-08-03 20:54:43 $
    1717 *
    1818 *  Copyright 2006 IfA, University of Hawaii
     
    310310    psF32 *input = inVector->data.F32; // Dereference the vector
    311311
    312     // Allocate temporary vectors for the data.
    313     psVector *outVector = psVectorAllocEmpty(inVector->n, PS_TYPE_F32); // Vector containing unmasked values
     312    // use the temporary vector for the sorted output
     313    stats->tmpData = psVectorRecycle (stats->tmpData, inVector->n, PS_TYPE_F32);
     314    psVector *outVector = stats->tmpData;
    314315    psF32 *output = outVector->data.F32; // Dereference the vector
    315316
     
    333334    if (count == 0) {
    334335        psError(PS_ERR_BAD_PARAMETER_SIZE, true, "No valid data in input vector.\n");
    335         psFree(outVector);
    336336        stats->sampleUQ = NAN;
    337337        stats->sampleLQ = NAN;
     
    346346        stats->sampleLQ = NAN;
    347347        stats->sampleMedian = NAN;
    348         psFree(outVector);
    349348        return false;
    350349    }
     
    363362    stats->results |= PS_STAT_SAMPLE_MEDIAN;
    364363    stats->results |= PS_STAT_SAMPLE_QUARTILE;
    365 
    366     // Free the temporary data structures.
    367     psFree(outVector);
    368364
    369365    // Return "true" on success.
     
    584580    // We copy the mask vector, to preserve the original
    585581    psMaskType maskVal = MASK_MARK | maskValInput;
    586     psVector *tmpMask = psVectorAlloc(myVector->n, PS_TYPE_U8);
     582
     583    // use the temporary vector for local temporary mask
     584    stats->tmpMask = psVectorRecycle (stats->tmpMask, myVector->n, PS_TYPE_U8);
     585    psVector *tmpMask = stats->tmpMask;
    587586    psVectorInit(tmpMask, 0);
    588587    if (maskInput) {
     
    599598        psTrace(TRACE, 5, "Call to vectorSampleMedian returned NAN\n");
    600599        psTrace(TRACE, 4, "---- %s(false) end ----\n", __func__);
    601         psFree(tmpMask);
    602600        return false;
    603601    }
     
    609607        psTrace(TRACE, 5, "Call to vectorSampleStdev returned NAN\n");
    610608        psTrace(TRACE, 4, "---- %s(false) end ----\n", __func__);
    611         psFree(tmpMask);
    612609        return false;
    613610    }
     
    654651        // b) compute new mean and stdev
    655652        // Allocate a psStats structure for calculating the mean and stdev.
    656         psStats *statsTmp = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
    657         vectorSampleMean(myVector, errors, tmpMask, maskVal, statsTmp);
    658         vectorSampleStdev(myVector, errors, tmpMask, maskVal, statsTmp);
    659         psTrace(TRACE, 6, "The new sample mean is %f\n", statsTmp->sampleMean);
    660         psTrace(TRACE, 6, "The new sample stdev is %f\n", statsTmp->sampleStdev);
     653        // XXX Can we just use this psStats structure to calculate the SAMPLE MEAN and STDEV?
     654        // psStats *statsTmp = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
     655        // vectorSampleMean(myVector, errors, tmpMask, maskVal, statsTmp);
     656        // vectorSampleStdev(myVector, errors, tmpMask, maskVal, statsTmp);
     657        vectorSampleMean(myVector, errors, tmpMask, maskVal, stats);
     658        vectorSampleStdev(myVector, errors, tmpMask, maskVal, stats);
     659        psTrace(TRACE, 6, "The new sample mean is %f\n", stats->sampleMean);
     660        psTrace(TRACE, 6, "The new sample stdev is %f\n", stats->sampleStdev);
    661661
    662662        // If the new mean and stdev are NAN, we must exit the loop.
    663663        // Otherwise, use the new results and continue.
    664         if (isnan(statsTmp->sampleMean) || isnan(statsTmp->sampleStdev)) {
    665             // Exit loop.
     664        if (isnan(stats->sampleMean) || isnan(stats->sampleStdev)) {
    666665            iter = stats->clipIter;
    667666            psError(PS_ERR_UNKNOWN, true, "vectorSampleMean() or vectorSampleStdev() returned a NAN.\n");
    668             psFree(tmpMask);
    669667            return false;
    670668        } else {
    671             clippedMean = statsTmp->sampleMean;
    672             clippedStdev = statsTmp->sampleStdev;
    673         }
    674         psFree(statsTmp);
     669            clippedMean = stats->sampleMean;
     670            clippedStdev = stats->sampleStdev;
     671        }
     672        // psFree(statsTmp);
    675673    }
    676674
     
    690688    psTrace(TRACE, 6, "The final clipped stdev is %f\n", clippedStdev);
    691689
    692     psFree(tmpMask);
    693690    psTrace(TRACE, 4, "---- %s(true) end ----\n", __func__);
    694691    return true;
     
    21392136/*****************************************************************************/
    21402137
    2141 // We keep statsFree so that we can identify statistics pointers from the memblock
     2138// free function
    21422139static void statsFree(psStats *stats)
    21432140{
    2144     // There are non dynamic allocated items
     2141    if (!stats) return;
     2142    psFree (stats->tmpData);
     2143    psFree (stats->tmpMask);
    21452144    return;
    21462145}
     
    21652164    stats->nSubsample = 100000;
    21662165    stats->options = options;
     2166    stats->tmpData = NULL;
     2167    stats->tmpMask = NULL;
    21672168
    21682169    psTrace(TRACE, 3, "---- %s() end  ----\n", __func__);
  • trunk/psLib/src/math/psStats.h

    r15840 r18876  
    88 * @author GLG, MHPCC
    99 *
    10  * @version $Revision: 1.64 $ $Name: not supported by cvs2svn $
    11  * @date $Date: 2007-12-15 01:17:28 $
     10 * @version $Revision: 1.65 $ $Name: not supported by cvs2svn $
     11 * @date $Date: 2008-08-03 20:55:09 $
    1212 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1313 */
     
    8686    psStatsOptions options;            ///< bitmask of values requested
    8787    psStatsOptions results;            ///< bitmask of values calculated
     88    psVector *tmpData;                 ///< temporary vector so repeated calls do not have to realloc
     89    psVector *tmpMask;                 ///< temporary vector so repeated calls do not have to realloc
    8890}
    8991psStats;
Note: See TracChangeset for help on using the changeset viewer.