Changeset 9ee2ce3 for thirdparty/SZ/sz/src/dataCompression.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/dataCompression.c
r2c47b73 r9ee2ce3 67 67 { 68 68 unsigned int* data = (unsigned int*)oriData; 69 int data_;69 unsigned int data_; 70 70 min = data[0], max = min; 71 71 computeMinMax(data); … … 74 74 { 75 75 int* data = (int*)oriData; 76 unsignedint data_;76 int data_; 77 77 min = data[0], max = min; 78 78 computeMinMax(data); … … 596 596 return k; 597 597 } 598 599 //The following functions are float-precision version of dealing with the unpredictable data points 600 int generateLossyCoefficients_float(float* oriData, double precision, size_t nbEle, int* reqBytesLength, int* resiBitsLength, float* medianValue, float* decData) 601 { 602 float valueRangeSize; 603 604 computeRangeSize_float(oriData, nbEle, &valueRangeSize, medianValue); 605 short radExpo = getExponent_float(valueRangeSize/2); 606 607 int reqLength; 608 computeReqLength_float(precision, radExpo, &reqLength, medianValue); 609 610 *reqBytesLength = reqLength/8; 611 *resiBitsLength = reqLength%8; 612 613 size_t i = 0; 614 for(i = 0;i < nbEle;i++) 615 { 616 float normValue = oriData[i] - *medianValue; 617 618 lfloat lfBuf; 619 lfBuf.value = normValue; 620 621 int ignBytesLength = 32 - reqLength; 622 if(ignBytesLength<0) 623 ignBytesLength = 0; 624 625 lfBuf.ivalue = (lfBuf.ivalue >> ignBytesLength) << ignBytesLength; 626 627 //float tmpValue = lfBuf.value; 628 629 decData[i] = lfBuf.value + *medianValue; 630 } 631 return reqLength; 632 } 633 634 /** 635 * @param float* oriData: inplace argument (input / output) 636 * 637 * */ 638 int compressExactDataArray_float(float* oriData, double precision, size_t nbEle, unsigned char** leadArray, unsigned char** midArray, unsigned char** resiArray, 639 int reqLength, int reqBytesLength, int resiBitsLength, float medianValue) 640 { 641 //allocate memory for coefficient compression arrays 642 DynamicIntArray *exactLeadNumArray; 643 new_DIA(&exactLeadNumArray, DynArrayInitLen); 644 DynamicByteArray *exactMidByteArray; 645 new_DBA(&exactMidByteArray, DynArrayInitLen); 646 DynamicIntArray *resiBitArray; 647 new_DIA(&resiBitArray, DynArrayInitLen); 648 unsigned char preDataBytes[4] = {0,0,0,0}; 649 650 //allocate memory for vce and lce 651 FloatValueCompressElement *vce = (FloatValueCompressElement*)malloc(sizeof(FloatValueCompressElement)); 652 LossyCompressionElement *lce = (LossyCompressionElement*)malloc(sizeof(LossyCompressionElement)); 653 654 size_t i = 0; 655 for(i = 0;i < nbEle;i++) 656 { 657 compressSingleFloatValue(vce, oriData[i], precision, medianValue, reqLength, reqBytesLength, resiBitsLength); 658 updateLossyCompElement_Float(vce->curBytes, preDataBytes, reqBytesLength, resiBitsLength, lce); 659 memcpy(preDataBytes,vce->curBytes,4); 660 addExactData(exactMidByteArray, exactLeadNumArray, resiBitArray, lce); 661 oriData[i] = vce->data; 662 } 663 convertDIAtoInts(exactLeadNumArray, leadArray); 664 convertDBAtoBytes(exactMidByteArray,midArray); 665 convertDIAtoInts(resiBitArray, resiArray); 666 667 size_t midArraySize = exactMidByteArray->size; 668 669 free(vce); 670 free(lce); 671 672 free_DIA(exactLeadNumArray); 673 free_DBA(exactMidByteArray); 674 free_DIA(resiBitArray); 675 676 return midArraySize; 677 } 678 679 void decompressExactDataArray_float(unsigned char* leadNum, unsigned char* exactMidBytes, unsigned char* residualMidBits, size_t nbEle, int reqLength, float medianValue, float** decData) 680 { 681 *decData = (float*)malloc(nbEle*sizeof(float)); 682 size_t i = 0, j = 0, k = 0, l = 0, p = 0, curByteIndex = 0; 683 float exactData = 0; 684 unsigned char preBytes[4] = {0,0,0,0}; 685 unsigned char curBytes[4]; 686 int resiBits; 687 unsigned char leadingNum; 688 689 int reqBytesLength = reqLength/8; 690 int resiBitsLength = reqLength%8; 691 692 for(i = 0; i<nbEle;i++) 693 { 694 // compute resiBits 695 resiBits = 0; 696 if (resiBitsLength != 0) { 697 int kMod8 = k % 8; 698 int rightMovSteps = getRightMovingSteps(kMod8, resiBitsLength); 699 if (rightMovSteps > 0) { 700 int code = getRightMovingCode(kMod8, resiBitsLength); 701 resiBits = (residualMidBits[p] & code) >> rightMovSteps; 702 } else if (rightMovSteps < 0) { 703 int code1 = getLeftMovingCode(kMod8); 704 int code2 = getRightMovingCode(kMod8, resiBitsLength); 705 int leftMovSteps = -rightMovSteps; 706 rightMovSteps = 8 - leftMovSteps; 707 resiBits = (residualMidBits[p] & code1) << leftMovSteps; 708 p++; 709 resiBits = resiBits 710 | ((residualMidBits[p] & code2) >> rightMovSteps); 711 } else // rightMovSteps == 0 712 { 713 int code = getRightMovingCode(kMod8, resiBitsLength); 714 resiBits = (residualMidBits[p] & code); 715 p++; 716 } 717 k += resiBitsLength; 718 } 719 720 // recover the exact data 721 memset(curBytes, 0, 4); 722 leadingNum = leadNum[l++]; 723 memcpy(curBytes, preBytes, leadingNum); 724 for (j = leadingNum; j < reqBytesLength; j++) 725 curBytes[j] = exactMidBytes[curByteIndex++]; 726 if (resiBitsLength != 0) { 727 unsigned char resiByte = (unsigned char) (resiBits << (8 - resiBitsLength)); 728 curBytes[reqBytesLength] = resiByte; 729 } 730 731 exactData = bytesToFloat(curBytes); 732 (*decData)[i] = exactData + medianValue; 733 memcpy(preBytes,curBytes,4); 734 } 735 } 736 737 //double-precision version of dealing with unpredictable data points in sz 2.0 738 int generateLossyCoefficients_double(double* oriData, double precision, size_t nbEle, int* reqBytesLength, int* resiBitsLength, double* medianValue, double* decData) 739 { 740 double valueRangeSize; 741 742 computeRangeSize_double(oriData, nbEle, &valueRangeSize, medianValue); 743 short radExpo = getExponent_double(valueRangeSize/2); 744 745 int reqLength; 746 computeReqLength_double(precision, radExpo, &reqLength, medianValue); 747 748 *reqBytesLength = reqLength/8; 749 *resiBitsLength = reqLength%8; 750 751 size_t i = 0; 752 for(i = 0;i < nbEle;i++) 753 { 754 double normValue = oriData[i] - *medianValue; 755 756 ldouble ldBuf; 757 ldBuf.value = normValue; 758 759 int ignBytesLength = 64 - reqLength; 760 if(ignBytesLength<0) 761 ignBytesLength = 0; 762 763 ldBuf.lvalue = (ldBuf.lvalue >> ignBytesLength) << ignBytesLength; 764 765 decData[i] = ldBuf.value + *medianValue; 766 } 767 return reqLength; 768 } 769 770 /** 771 * @param double* oriData: inplace argument (input / output) 772 * 773 * */ 774 int compressExactDataArray_double(double* oriData, double precision, size_t nbEle, unsigned char** leadArray, unsigned char** midArray, unsigned char** resiArray, 775 int reqLength, int reqBytesLength, int resiBitsLength, double medianValue) 776 { 777 //allocate memory for coefficient compression arrays 778 DynamicIntArray *exactLeadNumArray; 779 new_DIA(&exactLeadNumArray, DynArrayInitLen); 780 DynamicByteArray *exactMidByteArray; 781 new_DBA(&exactMidByteArray, DynArrayInitLen); 782 DynamicIntArray *resiBitArray; 783 new_DIA(&resiBitArray, DynArrayInitLen); 784 unsigned char preDataBytes[8] = {0,0,0,0,0,0,0,0}; 785 786 //allocate memory for vce and lce 787 DoubleValueCompressElement *vce = (DoubleValueCompressElement*)malloc(sizeof(DoubleValueCompressElement)); 788 LossyCompressionElement *lce = (LossyCompressionElement*)malloc(sizeof(LossyCompressionElement)); 789 790 size_t i = 0; 791 for(i = 0;i < nbEle;i++) 792 { 793 compressSingleDoubleValue(vce, oriData[i], precision, medianValue, reqLength, reqBytesLength, resiBitsLength); 794 updateLossyCompElement_Double(vce->curBytes, preDataBytes, reqBytesLength, resiBitsLength, lce); 795 memcpy(preDataBytes,vce->curBytes,8); 796 addExactData(exactMidByteArray, exactLeadNumArray, resiBitArray, lce); 797 oriData[i] = vce->data; 798 } 799 convertDIAtoInts(exactLeadNumArray, leadArray); 800 convertDBAtoBytes(exactMidByteArray,midArray); 801 convertDIAtoInts(resiBitArray, resiArray); 802 803 size_t midArraySize = exactMidByteArray->size; 804 805 free(vce); 806 free(lce); 807 808 free_DIA(exactLeadNumArray); 809 free_DBA(exactMidByteArray); 810 free_DIA(resiBitArray); 811 812 return midArraySize; 813 } 814 815 void decompressExactDataArray_double(unsigned char* leadNum, unsigned char* exactMidBytes, unsigned char* residualMidBits, size_t nbEle, int reqLength, double medianValue, double** decData) 816 { 817 *decData = (double*)malloc(nbEle*sizeof(double)); 818 size_t i = 0, j = 0, k = 0, l = 0, p = 0, curByteIndex = 0; 819 double exactData = 0; 820 unsigned char preBytes[8] = {0,0,0,0,0,0,0,0}; 821 unsigned char curBytes[8]; 822 int resiBits; 823 unsigned char leadingNum; 824 825 int reqBytesLength = reqLength/8; 826 int resiBitsLength = reqLength%8; 827 828 for(i = 0; i<nbEle;i++) 829 { 830 // compute resiBits 831 resiBits = 0; 832 if (resiBitsLength != 0) { 833 int kMod8 = k % 8; 834 int rightMovSteps = getRightMovingSteps(kMod8, resiBitsLength); 835 if (rightMovSteps > 0) { 836 int code = getRightMovingCode(kMod8, resiBitsLength); 837 resiBits = (residualMidBits[p] & code) >> rightMovSteps; 838 } else if (rightMovSteps < 0) { 839 int code1 = getLeftMovingCode(kMod8); 840 int code2 = getRightMovingCode(kMod8, resiBitsLength); 841 int leftMovSteps = -rightMovSteps; 842 rightMovSteps = 8 - leftMovSteps; 843 resiBits = (residualMidBits[p] & code1) << leftMovSteps; 844 p++; 845 resiBits = resiBits 846 | ((residualMidBits[p] & code2) >> rightMovSteps); 847 } else // rightMovSteps == 0 848 { 849 int code = getRightMovingCode(kMod8, resiBitsLength); 850 resiBits = (residualMidBits[p] & code); 851 p++; 852 } 853 k += resiBitsLength; 854 } 855 856 // recover the exact data 857 memset(curBytes, 0, 8); 858 leadingNum = leadNum[l++]; 859 memcpy(curBytes, preBytes, leadingNum); 860 for (j = leadingNum; j < reqBytesLength; j++) 861 curBytes[j] = exactMidBytes[curByteIndex++]; 862 if (resiBitsLength != 0) { 863 unsigned char resiByte = (unsigned char) (resiBits << (8 - resiBitsLength)); 864 curBytes[reqBytesLength] = resiByte; 865 } 866 867 exactData = bytesToDouble(curBytes); 868 (*decData)[i] = exactData + medianValue; 869 memcpy(preBytes,curBytes,8); 870 } 871 }
Note: See TracChangeset
for help on using the changeset viewer.