IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24884


Ignore:
Timestamp:
Jul 21, 2009, 2:52:17 PM (17 years ago)
Author:
eugene
Message:

add test for zero-range vector in fitted stats v4; clean up exit for function

File:
1 edited

Legend:

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

    r24790 r24884  
    17341734
    17351735    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    1736     if (isnan(stats->robustMedian)) {
    1737         stats->fittedStdev = NAN;
    1738         stats->fittedStdev = NAN;
    1739         return true;
    1740     }
     1736    if (isnan(stats->robustMedian)) goto escape;
    17411737
    17421738    float guessStdev = stats->robustStdev;  // pass the guess sigma
     
    17701766            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
    17711767            psFree(statsMinMax);
    1772             stats->fittedStdev = NAN;
    1773             stats->fittedStdev = NAN;
     1768            goto escape;
     1769        }
     1770
     1771        // If all data points have the same value, then we set the appropriate members of stats and return.
     1772        if (fabs(max - min) <= FLT_EPSILON) {
     1773            COUNT_WARNING(10, 100, "All data points have the same value: %f.\n", min);
     1774            stats->fittedMean = min;
     1775            stats->fittedStdev = 0.0;
     1776            stats->results |= PS_STAT_FITTED_MEAN_V4;
     1777            stats->results |= PS_STAT_FITTED_STDEV_V4;
    17741778            return true;
    17751779        }
     
    17891793            psFree(histogram);
    17901794            psFree(statsMinMax);
    1791             stats->fittedStdev = NAN;
    1792             stats->fittedStdev = NAN;
    1793             return true;
     1795            goto escape;
    17941796        }
    17951797        if (psTraceGetLevel("psLib.math") >= 8) {
     
    18231825            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
    18241826            psFree(statsMinMax);
    1825             stats->fittedStdev = NAN;
    1826             stats->fittedStdev = NAN;
    1827             return true;
     1827            goto escape;
    18281828        }
    18291829
     
    18981898                psFree(histogram);
    18991899                psFree(statsMinMax);
    1900                 stats->fittedStdev = NAN;
    1901                 stats->fittedStdev = NAN;
    1902                 return true;
     1900                goto escape;
    19031901            }
    19041902
     
    19191917
    19201918                COUNT_WARNING(10, 100, "fit did not converge\n");
    1921                 stats->fittedStdev = NAN;
    1922                 stats->fittedStdev = NAN;
    1923                 return true;
     1919                goto escape;
    19241920            }
    19251921
     
    19911987                psFree(histogram);
    19921988                psFree(statsMinMax);
    1993                 stats->fittedStdev = NAN;
    1994                 stats->fittedStdev = NAN;
    1995                 return true;
     1989                goto escape;
    19961990            }
    19971991
     
    20382032    psTrace(TRACE, 6, "The fitted stdev is %f.\n", stats->fittedStdev);
    20392033
     2034    stats->results |= PS_STAT_FITTED_MEAN_V4;
     2035    stats->results |= PS_STAT_FITTED_STDEV_V4;
     2036
     2037    return true;
     2038
     2039escape:
     2040    stats->fittedMean = NAN;
     2041    stats->fittedStdev = NAN;
    20402042    stats->results |= PS_STAT_FITTED_MEAN_V4;
    20412043    stats->results |= PS_STAT_FITTED_STDEV_V4;
Note: See TracChangeset for help on using the changeset viewer.