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