Changeset 9ee2ce3 for thirdparty/SZ/sz/src/sz_float_pwr.c
- Timestamp:
- 09/28/18 16:32:55 (6 years ago)
- Branches:
- master, pympi
- Children:
- e6aa0eb
- Parents:
- abca157
- git-author:
- Hal Finkel <hfinkel@…> (09/28/18 16:32:55)
- git-committer:
- Hal Finkel <hfinkel@…> (09/28/18 16:32:55)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
thirdparty/SZ/sz/src/sz_float_pwr.c
r2c47b73 r9ee2ce3 24 24 #include "zlib.h" 25 25 #include "rw.h" 26 #include "utility.h" 26 27 27 28 void compute_segment_precisions_float_1D(float *oriData, size_t dataLength, float* pwrErrBound, unsigned char* pwrErrBoundBytes, double globalPrecision) … … 1781 1782 free_TightDataPointStorageF(tdps); 1782 1783 } 1784 1785 #include <stdbool.h> 1786 1787 void SZ_compress_args_float_NoCkRngeNoGzip_1D_pwr_pre_log(unsigned char** newByteData, float *oriData, double pwrErrRatio, size_t dataLength, size_t *outSize, float min, float max){ 1788 1789 float * log_data = (float *) malloc(dataLength * sizeof(float)); 1790 1791 unsigned char * signs = (unsigned char *) malloc(dataLength); 1792 memset(signs, 0, dataLength); 1793 // preprocess 1794 float max_abs_log_data; 1795 if(min == 0) max_abs_log_data = fabs(log2(fabs(max))); 1796 else if(max == 0) max_abs_log_data = fabs(log2(fabs(min))); 1797 else max_abs_log_data = fabs(log2(fabs(min))) > fabs(log2(fabs(max))) ? fabs(log2(fabs(min))) : fabs(log2(fabs(max))); 1798 float min_log_data = max_abs_log_data; 1799 bool positive = true; 1800 for(size_t i=0; i<dataLength; i++){ 1801 if(oriData[i] < 0){ 1802 signs[i] = 1; 1803 log_data[i] = -oriData[i]; 1804 positive = false; 1805 } 1806 else 1807 log_data[i] = oriData[i]; 1808 if(log_data[i] > 0){ 1809 log_data[i] = log2(log_data[i]); 1810 if(log_data[i] > max_abs_log_data) max_abs_log_data = log_data[i]; 1811 if(log_data[i] < min_log_data) min_log_data = log_data[i]; 1812 } 1813 } 1814 1815 float valueRangeSize, medianValue_f; 1816 computeRangeSize_float(log_data, dataLength, &valueRangeSize, &medianValue_f); 1817 if(fabs(min_log_data) > max_abs_log_data) max_abs_log_data = fabs(min_log_data); 1818 double realPrecision = log2(1.0 + pwrErrRatio) - max_abs_log_data * 1.2e-7; 1819 for(size_t i=0; i<dataLength; i++){ 1820 if(oriData[i] == 0){ 1821 log_data[i] = min_log_data - 2.0001*realPrecision; 1822 } 1823 } 1824 1825 TightDataPointStorageF* tdps = SZ_compress_float_1D_MDQ(log_data, dataLength, realPrecision, valueRangeSize, medianValue_f); 1826 tdps->minLogValue = min_log_data - 1.0001*realPrecision; 1827 free(log_data); 1828 if(!positive){ 1829 unsigned char * comp_signs; 1830 // compress signs 1831 unsigned long signSize = sz_lossless_compress(confparams_cpr->losslessCompressor, confparams_cpr->gzipMode, signs, dataLength, &comp_signs); 1832 tdps->pwrErrBoundBytes = comp_signs; 1833 tdps->pwrErrBoundBytes_size = signSize; 1834 } 1835 else{ 1836 tdps->pwrErrBoundBytes = NULL; 1837 tdps->pwrErrBoundBytes_size = 0; 1838 } 1839 free(signs); 1840 1841 convertTDPStoFlatBytes_float(tdps, newByteData, outSize); 1842 if(*outSize>dataLength*sizeof(float)) 1843 SZ_compress_args_float_StoreOriData(oriData, dataLength+2, tdps, newByteData, outSize); 1844 1845 free_TightDataPointStorageF(tdps); 1846 } 1847 1848 void SZ_compress_args_float_NoCkRngeNoGzip_2D_pwr_pre_log(unsigned char** newByteData, float *oriData, double pwrErrRatio, size_t r1, size_t r2, size_t *outSize, float min, float max){ 1849 1850 size_t dataLength = r1 * r2; 1851 float * log_data = (float *) malloc(dataLength * sizeof(float)); 1852 1853 unsigned char * signs = (unsigned char *) malloc(dataLength); 1854 memset(signs, 0, dataLength); 1855 // preprocess 1856 float max_abs_log_data; 1857 if(min == 0) max_abs_log_data = fabs(log2(fabs(max))); 1858 else if(max == 0) max_abs_log_data = fabs(log2(fabs(min))); 1859 else max_abs_log_data = fabs(log2(fabs(min))) > fabs(log2(fabs(max))) ? fabs(log2(fabs(min))) : fabs(log2(fabs(max))); 1860 float min_log_data = max_abs_log_data; 1861 bool positive = true; 1862 for(size_t i=0; i<dataLength; i++){ 1863 if(oriData[i] < 0){ 1864 signs[i] = 1; 1865 log_data[i] = -oriData[i]; 1866 positive = false; 1867 } 1868 else 1869 log_data[i] = oriData[i]; 1870 if(log_data[i] > 0){ 1871 log_data[i] = log2(log_data[i]); 1872 if(log_data[i] > max_abs_log_data) max_abs_log_data = log_data[i]; 1873 if(log_data[i] < min_log_data) min_log_data = log_data[i]; 1874 } 1875 } 1876 1877 float valueRangeSize, medianValue_f; 1878 computeRangeSize_float(log_data, dataLength, &valueRangeSize, &medianValue_f); 1879 if(fabs(min_log_data) > max_abs_log_data) max_abs_log_data = fabs(min_log_data); 1880 double realPrecision = log2(1.0 + pwrErrRatio) - max_abs_log_data * 1.2e-7; 1881 for(size_t i=0; i<dataLength; i++){ 1882 if(oriData[i] == 0){ 1883 log_data[i] = min_log_data - 2.0001*realPrecision; 1884 } 1885 } 1886 1887 TightDataPointStorageF* tdps = SZ_compress_float_2D_MDQ(log_data, r1, r2, realPrecision, valueRangeSize, medianValue_f); 1888 tdps->minLogValue = min_log_data - 1.0001*realPrecision; 1889 free(log_data); 1890 if(!positive){ 1891 unsigned char * comp_signs; 1892 // compress signs 1893 unsigned long signSize = sz_lossless_compress(confparams_cpr->losslessCompressor, confparams_cpr->gzipMode, signs, dataLength, &comp_signs); 1894 tdps->pwrErrBoundBytes = comp_signs; 1895 tdps->pwrErrBoundBytes_size = signSize; 1896 } 1897 else{ 1898 tdps->pwrErrBoundBytes = NULL; 1899 tdps->pwrErrBoundBytes_size = 0; 1900 } 1901 free(signs); 1902 1903 convertTDPStoFlatBytes_float(tdps, newByteData, outSize); 1904 if(*outSize>dataLength*sizeof(float)) 1905 SZ_compress_args_float_StoreOriData(oriData, dataLength+2, tdps, newByteData, outSize); 1906 1907 free_TightDataPointStorageF(tdps); 1908 } 1909 1910 void SZ_compress_args_float_NoCkRngeNoGzip_3D_pwr_pre_log(unsigned char** newByteData, float *oriData, double pwrErrRatio, size_t r1, size_t r2, size_t r3, size_t *outSize, float min, float max){ 1911 1912 size_t dataLength = r1 * r2 * r3; 1913 float * log_data = (float *) malloc(dataLength * sizeof(float)); 1914 1915 unsigned char * signs = (unsigned char *) malloc(dataLength); 1916 memset(signs, 0, dataLength); 1917 // preprocess 1918 float max_abs_log_data; 1919 if(min == 0) max_abs_log_data = fabs(log2(fabs(max))); 1920 else if(max == 0) max_abs_log_data = fabs(log2(fabs(min))); 1921 else max_abs_log_data = fabs(log2(fabs(min))) > fabs(log2(fabs(max))) ? fabs(log2(fabs(min))) : fabs(log2(fabs(max))); 1922 float min_log_data = max_abs_log_data; 1923 bool positive = true; 1924 for(size_t i=0; i<dataLength; i++){ 1925 if(oriData[i] < 0){ 1926 signs[i] = 1; 1927 log_data[i] = -oriData[i]; 1928 positive = false; 1929 } 1930 else 1931 log_data[i] = oriData[i]; 1932 if(log_data[i] > 0){ 1933 log_data[i] = log2(log_data[i]); 1934 if(log_data[i] > max_abs_log_data) max_abs_log_data = log_data[i]; 1935 if(log_data[i] < min_log_data) min_log_data = log_data[i]; 1936 } 1937 } 1938 1939 float valueRangeSize, medianValue_f; 1940 computeRangeSize_float(log_data, dataLength, &valueRangeSize, &medianValue_f); 1941 if(fabs(min_log_data) > max_abs_log_data) max_abs_log_data = fabs(min_log_data); 1942 double realPrecision = log2(1.0 + pwrErrRatio) - max_abs_log_data * 1.2e-7; 1943 for(size_t i=0; i<dataLength; i++){ 1944 if(oriData[i] == 0){ 1945 log_data[i] = min_log_data - 2.0001*realPrecision; 1946 } 1947 } 1948 1949 TightDataPointStorageF* tdps = SZ_compress_float_3D_MDQ(log_data, r1, r2, r3, realPrecision, valueRangeSize, medianValue_f); 1950 tdps->minLogValue = min_log_data - 1.0001*realPrecision; 1951 free(log_data); 1952 if(!positive){ 1953 unsigned char * comp_signs; 1954 // compress signs 1955 unsigned long signSize = sz_lossless_compress(confparams_cpr->losslessCompressor, confparams_cpr->gzipMode, signs, dataLength, &comp_signs); 1956 tdps->pwrErrBoundBytes = comp_signs; 1957 tdps->pwrErrBoundBytes_size = signSize; 1958 } 1959 else{ 1960 tdps->pwrErrBoundBytes = NULL; 1961 tdps->pwrErrBoundBytes_size = 0; 1962 } 1963 free(signs); 1964 1965 convertTDPStoFlatBytes_float(tdps, newByteData, outSize); 1966 if(*outSize>dataLength*sizeof(float)) 1967 SZ_compress_args_float_StoreOriData(oriData, dataLength+2, tdps, newByteData, outSize); 1968 1969 free_TightDataPointStorageF(tdps); 1970 }
Note: See TracChangeset
for help on using the changeset viewer.