IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27334


Ignore:
Timestamp:
Mar 18, 2010, 1:28:21 PM (16 years ago)
Author:
Paul Price
Message:

Plug memory leak.

File:
1 edited

Legend:

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

    r26641 r27334  
    751751        psTrace(TRACE, 6, "-------------------- Iterating on Bin size.  Iteration number %d --------------------\n", iterate);
    752752
    753         if (iterate >= PS_ROBUST_MAX_ITERATIONS) {
    754           // This occurs when a large number of the values are identical --- a bin size cannot be found
    755           // that will spread out the distribution.  Therefore, set what we can, and fall over
    756           // gracefully.
    757           COUNT_WARNING(10, 100, "Maximum number of iterations (%d) exceeded.", PS_ROBUST_MAX_ITERATIONS);
    758           goto escape;
    759         }
     753        if (iterate >= PS_ROBUST_MAX_ITERATIONS) {
     754          // This occurs when a large number of the values are identical --- a bin size cannot be found
     755          // that will spread out the distribution.  Therefore, set what we can, and fall over
     756          // gracefully.
     757          COUNT_WARNING(10, 100, "Maximum number of iterations (%d) exceeded.", PS_ROBUST_MAX_ITERATIONS);
     758          goto escape;
     759        }
    760760
    761761        // Get the minimum and maximum values
     
    823823        }
    824824
    825         // perversity check: if most of the values land in a single bin, then we probably
    826         // have a perverse case (eg, small number of points at extremely large / small
    827         // values; nearly bi-modal distribution).  if so, keep only points within 5? 10?
    828         // bins of that excess bin:
    829         int nMaxBin = 0;
    830         int iMaxBin = 0;
     825        // perversity check: if most of the values land in a single bin, then we probably
     826        // have a perverse case (eg, small number of points at extremely large / small
     827        // values; nearly bi-modal distribution).  if so, keep only points within 5? 10?
     828        // bins of that excess bin:
     829        int nMaxBin = 0;
     830        int iMaxBin = 0;
    831831        for (long i = 1; i < histogram->nums->n; i++) {
    832             if (histogram->nums->data.F32[i] > nMaxBin) {
    833                 nMaxBin = histogram->nums->data.F32[i];
    834                 iMaxBin = i;
    835             }
    836         }
    837         if (nMaxBin > numValid / 2) {
    838             float minKeep = histogram->bounds->data.F32[iMaxBin] - 10*binSize;
    839             float maxKeep = histogram->bounds->data.F32[iMaxBin + 1] + 10*binSize;
    840             int nInvalid = 0;
    841             for (long i = 0; i < myVector->n; i++) {
    842                 // skip the already-masked values
    843                 if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal) continue;
    844                 bool invalid = false;
    845                 invalid |= (myVector->data.F32[i] <= minKeep);
    846                 invalid |= (myVector->data.F32[i] >= maxKeep);
    847                 invalid |= (!isfinite(myVector->data.F32[i]));
    848                 if (!invalid) continue;
    849                 mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = maskVal;
    850                 nInvalid ++;
    851             }
    852 
    853             if (nInvalid) {
    854               psTrace(TRACE, 6, "data is concentrated in a single bin, masking %d extreme outliers and retrying\n", nInvalid);
    855               psFree(histogram);
    856               psFree(cumulative);
    857               histogram = NULL;
    858               cumulative = NULL;
    859               continue;
    860             }
    861             // if we did not mask anything, give up.
    862         }
     832            if (histogram->nums->data.F32[i] > nMaxBin) {
     833                nMaxBin = histogram->nums->data.F32[i];
     834                iMaxBin = i;
     835            }
     836        }
     837        if (nMaxBin > numValid / 2) {
     838            float minKeep = histogram->bounds->data.F32[iMaxBin] - 10*binSize;
     839            float maxKeep = histogram->bounds->data.F32[iMaxBin + 1] + 10*binSize;
     840            int nInvalid = 0;
     841            for (long i = 0; i < myVector->n; i++) {
     842                // skip the already-masked values
     843                if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal) continue;
     844                bool invalid = false;
     845                invalid |= (myVector->data.F32[i] <= minKeep);
     846                invalid |= (myVector->data.F32[i] >= maxKeep);
     847                invalid |= (!isfinite(myVector->data.F32[i]));
     848                if (!invalid) continue;
     849                mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = maskVal;
     850                nInvalid ++;
     851            }
     852
     853            if (nInvalid) {
     854              psTrace(TRACE, 6, "data is concentrated in a single bin, masking %d extreme outliers and retrying\n", nInvalid);
     855              psFree(histogram);
     856              psFree(cumulative);
     857              histogram = NULL;
     858              cumulative = NULL;
     859              continue;
     860            }
     861            // if we did not mask anything, give up.
     862        }
    863863
    864864        // ADD step 1: Convert the specific histogram to a cumulative histogram
     
    18731873            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
    18741874            psFree(statsMinMax);
     1875            psFree(histogram);
    18751876            goto escape;
    18761877        }
     
    19421943
    19431944            if (!status) {
    1944                 psErrorClear();
     1945                psErrorClear();
    19451946                COUNT_WARNING(10, 100, "Failed to fit a gaussian to the robust histogram.\n");
    19461947                psFree(poly);
     
    20322033
    20332034            if (!status) {
    2034                 psErrorClear();
     2035                psErrorClear();
    20352036                COUNT_WARNING(10, 100, "Failed to fit a gaussian to the robust histogram.\n");
    20362037                psFree(poly);
Note: See TracChangeset for help on using the changeset viewer.