IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1328


Ignore:
Timestamp:
Jul 28, 2004, 6:17:20 PM (22 years ago)
Author:
gusciora
Message:

...

File:
1 edited

Legend:

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

    r1327 r1328  
    8888/*****************************************************************************/
    8989
     90bool p_psGetStatValue(const psStats* stats, double* value)
     91{
     92
     93    switch (stats->options &
     94            ~ (PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE | PS_STAT_ROBUST_FOR_SAMPLE)) {
     95    case PS_STAT_SAMPLE_MEAN:
     96        *value = stats->sampleMean;
     97        return true;
     98
     99    case PS_STAT_SAMPLE_MEDIAN:
     100        *value = stats->sampleMedian;
     101        return true;
     102
     103    case PS_STAT_SAMPLE_STDEV:
     104        *value = stats->sampleStdev;
     105        return true;
     106
     107    case PS_STAT_ROBUST_MEAN:
     108        *value = stats->robustMean;
     109        return true;
     110
     111    case PS_STAT_ROBUST_MEDIAN:
     112        *value = stats->robustMedian;
     113        return true;
     114
     115    case PS_STAT_ROBUST_MODE:
     116        *value = stats->robustMode;
     117        return true;
     118
     119    case PS_STAT_ROBUST_STDEV:
     120        *value = stats->robustStdev;
     121        return true;
     122
     123    case PS_STAT_CLIPPED_MEAN:
     124        *value = stats->clippedMean;
     125        return true;
     126
     127    case PS_STAT_CLIPPED_STDEV:
     128        *value = stats->clippedStdev;
     129        return true;
     130
     131    case PS_STAT_MAX:
     132        *value = stats->max;
     133        return true;
     134
     135    case PS_STAT_MIN:
     136        *value = stats->min;
     137        return true;
     138
     139    default:
     140        return false;
     141    }
     142}
     143
    90144/*****************************************************************************
    91145p_psVectorPrint(myVector, maskVector, maskVal, stats): a private internal
     
    140194calculated in this routine.
    141195 *****************************************************************************/
     196
    142197void p_psVectorSampleMean(const psVector *restrict myVector,
    143198                          const psVector *restrict maskVector,
     
    17901845
    17911846/******************************************************************************
     1847p_psConvertToF32(myVector, maskVector, maskVal, stats): this is the cheap
     1848way to support a variety of vector data types: we simply convert the input
     1849vector to F32 at the beginning, and write all of our functions in F32.  If
     1850the vast majority of all vector stat operations are F32 (or any other single
     1851type), then this is probably the best way to go.  Otherwise, when the
     1852algorithms stablize, we will then macro everything and put type support in
     1853the various stat functions.
     1854 *****************************************************************************/
     1855psVector *p_psConvertToF32(psStats *stats,
     1856                           psVector *in,
     1857                           psVector *mask,
     1858                           unsigned int maskVal)
     1859{
     1860    int i = 0;
     1861    psVector *tmp = NULL;
     1862
     1863    if (in->type.type == PS_TYPE_S32) {
     1864        tmp = psVectorAlloc(in->n, PS_TYPE_F32);
     1865        for (i=0;i<in->n;i++) {
     1866            tmp->data.F32[i] = (float) in->data.S32[i];
     1867        }
     1868    } else if (in->type.type == PS_TYPE_U32) {
     1869        tmp = psVectorAlloc(in->n, PS_TYPE_F32);
     1870        for (i=0;i<in->n;i++) {
     1871            tmp->data.F32[i] = (float) in->data.U32[i];
     1872        }
     1873    } else if (in->type.type == PS_TYPE_F64) {
     1874        tmp = psVectorAlloc(in->n, PS_TYPE_F32);
     1875        for (i=0;i<in->n;i++) {
     1876            tmp->data.F32[i] = (float) in->data.F64[i];
     1877        }
     1878    } else {
     1879        psAbort(__func__, "unsupported vector type 0x%x\n", in->type.type);
     1880    }
     1881    return(tmp);
     1882}
     1883
     1884
     1885/******************************************************************************
    17921886psVectorStats(myVector, maskVector, maskVal, stats): this is the public API
    17931887function which calls the above private stats functions based on what bits
     
    18111905                       unsigned int maskVal)
    18121906{
     1907    psVector *inF32;
     1908    int mustFreeTmp = 1;
     1909
    18131910    // NOTE: Verify that this is the correct action.
    18141911    if (in == NULL) {
     
    18171914    if (stats == NULL) {
    18181915        return(NULL);
     1916    }
     1917
     1918    inF32 = p_psConvertToF32(stats, in, mask, maskVal);
     1919    if (inF32 == NULL) {
     1920        inF32 = in;
     1921        mustFreeTmp = 0;
    18191922    }
    18201923
     
    18261929    }
    18271930
    1828     PS_CHECK_VECTOR_TYPE(in, PS_TYPE_F32);
     1931    //    PS_CHECK_VECTOR_TYPE(in, PS_TYPE_F32);
    18291932    if (mask != NULL) {
    18301933        PS_CHECK_NULL_VECTOR(mask);
     
    18831986    }
    18841987
     1988    if (mustFreeTmp == 1) {
     1989        psFree(inF32);
     1990    }
     1991
    18851992    return(stats);
    18861993}
    1887 
    1888 bool p_psGetStatValue(const psStats* stats, double* value)
    1889 {
    1890 
    1891     switch (stats->options &
    1892             ~ (PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE | PS_STAT_ROBUST_FOR_SAMPLE)) {
    1893     case PS_STAT_SAMPLE_MEAN:
    1894         *value = stats->sampleMean;
    1895         return true;
    1896 
    1897     case PS_STAT_SAMPLE_MEDIAN:
    1898         *value = stats->sampleMedian;
    1899         return true;
    1900 
    1901     case PS_STAT_SAMPLE_STDEV:
    1902         *value = stats->sampleStdev;
    1903         return true;
    1904 
    1905     case PS_STAT_ROBUST_MEAN:
    1906         *value = stats->robustMean;
    1907         return true;
    1908 
    1909     case PS_STAT_ROBUST_MEDIAN:
    1910         *value = stats->robustMedian;
    1911         return true;
    1912 
    1913     case PS_STAT_ROBUST_MODE:
    1914         *value = stats->robustMode;
    1915         return true;
    1916 
    1917     case PS_STAT_ROBUST_STDEV:
    1918         *value = stats->robustStdev;
    1919         return true;
    1920 
    1921     case PS_STAT_CLIPPED_MEAN:
    1922         *value = stats->clippedMean;
    1923         return true;
    1924 
    1925     case PS_STAT_CLIPPED_STDEV:
    1926         *value = stats->clippedStdev;
    1927         return true;
    1928 
    1929     case PS_STAT_MAX:
    1930         *value = stats->max;
    1931         return true;
    1932 
    1933     case PS_STAT_MIN:
    1934         *value = stats->min;
    1935         return true;
    1936 
    1937     default:
    1938         return false;
    1939     }
    1940 }
Note: See TracChangeset for help on using the changeset viewer.