Changeset 9ee2ce3 for thirdparty/SZ/sz/src/sz_double_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_double_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_double_1D(double *oriData, size_t dataLength, double* pwrErrBound, unsigned char* pwrErrBoundBytes, double globalPrecision) … … 1773 1774 free_TightDataPointStorageD(tdps); 1774 1775 } 1776 1777 #include <stdbool.h> 1778 1779 void SZ_compress_args_double_NoCkRngeNoGzip_1D_pwr_pre_log(unsigned char** newByteData, double *oriData, double pwrErrRatio, size_t dataLength, size_t *outSize, double min, double max){ 1780 1781 double * log_data = (double *) malloc(dataLength * sizeof(double)); 1782 1783 unsigned char * signs = (unsigned char *) malloc(dataLength); 1784 memset(signs, 0, dataLength); 1785 // preprocess 1786 double max_abs_log_data; 1787 if(min == 0) max_abs_log_data = fabs(log2(fabs(max))); 1788 else if(max == 0) max_abs_log_data = fabs(log2(fabs(min))); 1789 else max_abs_log_data = fabs(log2(fabs(min))) > fabs(log2(fabs(max))) ? fabs(log2(fabs(min))) : fabs(log2(fabs(max))); 1790 double min_log_data = max_abs_log_data; 1791 bool positive = true; 1792 for(size_t i=0; i<dataLength; i++){ 1793 if(oriData[i] < 0){ 1794 signs[i] = 1; 1795 log_data[i] = -oriData[i]; 1796 positive = false; 1797 } 1798 else 1799 log_data[i] = oriData[i]; 1800 if(log_data[i] > 0){ 1801 log_data[i] = log2(log_data[i]); 1802 if(log_data[i] > max_abs_log_data) max_abs_log_data = log_data[i]; 1803 if(log_data[i] < min_log_data) min_log_data = log_data[i]; 1804 } 1805 } 1806 1807 double valueRangeSize, medianValue_f; 1808 computeRangeSize_double(log_data, dataLength, &valueRangeSize, &medianValue_f); 1809 if(fabs(min_log_data) > max_abs_log_data) max_abs_log_data = fabs(min_log_data); 1810 double realPrecision = log2(1.0 + pwrErrRatio) - max_abs_log_data * 2.23e-16; 1811 for(size_t i=0; i<dataLength; i++){ 1812 if(oriData[i] == 0){ 1813 log_data[i] = min_log_data - 2.0001*realPrecision; 1814 } 1815 } 1816 TightDataPointStorageD* tdps = SZ_compress_double_1D_MDQ(log_data, dataLength, realPrecision, valueRangeSize, medianValue_f); 1817 tdps->minLogValue = min_log_data - 1.0001*realPrecision; 1818 free(log_data); 1819 if(!positive){ 1820 unsigned char * comp_signs; 1821 // compress signs 1822 unsigned long signSize = sz_lossless_compress(confparams_cpr->losslessCompressor, confparams_cpr->gzipMode, signs, dataLength, &comp_signs); 1823 tdps->pwrErrBoundBytes = comp_signs; 1824 tdps->pwrErrBoundBytes_size = signSize; 1825 } 1826 else{ 1827 tdps->pwrErrBoundBytes = NULL; 1828 tdps->pwrErrBoundBytes_size = 0; 1829 } 1830 free(signs); 1831 1832 convertTDPStoFlatBytes_double(tdps, newByteData, outSize); 1833 if(*outSize>dataLength*sizeof(double)) 1834 SZ_compress_args_double_StoreOriData(oriData, dataLength+2, tdps, newByteData, outSize); 1835 1836 free_TightDataPointStorageD(tdps); 1837 } 1838 1839 void SZ_compress_args_double_NoCkRngeNoGzip_2D_pwr_pre_log(unsigned char** newByteData, double *oriData, double pwrErrRatio, size_t r1, size_t r2, size_t *outSize, double min, double max){ 1840 1841 size_t dataLength = r1 * r2; 1842 double * log_data = (double *) malloc(dataLength * sizeof(double)); 1843 1844 unsigned char * signs = (unsigned char *) malloc(dataLength); 1845 memset(signs, 0, dataLength); 1846 // preprocess 1847 double max_abs_log_data; 1848 if(min == 0) max_abs_log_data = fabs(log2(fabs(max))); 1849 else if(max == 0) max_abs_log_data = fabs(log2(fabs(min))); 1850 else max_abs_log_data = fabs(log2(fabs(min))) > fabs(log2(fabs(max))) ? fabs(log2(fabs(min))) : fabs(log2(fabs(max))); 1851 double min_log_data = max_abs_log_data; 1852 bool positive = true; 1853 for(size_t i=0; i<dataLength; i++){ 1854 if(oriData[i] < 0){ 1855 signs[i] = 1; 1856 log_data[i] = -oriData[i]; 1857 positive = false; 1858 } 1859 else 1860 log_data[i] = oriData[i]; 1861 if(log_data[i] > 0){ 1862 log_data[i] = log2(log_data[i]); 1863 if(log_data[i] > max_abs_log_data) max_abs_log_data = log_data[i]; 1864 if(log_data[i] < min_log_data) min_log_data = log_data[i]; 1865 } 1866 } 1867 1868 double valueRangeSize, medianValue_f; 1869 computeRangeSize_double(log_data, dataLength, &valueRangeSize, &medianValue_f); 1870 if(fabs(min_log_data) > max_abs_log_data) max_abs_log_data = fabs(min_log_data); 1871 double realPrecision = log2(1.0 + pwrErrRatio) - max_abs_log_data * 2.23e-16; 1872 for(size_t i=0; i<dataLength; i++){ 1873 if(oriData[i] == 0){ 1874 log_data[i] = min_log_data - 2.0001*realPrecision; 1875 } 1876 } 1877 TightDataPointStorageD* tdps = SZ_compress_double_2D_MDQ(log_data, r1, r2, realPrecision, valueRangeSize, medianValue_f); 1878 tdps->minLogValue = min_log_data - 1.0001*realPrecision; 1879 free(log_data); 1880 1881 if(!positive){ 1882 unsigned char * comp_signs; 1883 // compress signs 1884 unsigned long signSize = sz_lossless_compress(confparams_cpr->losslessCompressor, confparams_cpr->gzipMode, signs, dataLength, &comp_signs); 1885 tdps->pwrErrBoundBytes = comp_signs; 1886 tdps->pwrErrBoundBytes_size = signSize; 1887 } 1888 else{ 1889 tdps->pwrErrBoundBytes = NULL; 1890 tdps->pwrErrBoundBytes_size = 0; 1891 } 1892 free(signs); 1893 1894 convertTDPStoFlatBytes_double(tdps, newByteData, outSize); 1895 if(*outSize>dataLength*sizeof(double)) 1896 SZ_compress_args_double_StoreOriData(oriData, dataLength+2, tdps, newByteData, outSize); 1897 1898 free_TightDataPointStorageD(tdps); 1899 } 1900 1901 void SZ_compress_args_double_NoCkRngeNoGzip_3D_pwr_pre_log(unsigned char** newByteData, double *oriData, double pwrErrRatio, size_t r1, size_t r2, size_t r3, size_t *outSize, double min, double max){ 1902 1903 size_t dataLength = r1 * r2 * r3; 1904 double * log_data = (double *) malloc(dataLength * sizeof(double)); 1905 1906 unsigned char * signs = (unsigned char *) malloc(dataLength); 1907 memset(signs, 0, dataLength); 1908 // preprocess 1909 double max_abs_log_data; 1910 if(min == 0) max_abs_log_data = fabs(log2(fabs(max))); 1911 else if(max == 0) max_abs_log_data = fabs(log2(fabs(min))); 1912 else max_abs_log_data = fabs(log2(fabs(min))) > fabs(log2(fabs(max))) ? fabs(log2(fabs(min))) : fabs(log2(fabs(max))); 1913 double min_log_data = max_abs_log_data; 1914 bool positive = true; 1915 for(size_t i=0; i<dataLength; i++){ 1916 if(oriData[i] < 0){ 1917 signs[i] = 1; 1918 log_data[i] = -oriData[i]; 1919 positive = false; 1920 } 1921 else 1922 log_data[i] = oriData[i]; 1923 if(log_data[i] > 0){ 1924 log_data[i] = log2(log_data[i]); 1925 if(log_data[i] > max_abs_log_data) max_abs_log_data = log_data[i]; 1926 if(log_data[i] < min_log_data) min_log_data = log_data[i]; 1927 } 1928 } 1929 1930 double valueRangeSize, medianValue_f; 1931 computeRangeSize_double(log_data, dataLength, &valueRangeSize, &medianValue_f); 1932 if(fabs(min_log_data) > max_abs_log_data) max_abs_log_data = fabs(min_log_data); 1933 double realPrecision = log2(1.0 + pwrErrRatio) - max_abs_log_data * 2.23e-16; 1934 for(size_t i=0; i<dataLength; i++){ 1935 if(oriData[i] == 0){ 1936 log_data[i] = min_log_data - 2.0001*realPrecision; 1937 } 1938 } 1939 TightDataPointStorageD* tdps = SZ_compress_double_3D_MDQ(log_data, r1, r2, r3, realPrecision, valueRangeSize, medianValue_f); 1940 tdps->minLogValue = min_log_data - 1.0001*realPrecision; 1941 free(log_data); 1942 if(!positive){ 1943 unsigned char * comp_signs; 1944 // compress signs 1945 unsigned long signSize = sz_lossless_compress(confparams_cpr->losslessCompressor, confparams_cpr->gzipMode, signs, dataLength, &comp_signs); 1946 tdps->pwrErrBoundBytes = comp_signs; 1947 tdps->pwrErrBoundBytes_size = signSize; 1948 } 1949 else{ 1950 tdps->pwrErrBoundBytes = NULL; 1951 tdps->pwrErrBoundBytes_size = 0; 1952 } 1953 free(signs); 1954 1955 convertTDPStoFlatBytes_double(tdps, newByteData, outSize); 1956 if(*outSize>dataLength*sizeof(double)) 1957 SZ_compress_args_double_StoreOriData(oriData, dataLength+2, tdps, newByteData, outSize); 1958 1959 free_TightDataPointStorageD(tdps); 1960 }
Note: See TracChangeset
for help on using the changeset viewer.