IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 27, 2006, 2:44:05 PM (20 years ago)
Author:
Paul Price
Message:

Replacing p_psGetStatValue with two functions: psStatsSingleOption returns the single option that is set, or 0 if no matching option is set; psStatsGetValue returns the value for a requested statistic. Tests seem to pass with the new code.

File:
1 edited

Legend:

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

    r7991 r7999  
    1616 * use ->min and ->max (PS_STAT_USE_RANGE)
    1717 *
    18  *  @version $Revision: 1.181 $ $Name: not supported by cvs2svn $
    19  *  @date $Date: 2006-07-27 03:51:13 $
     18 *  @version $Revision: 1.182 $ $Name: not supported by cvs2svn $
     19 *  @date $Date: 2006-07-28 00:44:05 $
    2020 *
    2121 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3434/*****************************************************************************/
    3535#include "psMemory.h"
     36#include "psAbort.h"
    3637#include "psImage.h"
    3738#include "psVector.h"
     
    8081
    8182// None
    82 
    83 /*****************************************************************************/
    84 /* FUNCTION IMPLEMENTATION - LOCAL                                           */
    85 /*****************************************************************************/
    86 
    87 psBool p_psGetStatValue(const psStats* stats, psF64 *value)
    88 {
    89     psTrace(__func__, 4, "---- %s() begin ----\n", __func__);
    90     //    switch (stats->options & ~(PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE | PS_STAT_ROBUST_FOR_SAMPLE)) {
    91     switch (stats->options & ~(PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE)) {
    92     case PS_STAT_SAMPLE_MEAN:
    93         *value = stats->sampleMean;
    94         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    95         return true;
    96 
    97     case PS_STAT_SAMPLE_MEDIAN:
    98         *value = stats->sampleMedian;
    99         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    100         return true;
    101 
    102     case PS_STAT_SAMPLE_STDEV:
    103         *value = stats->sampleStdev;
    104         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    105         return true;
    106 
    107     case PS_STAT_ROBUST_MEDIAN:
    108         *value = stats->robustMedian;
    109         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    110         return true;
    111 
    112     case PS_STAT_ROBUST_STDEV:
    113         *value = stats->robustStdev;
    114         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    115         return true;
    116 
    117     case PS_STAT_CLIPPED_MEAN:
    118         *value = stats->clippedMean;
    119         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    120         return true;
    121 
    122     case PS_STAT_CLIPPED_STDEV:
    123         *value = stats->clippedStdev;
    124         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    125         return true;
    126 
    127     case PS_STAT_MAX:
    128         *value = stats->max;
    129         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    130         return true;
    131 
    132     case PS_STAT_MIN:
    133         *value = stats->min;
    134         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    135         return true;
    136 
    137     default:
    138         psTrace(__func__, 4, "---- %s(false) end ----\n", __func__);
    139         return false;
    140     }
    141 }
    14283
    14384/******************************************************************************
     
    22112152    return psStatsOptionToString(stats->options);
    22122153}
     2154
     2155inline psStatsOptions psStatsSingleOption(psStatsOptions option)
     2156{
     2157    switch (option & ~(PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE)) {
     2158    case PS_STAT_SAMPLE_MEAN:
     2159    case PS_STAT_SAMPLE_MEDIAN:
     2160    case PS_STAT_SAMPLE_STDEV:
     2161    case PS_STAT_SAMPLE_QUARTILE:
     2162    case PS_STAT_ROBUST_MEDIAN:
     2163    case PS_STAT_ROBUST_STDEV:
     2164    case PS_STAT_ROBUST_QUARTILE:
     2165    case PS_STAT_FITTED_MEAN:
     2166    case PS_STAT_FITTED_STDEV:
     2167    case PS_STAT_CLIPPED_MEAN:
     2168    case PS_STAT_CLIPPED_STDEV:
     2169    case PS_STAT_MAX:
     2170    case PS_STAT_MIN:
     2171        return option & ~(PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE);
     2172    default:
     2173        return 0;
     2174    }
     2175    psAbort(__func__, "Should never get here.\n");
     2176    return 0;
     2177}
     2178
     2179inline double psStatsGetValue(const psStats *stats, psStatsOptions option)
     2180{
     2181    // We could call psStatsSingle to check, but it would be a waste since we effectively do it anyway
     2182    switch (option & ~(PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE)) {
     2183    case PS_STAT_SAMPLE_MEAN:
     2184        return stats->sampleMean;
     2185    case PS_STAT_SAMPLE_MEDIAN:
     2186        return stats->sampleMedian;
     2187    case PS_STAT_SAMPLE_STDEV:
     2188        return stats->sampleStdev;
     2189    case PS_STAT_ROBUST_MEDIAN:
     2190        return stats->robustMedian;
     2191    case PS_STAT_ROBUST_STDEV:
     2192        return stats->robustStdev;
     2193    case PS_STAT_FITTED_MEAN:
     2194        return stats->fittedMean;
     2195    case PS_STAT_FITTED_STDEV:
     2196        return stats->fittedStdev;
     2197    case PS_STAT_CLIPPED_MEAN:
     2198        return stats->clippedMean;
     2199    case PS_STAT_CLIPPED_STDEV:
     2200        return stats->clippedStdev;
     2201    case PS_STAT_MAX:
     2202        return stats->max;
     2203    case PS_STAT_MIN:
     2204        return stats->min;
     2205    case PS_STAT_SAMPLE_QUARTILE:
     2206    case PS_STAT_ROBUST_QUARTILE:
     2207        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Cannot return a single quartile value; "
     2208                "get them yourself.\n");
     2209        return NAN;
     2210    default:
     2211        return NAN;
     2212    }
     2213    psAbort(__func__, "Should never get here.\n");
     2214    return NAN;
     2215}
Note: See TracChangeset for help on using the changeset viewer.