1 | /** |
---|
2 | * @file szd_uint64.c |
---|
3 | * @author Sheng Di |
---|
4 | * @date Aug, 2017 |
---|
5 | * @brief |
---|
6 | * (C) 2016 by Mathematics and Computer Science (MCS), Argonne National Laboratory. |
---|
7 | * See COPYRIGHT in top-level directory. |
---|
8 | */ |
---|
9 | |
---|
10 | #include <stdlib.h> |
---|
11 | #include <stdio.h> |
---|
12 | #include <string.h> |
---|
13 | #include <math.h> |
---|
14 | #include "TightDataPointStorageI.h" |
---|
15 | #include "sz.h" |
---|
16 | #include "szd_uint64.h" |
---|
17 | #include "Huffman.h" |
---|
18 | #include "utility.h" |
---|
19 | |
---|
20 | /** |
---|
21 | * |
---|
22 | * |
---|
23 | * @return status SUCCESSFUL (SZ_SCES) or not (other error codes) f |
---|
24 | * */ |
---|
25 | int SZ_decompress_args_uint64(uint64_t** newData, size_t r5, size_t r4, size_t r3, size_t r2, size_t r1, unsigned char* cmpBytes, size_t cmpSize) |
---|
26 | { |
---|
27 | int status = SZ_SCES; |
---|
28 | size_t dataLength = computeDataLength(r5,r4,r3,r2,r1); |
---|
29 | |
---|
30 | //unsigned char* tmpBytes; |
---|
31 | size_t targetUncompressSize = dataLength <<2; //i.e., *4 |
---|
32 | //tmpSize must be "much" smaller than dataLength |
---|
33 | size_t i, tmpSize = 3+MetaDataByteLength+1+sizeof(uint64_t)+exe_params->SZ_SIZE_TYPE; |
---|
34 | unsigned char* szTmpBytes; |
---|
35 | |
---|
36 | if(cmpSize!=4+8+4+MetaDataByteLength && cmpSize!=4+8+8+MetaDataByteLength) |
---|
37 | { |
---|
38 | confparams_dec->losslessCompressor = is_lossless_compressed_data(cmpBytes, cmpSize); |
---|
39 | if(confparams_dec->losslessCompressor!=-1) |
---|
40 | confparams_dec->szMode = SZ_BEST_COMPRESSION; |
---|
41 | else |
---|
42 | confparams_dec->szMode = SZ_BEST_SPEED; |
---|
43 | if(confparams_dec->szMode==SZ_BEST_SPEED) |
---|
44 | { |
---|
45 | tmpSize = cmpSize; |
---|
46 | szTmpBytes = cmpBytes; |
---|
47 | } |
---|
48 | else if(confparams_dec->szMode==SZ_BEST_COMPRESSION || confparams_dec->szMode==SZ_DEFAULT_COMPRESSION) |
---|
49 | { |
---|
50 | if(targetUncompressSize<MIN_ZLIB_DEC_ALLOMEM_BYTES) //Considering the minimum size |
---|
51 | targetUncompressSize = MIN_ZLIB_DEC_ALLOMEM_BYTES; |
---|
52 | tmpSize = sz_lossless_decompress(confparams_dec->losslessCompressor, cmpBytes, (unsigned long)cmpSize, &szTmpBytes, (unsigned long)targetUncompressSize+4+MetaDataByteLength+exe_params->SZ_SIZE_TYPE);// (unsigned long)targetUncompressSize+8: consider the total length under lossless compression mode is actually 3+4+1+targetUncompressSize |
---|
53 | //szTmpBytes = (unsigned char*)malloc(sizeof(unsigned char)*tmpSize); |
---|
54 | //memcpy(szTmpBytes, tmpBytes, tmpSize); |
---|
55 | //free(tmpBytes); //release useless memory |
---|
56 | } |
---|
57 | else |
---|
58 | { |
---|
59 | printf("Wrong value of confparams_dec->szMode in the double compressed bytes.\n"); |
---|
60 | status = SZ_MERR; |
---|
61 | return status; |
---|
62 | } |
---|
63 | } |
---|
64 | else |
---|
65 | szTmpBytes = cmpBytes; |
---|
66 | //TODO: convert szTmpBytes to data array. |
---|
67 | TightDataPointStorageI* tdps; |
---|
68 | int errBoundMode = new_TightDataPointStorageI_fromFlatBytes(&tdps, szTmpBytes, tmpSize); |
---|
69 | //writeByteData(tdps->typeArray, tdps->typeArray_size, "decompress-typebytes.tbt"); |
---|
70 | int dim = computeDimension(r5,r4,r3,r2,r1); |
---|
71 | int intSize = sizeof(uint64_t); |
---|
72 | if(tdps->isLossless) |
---|
73 | { |
---|
74 | *newData = (uint64_t*)malloc(intSize*dataLength); |
---|
75 | if(sysEndianType==BIG_ENDIAN_SYSTEM) |
---|
76 | { |
---|
77 | memcpy(*newData, szTmpBytes+4+MetaDataByteLength+exe_params->SZ_SIZE_TYPE, dataLength*intSize); |
---|
78 | } |
---|
79 | else |
---|
80 | { |
---|
81 | unsigned char* p = szTmpBytes+4+MetaDataByteLength+exe_params->SZ_SIZE_TYPE; |
---|
82 | for(i=0;i<dataLength;i++,p+=intSize) |
---|
83 | (*newData)[i] = bytesToUInt64_bigEndian(p); |
---|
84 | } |
---|
85 | } |
---|
86 | else if (dim == 1) |
---|
87 | getSnapshotData_uint64_1D(newData,r1,tdps, errBoundMode); |
---|
88 | else |
---|
89 | if (dim == 2) |
---|
90 | getSnapshotData_uint64_2D(newData,r2,r1,tdps, errBoundMode); |
---|
91 | else |
---|
92 | if (dim == 3) |
---|
93 | getSnapshotData_uint64_3D(newData,r3,r2,r1,tdps, errBoundMode); |
---|
94 | else |
---|
95 | if (dim == 4) |
---|
96 | getSnapshotData_uint64_4D(newData,r4,r3,r2,r1,tdps, errBoundMode); |
---|
97 | else |
---|
98 | { |
---|
99 | printf("Error: currently support only at most 4 dimensions!\n"); |
---|
100 | status = SZ_DERR; |
---|
101 | } |
---|
102 | free_TightDataPointStorageI2(tdps); |
---|
103 | if(confparams_dec->szMode!=SZ_BEST_SPEED && cmpSize!=4+sizeof(uint64_t)+exe_params->SZ_SIZE_TYPE+MetaDataByteLength) |
---|
104 | free(szTmpBytes); |
---|
105 | return status; |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | void decompressDataSeries_uint64_1D(uint64_t** data, size_t dataSeriesLength, TightDataPointStorageI* tdps) |
---|
110 | { |
---|
111 | updateQuantizationInfo(tdps->intervals); |
---|
112 | size_t i; |
---|
113 | double interval = tdps->realPrecision*2; |
---|
114 | |
---|
115 | *data = (uint64_t*)malloc(sizeof(uint64_t)*dataSeriesLength); |
---|
116 | |
---|
117 | int* type = (int*)malloc(dataSeriesLength*sizeof(int)); |
---|
118 | |
---|
119 | HuffmanTree* huffmanTree = createHuffmanTree(tdps->stateNum); |
---|
120 | decode_withTree(huffmanTree, tdps->typeArray, dataSeriesLength, type); |
---|
121 | SZ_ReleaseHuffman(huffmanTree); |
---|
122 | |
---|
123 | //sdi:Debug |
---|
124 | //writeUShortData(type, dataSeriesLength, "decompressStateBytes.sb"); |
---|
125 | |
---|
126 | uint64_t minValue, exactData, predValue; |
---|
127 | |
---|
128 | minValue = tdps->minValue; |
---|
129 | |
---|
130 | int exactByteSize = tdps->exactByteSize; |
---|
131 | unsigned char* exactDataBytePointer = tdps->exactDataBytes; |
---|
132 | |
---|
133 | unsigned char curBytes[8] = {0,0,0,0,0,0,0,0}; |
---|
134 | |
---|
135 | int rightShiftBits = computeRightShiftBits(exactByteSize, SZ_UINT64); |
---|
136 | if(rightShiftBits<0) |
---|
137 | { |
---|
138 | printf("Error: rightShift < 0!\n"); |
---|
139 | exit(0); |
---|
140 | } |
---|
141 | int type_; |
---|
142 | for (i = 0; i < dataSeriesLength; i++) { |
---|
143 | type_ = type[i]; |
---|
144 | switch (type_) { |
---|
145 | case 0: |
---|
146 | // recover the exact data |
---|
147 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
148 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
149 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
150 | exactDataBytePointer += exactByteSize; |
---|
151 | (*data)[i] = exactData + minValue; |
---|
152 | break; |
---|
153 | default: |
---|
154 | //predValue = 2 * (*data)[i-1] - (*data)[i-2]; |
---|
155 | predValue = (*data)[i-1]; |
---|
156 | (*data)[i] = predValue + (type_-exe_params->intvRadius)*interval; |
---|
157 | break; |
---|
158 | } |
---|
159 | //printf("%.30G\n",(*data)[i]); |
---|
160 | } |
---|
161 | free(type); |
---|
162 | return; |
---|
163 | } |
---|
164 | |
---|
165 | void decompressDataSeries_uint64_2D(uint64_t** data, size_t r1, size_t r2, TightDataPointStorageI* tdps) |
---|
166 | { |
---|
167 | updateQuantizationInfo(tdps->intervals); |
---|
168 | //printf("tdps->intervals=%d, exe_params->intvRadius=%d\n", tdps->intervals, exe_params->intvRadius); |
---|
169 | |
---|
170 | size_t dataSeriesLength = r1*r2; |
---|
171 | // printf ("%d %d\n", r1, r2); |
---|
172 | |
---|
173 | double realPrecision = tdps->realPrecision; |
---|
174 | |
---|
175 | *data = (uint64_t*)malloc(sizeof(uint64_t)*dataSeriesLength); |
---|
176 | |
---|
177 | int* type = (int*)malloc(dataSeriesLength*sizeof(int)); |
---|
178 | |
---|
179 | HuffmanTree* huffmanTree = createHuffmanTree(tdps->stateNum); |
---|
180 | decode_withTree(huffmanTree, tdps->typeArray, dataSeriesLength, type); |
---|
181 | SZ_ReleaseHuffman(huffmanTree); |
---|
182 | |
---|
183 | uint64_t minValue, exactData; |
---|
184 | |
---|
185 | minValue = tdps->minValue; |
---|
186 | |
---|
187 | int exactByteSize = tdps->exactByteSize; |
---|
188 | unsigned char* exactDataBytePointer = tdps->exactDataBytes; |
---|
189 | |
---|
190 | unsigned char curBytes[8] = {0,0,0,0,0,0,0,0}; |
---|
191 | |
---|
192 | int rightShiftBits = computeRightShiftBits(exactByteSize, SZ_UINT64); |
---|
193 | |
---|
194 | uint64_t pred1D, pred2D; |
---|
195 | size_t ii, jj; |
---|
196 | |
---|
197 | /* Process Row-0, data 0 */ |
---|
198 | |
---|
199 | // recover the exact data |
---|
200 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
201 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
202 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
203 | exactDataBytePointer += exactByteSize; |
---|
204 | (*data)[0] = exactData + minValue; |
---|
205 | |
---|
206 | /* Process Row-0, data 1 */ |
---|
207 | int type_ = type[1]; |
---|
208 | if (type_ != 0) |
---|
209 | { |
---|
210 | pred1D = (*data)[0]; |
---|
211 | (*data)[1] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
212 | } |
---|
213 | else |
---|
214 | { |
---|
215 | // recover the exact data |
---|
216 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
217 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
218 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
219 | exactDataBytePointer += exactByteSize; |
---|
220 | (*data)[1] = exactData + minValue; |
---|
221 | } |
---|
222 | |
---|
223 | /* Process Row-0, data 2 --> data r2-1 */ |
---|
224 | for (jj = 2; jj < r2; jj++) |
---|
225 | { |
---|
226 | type_ = type[jj]; |
---|
227 | if (type_ != 0) |
---|
228 | { |
---|
229 | pred1D = 2*(*data)[jj-1] - (*data)[jj-2]; |
---|
230 | (*data)[jj] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
231 | } |
---|
232 | else |
---|
233 | { |
---|
234 | // recover the exact data |
---|
235 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
236 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
237 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
238 | exactDataBytePointer += exactByteSize; |
---|
239 | (*data)[jj] = exactData + minValue; |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | size_t index; |
---|
244 | /* Process Row-1 --> Row-r1-1 */ |
---|
245 | for (ii = 1; ii < r1; ii++) |
---|
246 | { |
---|
247 | /* Process row-ii data 0 */ |
---|
248 | index = ii*r2; |
---|
249 | |
---|
250 | type_ = type[index]; |
---|
251 | if (type_ != 0) |
---|
252 | { |
---|
253 | pred1D = (*data)[index-r2]; |
---|
254 | (*data)[index] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
255 | } |
---|
256 | else |
---|
257 | { |
---|
258 | // recover the exact data |
---|
259 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
260 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
261 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
262 | exactDataBytePointer += exactByteSize; |
---|
263 | (*data)[index] = exactData + minValue; |
---|
264 | } |
---|
265 | |
---|
266 | /* Process row-ii data 1 --> r2-1*/ |
---|
267 | for (jj = 1; jj < r2; jj++) |
---|
268 | { |
---|
269 | index = ii*r2+jj; |
---|
270 | pred2D = (*data)[index-1] + (*data)[index-r2] - (*data)[index-r2-1]; |
---|
271 | |
---|
272 | type_ = type[index]; |
---|
273 | if (type_ != 0) |
---|
274 | { |
---|
275 | (*data)[index] = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
276 | } |
---|
277 | else |
---|
278 | { |
---|
279 | // recover the exact data |
---|
280 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
281 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
282 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
283 | exactDataBytePointer += exactByteSize; |
---|
284 | (*data)[index] = exactData + minValue; |
---|
285 | } |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | free(type); |
---|
290 | return; |
---|
291 | } |
---|
292 | |
---|
293 | void decompressDataSeries_uint64_3D(uint64_t** data, size_t r1, size_t r2, size_t r3, TightDataPointStorageI* tdps) |
---|
294 | { |
---|
295 | updateQuantizationInfo(tdps->intervals); |
---|
296 | size_t dataSeriesLength = r1*r2*r3; |
---|
297 | size_t r23 = r2*r3; |
---|
298 | // printf ("%d %d %d\n", r1, r2, r3); |
---|
299 | double realPrecision = tdps->realPrecision; |
---|
300 | |
---|
301 | *data = (uint64_t*)malloc(sizeof(uint64_t)*dataSeriesLength); |
---|
302 | int* type = (int*)malloc(dataSeriesLength*sizeof(int)); |
---|
303 | |
---|
304 | HuffmanTree* huffmanTree = createHuffmanTree(tdps->stateNum); |
---|
305 | decode_withTree(huffmanTree, tdps->typeArray, dataSeriesLength, type); |
---|
306 | SZ_ReleaseHuffman(huffmanTree); |
---|
307 | |
---|
308 | uint64_t minValue, exactData; |
---|
309 | |
---|
310 | minValue = tdps->minValue; |
---|
311 | |
---|
312 | int exactByteSize = tdps->exactByteSize; |
---|
313 | unsigned char* exactDataBytePointer = tdps->exactDataBytes; |
---|
314 | |
---|
315 | unsigned char curBytes[8] = {0,0,0,0,0,0,0,0}; |
---|
316 | |
---|
317 | int rightShiftBits = computeRightShiftBits(exactByteSize, SZ_UINT64); |
---|
318 | |
---|
319 | uint64_t pred1D, pred2D, pred3D; |
---|
320 | size_t ii, jj, kk; |
---|
321 | |
---|
322 | /////////////////////////// Process layer-0 /////////////////////////// |
---|
323 | /* Process Row-0 data 0*/ |
---|
324 | |
---|
325 | // recover the exact data |
---|
326 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
327 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
328 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
329 | exactDataBytePointer += exactByteSize; |
---|
330 | (*data)[0] = exactData + minValue; |
---|
331 | |
---|
332 | /* Process Row-0, data 1 */ |
---|
333 | pred1D = (*data)[0]; |
---|
334 | |
---|
335 | int type_ = type[1]; |
---|
336 | if (type_ != 0) |
---|
337 | { |
---|
338 | (*data)[1] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
339 | } |
---|
340 | else |
---|
341 | { |
---|
342 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
343 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
344 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
345 | exactDataBytePointer += exactByteSize; |
---|
346 | (*data)[1] = exactData + minValue; |
---|
347 | } |
---|
348 | /* Process Row-0, data 2 --> data r3-1 */ |
---|
349 | for (jj = 2; jj < r3; jj++) |
---|
350 | { |
---|
351 | pred1D = 2*(*data)[jj-1] - (*data)[jj-2]; |
---|
352 | |
---|
353 | type_ = type[jj]; |
---|
354 | if (type_ != 0) |
---|
355 | { |
---|
356 | (*data)[jj] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
357 | } |
---|
358 | else |
---|
359 | { |
---|
360 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
361 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
362 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
363 | exactDataBytePointer += exactByteSize; |
---|
364 | (*data)[jj] = exactData + minValue; |
---|
365 | } |
---|
366 | } |
---|
367 | |
---|
368 | size_t index; |
---|
369 | /* Process Row-1 --> Row-r2-1 */ |
---|
370 | for (ii = 1; ii < r2; ii++) |
---|
371 | { |
---|
372 | /* Process row-ii data 0 */ |
---|
373 | index = ii*r3; |
---|
374 | pred1D = (*data)[index-r3]; |
---|
375 | |
---|
376 | type_ = type[index]; |
---|
377 | if (type_ != 0) |
---|
378 | { |
---|
379 | (*data)[index] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
380 | } |
---|
381 | else |
---|
382 | { |
---|
383 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
384 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
385 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
386 | exactDataBytePointer += exactByteSize; |
---|
387 | (*data)[index] = exactData + minValue; |
---|
388 | } |
---|
389 | |
---|
390 | /* Process row-ii data 1 --> r3-1*/ |
---|
391 | for (jj = 1; jj < r3; jj++) |
---|
392 | { |
---|
393 | index = ii*r3+jj; |
---|
394 | pred2D = (*data)[index-1] + (*data)[index-r3] - (*data)[index-r3-1]; |
---|
395 | |
---|
396 | type_ = type[index]; |
---|
397 | if (type_ != 0) |
---|
398 | { |
---|
399 | (*data)[index] = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
400 | } |
---|
401 | else |
---|
402 | { |
---|
403 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
404 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
405 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
406 | exactDataBytePointer += exactByteSize; |
---|
407 | (*data)[index] = exactData + minValue; |
---|
408 | } |
---|
409 | } |
---|
410 | } |
---|
411 | |
---|
412 | /////////////////////////// Process layer-1 --> layer-r1-1 /////////////////////////// |
---|
413 | |
---|
414 | for (kk = 1; kk < r1; kk++) |
---|
415 | { |
---|
416 | /* Process Row-0 data 0*/ |
---|
417 | index = kk*r23; |
---|
418 | pred1D = (*data)[index-r23]; |
---|
419 | |
---|
420 | type_ = type[index]; |
---|
421 | if (type_ != 0) |
---|
422 | { |
---|
423 | (*data)[index] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
424 | } |
---|
425 | else |
---|
426 | { |
---|
427 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
428 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
429 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
430 | exactDataBytePointer += exactByteSize; |
---|
431 | (*data)[index] = exactData + minValue; |
---|
432 | } |
---|
433 | |
---|
434 | /* Process Row-0 data 1 --> data r3-1 */ |
---|
435 | for (jj = 1; jj < r3; jj++) |
---|
436 | { |
---|
437 | index = kk*r23+jj; |
---|
438 | pred2D = (*data)[index-1] + (*data)[index-r23] - (*data)[index-r23-1]; |
---|
439 | |
---|
440 | type_ = type[index]; |
---|
441 | if (type_ != 0) |
---|
442 | { |
---|
443 | (*data)[index] = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
444 | } |
---|
445 | else |
---|
446 | { |
---|
447 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
448 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
449 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
450 | exactDataBytePointer += exactByteSize; |
---|
451 | (*data)[index] = exactData + minValue; |
---|
452 | } |
---|
453 | } |
---|
454 | |
---|
455 | /* Process Row-1 --> Row-r2-1 */ |
---|
456 | for (ii = 1; ii < r2; ii++) |
---|
457 | { |
---|
458 | /* Process Row-i data 0 */ |
---|
459 | index = kk*r23 + ii*r3; |
---|
460 | pred2D = (*data)[index-r3] + (*data)[index-r23] - (*data)[index-r23-r3]; |
---|
461 | |
---|
462 | type_ = type[index]; |
---|
463 | if (type_ != 0) |
---|
464 | { |
---|
465 | (*data)[index] = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
466 | } |
---|
467 | else |
---|
468 | { |
---|
469 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
470 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
471 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
472 | exactDataBytePointer += exactByteSize; |
---|
473 | (*data)[index] = exactData + minValue; |
---|
474 | } |
---|
475 | |
---|
476 | /* Process Row-i data 1 --> data r3-1 */ |
---|
477 | for (jj = 1; jj < r3; jj++) |
---|
478 | { |
---|
479 | index = kk*r23 + ii*r3 + jj; |
---|
480 | pred3D = (*data)[index-1] + (*data)[index-r3] + (*data)[index-r23] |
---|
481 | - (*data)[index-r3-1] - (*data)[index-r23-r3] - (*data)[index-r23-1] + (*data)[index-r23-r3-1]; |
---|
482 | |
---|
483 | type_ = type[index]; |
---|
484 | if (type_ != 0) |
---|
485 | { |
---|
486 | (*data)[index] = pred3D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
487 | } |
---|
488 | else |
---|
489 | { |
---|
490 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
491 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
492 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
493 | exactDataBytePointer += exactByteSize; |
---|
494 | (*data)[index] = exactData + minValue; |
---|
495 | } |
---|
496 | } |
---|
497 | } |
---|
498 | } |
---|
499 | |
---|
500 | free(type); |
---|
501 | return; |
---|
502 | } |
---|
503 | |
---|
504 | |
---|
505 | void decompressDataSeries_uint64_4D(uint64_t** data, size_t r1, size_t r2, size_t r3, size_t r4, TightDataPointStorageI* tdps) |
---|
506 | { |
---|
507 | updateQuantizationInfo(tdps->intervals); |
---|
508 | size_t dataSeriesLength = r1*r2*r3*r4; |
---|
509 | size_t r234 = r2*r3*r4; |
---|
510 | size_t r34 = r3*r4; |
---|
511 | |
---|
512 | double realPrecision = tdps->realPrecision; |
---|
513 | |
---|
514 | *data = (uint64_t*)malloc(sizeof(uint64_t)*dataSeriesLength); |
---|
515 | int* type = (int*)malloc(dataSeriesLength*sizeof(int)); |
---|
516 | |
---|
517 | HuffmanTree* huffmanTree = createHuffmanTree(tdps->stateNum); |
---|
518 | decode_withTree(huffmanTree, tdps->typeArray, dataSeriesLength, type); |
---|
519 | SZ_ReleaseHuffman(huffmanTree); |
---|
520 | |
---|
521 | uint64_t minValue, exactData; |
---|
522 | |
---|
523 | minValue = tdps->minValue; |
---|
524 | |
---|
525 | int exactByteSize = tdps->exactByteSize; |
---|
526 | unsigned char* exactDataBytePointer = tdps->exactDataBytes; |
---|
527 | |
---|
528 | unsigned char curBytes[8] = {0,0,0,0,0,0,0,0}; |
---|
529 | |
---|
530 | int rightShiftBits = computeRightShiftBits(exactByteSize, SZ_UINT64); |
---|
531 | |
---|
532 | int type_; |
---|
533 | |
---|
534 | uint64_t pred1D, pred2D, pred3D; |
---|
535 | size_t ii, jj, kk, ll; |
---|
536 | size_t index; |
---|
537 | |
---|
538 | for (ll = 0; ll < r1; ll++) |
---|
539 | { |
---|
540 | /////////////////////////// Process layer-0 /////////////////////////// |
---|
541 | /* Process Row-0 data 0*/ |
---|
542 | index = ll*r234; |
---|
543 | |
---|
544 | // recover the exact data |
---|
545 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
546 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
547 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
548 | exactDataBytePointer += exactByteSize; |
---|
549 | (*data)[index] = exactData + minValue; |
---|
550 | |
---|
551 | /* Process Row-0, data 1 */ |
---|
552 | index = ll*r234+1; |
---|
553 | |
---|
554 | pred1D = (*data)[index-1]; |
---|
555 | |
---|
556 | type_ = type[index]; |
---|
557 | if (type_ != 0) |
---|
558 | { |
---|
559 | (*data)[index] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
560 | } |
---|
561 | else |
---|
562 | { |
---|
563 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
564 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
565 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
566 | exactDataBytePointer += exactByteSize; |
---|
567 | (*data)[index] = exactData + minValue; |
---|
568 | } |
---|
569 | |
---|
570 | /* Process Row-0, data 2 --> data r4-1 */ |
---|
571 | for (jj = 2; jj < r4; jj++) |
---|
572 | { |
---|
573 | index = ll*r234+jj; |
---|
574 | |
---|
575 | pred1D = 2*(*data)[index-1] - (*data)[index-2]; |
---|
576 | |
---|
577 | type_ = type[index]; |
---|
578 | if (type_ != 0) |
---|
579 | { |
---|
580 | (*data)[index] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
581 | } |
---|
582 | else |
---|
583 | { |
---|
584 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
585 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
586 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
587 | exactDataBytePointer += exactByteSize; |
---|
588 | (*data)[index] = exactData + minValue; |
---|
589 | } |
---|
590 | } |
---|
591 | |
---|
592 | /* Process Row-1 --> Row-r3-1 */ |
---|
593 | for (ii = 1; ii < r3; ii++) |
---|
594 | { |
---|
595 | /* Process row-ii data 0 */ |
---|
596 | index = ll*r234+ii*r4; |
---|
597 | |
---|
598 | pred1D = (*data)[index-r4]; |
---|
599 | |
---|
600 | type_ = type[index]; |
---|
601 | if (type_ != 0) |
---|
602 | { |
---|
603 | (*data)[index] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
604 | } |
---|
605 | else |
---|
606 | { |
---|
607 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
608 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
609 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
610 | exactDataBytePointer += exactByteSize; |
---|
611 | (*data)[index] = exactData + minValue; |
---|
612 | } |
---|
613 | |
---|
614 | /* Process row-ii data 1 --> r4-1*/ |
---|
615 | for (jj = 1; jj < r4; jj++) |
---|
616 | { |
---|
617 | index = ll*r234+ii*r4+jj; |
---|
618 | |
---|
619 | pred2D = (*data)[index-1] + (*data)[index-r4] - (*data)[index-r4-1]; |
---|
620 | |
---|
621 | type_ = type[index]; |
---|
622 | if (type_ != 0) |
---|
623 | { |
---|
624 | (*data)[index] = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
625 | } |
---|
626 | else |
---|
627 | { |
---|
628 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
629 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
630 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
631 | exactDataBytePointer += exactByteSize; |
---|
632 | (*data)[index] = exactData + minValue; |
---|
633 | } |
---|
634 | } |
---|
635 | } |
---|
636 | |
---|
637 | /////////////////////////// Process layer-1 --> layer-r2-1 /////////////////////////// |
---|
638 | |
---|
639 | for (kk = 1; kk < r2; kk++) |
---|
640 | { |
---|
641 | /* Process Row-0 data 0*/ |
---|
642 | index = ll*r234+kk*r34; |
---|
643 | |
---|
644 | pred1D = (*data)[index-r34]; |
---|
645 | |
---|
646 | type_ = type[index]; |
---|
647 | if (type_ != 0) |
---|
648 | { |
---|
649 | (*data)[index] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
650 | } |
---|
651 | else |
---|
652 | { |
---|
653 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
654 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
655 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
656 | exactDataBytePointer += exactByteSize; |
---|
657 | (*data)[index] = exactData + minValue; |
---|
658 | } |
---|
659 | |
---|
660 | /* Process Row-0 data 1 --> data r4-1 */ |
---|
661 | for (jj = 1; jj < r4; jj++) |
---|
662 | { |
---|
663 | index = ll*r234+kk*r34+jj; |
---|
664 | |
---|
665 | pred2D = (*data)[index-1] + (*data)[index-r34] - (*data)[index-r34-1]; |
---|
666 | |
---|
667 | type_ = type[index]; |
---|
668 | if (type_ != 0) |
---|
669 | { |
---|
670 | (*data)[index] = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
671 | } |
---|
672 | else |
---|
673 | { |
---|
674 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
675 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
676 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
677 | exactDataBytePointer += exactByteSize; |
---|
678 | (*data)[index] = exactData + minValue; |
---|
679 | } |
---|
680 | } |
---|
681 | |
---|
682 | /* Process Row-1 --> Row-r3-1 */ |
---|
683 | for (ii = 1; ii < r3; ii++) |
---|
684 | { |
---|
685 | /* Process Row-i data 0 */ |
---|
686 | index = ll*r234+kk*r34+ii*r4; |
---|
687 | |
---|
688 | pred2D = (*data)[index-r4] + (*data)[index-r34] - (*data)[index-r34-r4]; |
---|
689 | |
---|
690 | type_ = type[index]; |
---|
691 | if (type_ != 0) |
---|
692 | { |
---|
693 | (*data)[index] = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
694 | } |
---|
695 | else |
---|
696 | { |
---|
697 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
698 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
699 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
700 | exactDataBytePointer += exactByteSize; |
---|
701 | (*data)[index] = exactData + minValue; |
---|
702 | } |
---|
703 | |
---|
704 | /* Process Row-i data 1 --> data r4-1 */ |
---|
705 | for (jj = 1; jj < r4; jj++) |
---|
706 | { |
---|
707 | index = ll*r234+kk*r34+ii*r4+jj; |
---|
708 | |
---|
709 | pred3D = (*data)[index-1] + (*data)[index-r4] + (*data)[index-r34] |
---|
710 | - (*data)[index-r4-1] - (*data)[index-r34-r4] - (*data)[index-r34-1] + (*data)[index-r34-r4-1]; |
---|
711 | |
---|
712 | |
---|
713 | type_ = type[index]; |
---|
714 | if (type_ != 0) |
---|
715 | { |
---|
716 | (*data)[index] = pred3D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
717 | } |
---|
718 | else |
---|
719 | { |
---|
720 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
721 | exactData = bytesToUInt64_bigEndian(curBytes); |
---|
722 | exactData = (uint64_t)exactData >> rightShiftBits; |
---|
723 | exactDataBytePointer += exactByteSize; |
---|
724 | (*data)[index] = exactData + minValue; |
---|
725 | } |
---|
726 | } |
---|
727 | } |
---|
728 | } |
---|
729 | } |
---|
730 | |
---|
731 | free(type); |
---|
732 | return; |
---|
733 | } |
---|
734 | |
---|
735 | void getSnapshotData_uint64_1D(uint64_t** data, size_t dataSeriesLength, TightDataPointStorageI* tdps, int errBoundMode) |
---|
736 | { |
---|
737 | size_t i; |
---|
738 | |
---|
739 | if (tdps->allSameData) { |
---|
740 | uint64_t value = bytesToUInt64_bigEndian(tdps->exactDataBytes); |
---|
741 | *data = (uint64_t*)malloc(sizeof(uint64_t)*dataSeriesLength); |
---|
742 | for (i = 0; i < dataSeriesLength; i++) |
---|
743 | (*data)[i] = value; |
---|
744 | } else { |
---|
745 | decompressDataSeries_uint64_1D(data, dataSeriesLength, tdps); |
---|
746 | } |
---|
747 | } |
---|
748 | |
---|
749 | void getSnapshotData_uint64_2D(uint64_t** data, size_t r1, size_t r2, TightDataPointStorageI* tdps, int errBoundMode) |
---|
750 | { |
---|
751 | size_t i; |
---|
752 | size_t dataSeriesLength = r1*r2; |
---|
753 | if (tdps->allSameData) { |
---|
754 | uint64_t value = bytesToUInt64_bigEndian(tdps->exactDataBytes); |
---|
755 | *data = (uint64_t*)malloc(sizeof(uint64_t)*dataSeriesLength); |
---|
756 | for (i = 0; i < dataSeriesLength; i++) |
---|
757 | (*data)[i] = value; |
---|
758 | } else { |
---|
759 | decompressDataSeries_uint64_2D(data, r1, r2, tdps); |
---|
760 | } |
---|
761 | } |
---|
762 | |
---|
763 | void getSnapshotData_uint64_3D(uint64_t** data, size_t r1, size_t r2, size_t r3, TightDataPointStorageI* tdps, int errBoundMode) |
---|
764 | { |
---|
765 | size_t i; |
---|
766 | size_t dataSeriesLength = r1*r2*r3; |
---|
767 | if (tdps->allSameData) { |
---|
768 | uint64_t value = bytesToUInt64_bigEndian(tdps->exactDataBytes); |
---|
769 | *data = (uint64_t*)malloc(sizeof(uint64_t)*dataSeriesLength); |
---|
770 | for (i = 0; i < dataSeriesLength; i++) |
---|
771 | (*data)[i] = value; |
---|
772 | } else { |
---|
773 | decompressDataSeries_uint64_3D(data, r1, r2, r3, tdps); |
---|
774 | } |
---|
775 | } |
---|
776 | |
---|
777 | void getSnapshotData_uint64_4D(uint64_t** data, size_t r1, size_t r2, size_t r3, size_t r4, TightDataPointStorageI* tdps, int errBoundMode) |
---|
778 | { |
---|
779 | size_t i; |
---|
780 | size_t dataSeriesLength = r1*r2*r3*r4; |
---|
781 | if (tdps->allSameData) { |
---|
782 | uint64_t value = bytesToUInt64_bigEndian(tdps->exactDataBytes); |
---|
783 | *data = (uint64_t*)malloc(sizeof(uint64_t)*dataSeriesLength); |
---|
784 | for (i = 0; i < dataSeriesLength; i++) |
---|
785 | (*data)[i] = value; |
---|
786 | } else { |
---|
787 | decompressDataSeries_uint64_4D(data, r1, r2, r3, r4, tdps); |
---|
788 | } |
---|
789 | } |
---|