Changeset 1328
- Timestamp:
- Jul 28, 2004, 6:17:20 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/dataManip/psStats.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/psStats.c
r1327 r1328 88 88 /*****************************************************************************/ 89 89 90 bool 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 90 144 /***************************************************************************** 91 145 p_psVectorPrint(myVector, maskVector, maskVal, stats): a private internal … … 140 194 calculated in this routine. 141 195 *****************************************************************************/ 196 142 197 void p_psVectorSampleMean(const psVector *restrict myVector, 143 198 const psVector *restrict maskVector, … … 1790 1845 1791 1846 /****************************************************************************** 1847 p_psConvertToF32(myVector, maskVector, maskVal, stats): this is the cheap 1848 way to support a variety of vector data types: we simply convert the input 1849 vector to F32 at the beginning, and write all of our functions in F32. If 1850 the vast majority of all vector stat operations are F32 (or any other single 1851 type), then this is probably the best way to go. Otherwise, when the 1852 algorithms stablize, we will then macro everything and put type support in 1853 the various stat functions. 1854 *****************************************************************************/ 1855 psVector *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 /****************************************************************************** 1792 1886 psVectorStats(myVector, maskVector, maskVal, stats): this is the public API 1793 1887 function which calls the above private stats functions based on what bits … … 1811 1905 unsigned int maskVal) 1812 1906 { 1907 psVector *inF32; 1908 int mustFreeTmp = 1; 1909 1813 1910 // NOTE: Verify that this is the correct action. 1814 1911 if (in == NULL) { … … 1817 1914 if (stats == NULL) { 1818 1915 return(NULL); 1916 } 1917 1918 inF32 = p_psConvertToF32(stats, in, mask, maskVal); 1919 if (inF32 == NULL) { 1920 inF32 = in; 1921 mustFreeTmp = 0; 1819 1922 } 1820 1923 … … 1826 1929 } 1827 1930 1828 PS_CHECK_VECTOR_TYPE(in, PS_TYPE_F32);1931 // PS_CHECK_VECTOR_TYPE(in, PS_TYPE_F32); 1829 1932 if (mask != NULL) { 1830 1933 PS_CHECK_NULL_VECTOR(mask); … … 1883 1986 } 1884 1987 1988 if (mustFreeTmp == 1) { 1989 psFree(inF32); 1990 } 1991 1885 1992 return(stats); 1886 1993 } 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.
