pysz 0.0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pysz-0.0.7/PKG-INFO ADDED
@@ -0,0 +1,96 @@
1
+ Metadata-Version: 2.1
2
+ Name: pysz
3
+ Version: 0.0.7
4
+ Summary: A python wrapper for the SZ3 compression library
5
+ Author-email: Zhuoxun Yang <jason.neptune.yang@gmail.com>
6
+ Project-URL: Homepage, https://github.com/JasonYang60/pysz
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: BSD License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+
13
+ # pysz
14
+ A user-friendly and easy-to-maintain python wrapper for SZ3 using a python-to-c package Cython>=3.0.10.\
15
+ Pysz is fully based on SZ3(https://github.com/szcompressor/SZ3). The pure SZ3 C++ library is incorporated into pysz interface through Cython, so the compression && decompression function is running much faster than Python code.
16
+
17
+
18
+ ## How to use pysz
19
+ We provided a test code in `./test/test.py` as shown below:
20
+ ```python
21
+ from pysz import sz
22
+
23
+ # setup configuration of compression
24
+ dim = (101, 203869, 3)
25
+ compressor = sz.sz(*dim)
26
+ filename = 'traj_xyz.dat'
27
+ datatype = 'float'
28
+
29
+ # compression
30
+ cmpData3, cmp_ratio_2 = compressor.compress(datatype, 'sz3.config', filename)
31
+
32
+ # decompression
33
+ decmpData2 = compressor.decompress(datatype, 'sz3.config', filename + '.sz')
34
+
35
+ # verification
36
+ compressor.verify(datatype, 'sz3.config', filename, filename + '.sz')
37
+ ```
38
+ The input data can either be the file path to the data file or numpy array contain the data.
39
+ ## Requirements
40
+ Python>=3.10
41
+
42
+ ## Installation
43
+
44
+ ### Method 1. install from .whl
45
+ If you are running a linux system and using x86 or x64 CPU platform, pysz can be installed directly from a pre-compiled `.whl` file(eg. `pysz-0.0.2-cp312-cp312-linux_x86_64.whl`) located in `./dist/`.
46
+ ```bash
47
+ git clone https://github.com/JasonYang60/pysz.git
48
+ cd pysz
49
+ mv ./dist/pysz-0.0.2-cp312-cp312-linux_x86_64.whl ./
50
+ pip install pysz-0.0.2-cp312-cp312-linux_x86_64.whl
51
+ ```
52
+ ### Method 2. local compilation
53
+ According to your system && CPU platform, if a coresponding `.whl` is absent, you should compile pysz locally.\
54
+ First, Make sure cmake && gcc installed.\
55
+ Pysz uses python-to-c package Cython>=3.0.10, so what `setup.py` does includes downloading c++ source code from github and automatically applying cmake && make command to finish c++ code compilation.\
56
+ Then
57
+ ```bash
58
+ pip install .
59
+ ```
60
+
61
+ #### Generate pre-compiled .whl and .tar.gz file
62
+ To pack this project up with .whl file, some python setup tool package (`wheel`, `build`) and are required.
63
+ ```bash
64
+ pip install wheel
65
+ pip install build
66
+ ```
67
+ Run following code to generate `.whl` and `.tar.gz` in `./dist`:
68
+ ```bash
69
+ python -m build
70
+ ```
71
+ tip: there is still some issues remaining to be fixed. This command will also work:
72
+ ```bash
73
+ python setup.py sdist bdist_wheel
74
+ ```
75
+ ### Method 3. install from Pypi
76
+ ```bash
77
+ pip install pysz
78
+ ```
79
+
80
+ ## Launch in docker
81
+
82
+ Dockerfile is provided for testing.
83
+ ```bash
84
+ docker build --name pysz .
85
+ docker run -it --name pysz_container pysz /bin/bash
86
+ ```
87
+ Then in container shell:
88
+ ```bash
89
+ pip install .
90
+ cd test
91
+ python ./test.py
92
+ ```
93
+
94
+ ## TODO list:
95
+ to test openMP and other utils && features \
96
+ more data types to be supported
pysz-0.0.7/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # pysz
2
+ A user-friendly and easy-to-maintain python wrapper for SZ3 using a python-to-c package Cython>=3.0.10.\
3
+ Pysz is fully based on SZ3(https://github.com/szcompressor/SZ3). The pure SZ3 C++ library is incorporated into pysz interface through Cython, so the compression && decompression function is running much faster than Python code.
4
+
5
+
6
+ ## How to use pysz
7
+ We provided a test code in `./test/test.py` as shown below:
8
+ ```python
9
+ from pysz import sz
10
+
11
+ # setup configuration of compression
12
+ dim = (101, 203869, 3)
13
+ compressor = sz.sz(*dim)
14
+ filename = 'traj_xyz.dat'
15
+ datatype = 'float'
16
+
17
+ # compression
18
+ cmpData3, cmp_ratio_2 = compressor.compress(datatype, 'sz3.config', filename)
19
+
20
+ # decompression
21
+ decmpData2 = compressor.decompress(datatype, 'sz3.config', filename + '.sz')
22
+
23
+ # verification
24
+ compressor.verify(datatype, 'sz3.config', filename, filename + '.sz')
25
+ ```
26
+ The input data can either be the file path to the data file or numpy array contain the data.
27
+ ## Requirements
28
+ Python>=3.10
29
+
30
+ ## Installation
31
+
32
+ ### Method 1. install from .whl
33
+ If you are running a linux system and using x86 or x64 CPU platform, pysz can be installed directly from a pre-compiled `.whl` file(eg. `pysz-0.0.2-cp312-cp312-linux_x86_64.whl`) located in `./dist/`.
34
+ ```bash
35
+ git clone https://github.com/JasonYang60/pysz.git
36
+ cd pysz
37
+ mv ./dist/pysz-0.0.2-cp312-cp312-linux_x86_64.whl ./
38
+ pip install pysz-0.0.2-cp312-cp312-linux_x86_64.whl
39
+ ```
40
+ ### Method 2. local compilation
41
+ According to your system && CPU platform, if a coresponding `.whl` is absent, you should compile pysz locally.\
42
+ First, Make sure cmake && gcc installed.\
43
+ Pysz uses python-to-c package Cython>=3.0.10, so what `setup.py` does includes downloading c++ source code from github and automatically applying cmake && make command to finish c++ code compilation.\
44
+ Then
45
+ ```bash
46
+ pip install .
47
+ ```
48
+
49
+ #### Generate pre-compiled .whl and .tar.gz file
50
+ To pack this project up with .whl file, some python setup tool package (`wheel`, `build`) and are required.
51
+ ```bash
52
+ pip install wheel
53
+ pip install build
54
+ ```
55
+ Run following code to generate `.whl` and `.tar.gz` in `./dist`:
56
+ ```bash
57
+ python -m build
58
+ ```
59
+ tip: there is still some issues remaining to be fixed. This command will also work:
60
+ ```bash
61
+ python setup.py sdist bdist_wheel
62
+ ```
63
+ ### Method 3. install from Pypi
64
+ ```bash
65
+ pip install pysz
66
+ ```
67
+
68
+ ## Launch in docker
69
+
70
+ Dockerfile is provided for testing.
71
+ ```bash
72
+ docker build --name pysz .
73
+ docker run -it --name pysz_container pysz /bin/bash
74
+ ```
75
+ Then in container shell:
76
+ ```bash
77
+ pip install .
78
+ cd test
79
+ python ./test.py
80
+ ```
81
+
82
+ ## TODO list:
83
+ to test openMP and other utils && features \
84
+ more data types to be supported
@@ -0,0 +1,145 @@
1
+ #ifndef SZ3_SZ_HPP
2
+ #define SZ3_SZ_HPP
3
+
4
+
5
+ #include "SZ3/api/impl/SZImpl.hpp"
6
+ #include "SZ3/version.hpp"
7
+ #include <memory>
8
+
9
+ /**
10
+ * API for compression
11
+ * @tparam T source data type
12
+ * @param config compression configuration. Please update the config with 1). data dimension and shape and 2). desired settings.
13
+ * @param data source data
14
+ * @param cmpSize compressed data size in bytes
15
+ * @return compressed data, remember to 'delete []' when the data is no longer needed.
16
+
17
+ The compression algorithms are:
18
+ ALGO_INTERP_LORENZO:
19
+ The default algorithm in SZ3. It is the implementation of our ICDE'21 paper.
20
+ The whole dataset will be compressed by interpolation or lorenzo predictor with auto-optimized settings.
21
+ ALGO_INTERP:
22
+ The whole dataset will be compressed by interpolation predictor with default settings.
23
+ ALGO_LORENZO_REG:
24
+ The whole dataset will be compressed by lorenzo and/or regression based predictors block by block with default settings.
25
+ The four predictors ( 1st-order lorenzo, 2nd-order lorenzo, 1st-order regression, 2nd-order regression)
26
+ can be enabled or disabled independently by conf settings (lorenzo, lorenzo2, regression, regression2).
27
+
28
+ Interpolation+lorenzo example:
29
+ SZ3::Config conf(100, 200, 300); // 300 is the fastest dimension
30
+ conf.cmprAlgo = SZ3::ALGO_INTERP_LORENZO;
31
+ conf.errorBoundMode = SZ3::EB_ABS; // refer to def.hpp for all supported error bound mode
32
+ conf.absErrorBound = 1E-3; // absolute error bound 1e-3
33
+ char *compressedData = SZ_compress(conf, data, outSize);
34
+
35
+ Interpolation example:
36
+ SZ3::Config conf(100, 200, 300); // 300 is the fastest dimension
37
+ conf.cmprAlgo = SZ3::ALGO_INTERP;
38
+ conf.errorBoundMode = SZ3::EB_REL; // refer to def.hpp for all supported error bound mode
39
+ conf.relErrorBound = 1E-3; // value-rang-based error bound 1e-3
40
+ char *compressedData = SZ_compress(conf, data, outSize);
41
+
42
+ Lorenzo/regression example :
43
+ SZ3::Config conf(100, 200, 300); // 300 is the fastest dimension
44
+ conf.cmprAlgo = SZ3::ALGO_LORENZO_REG;
45
+ conf.lorenzo = true; // only use 1st order lorenzo
46
+ conf.lorenzo2 = false;
47
+ conf.regression = false;
48
+ conf.regression2 = false;
49
+ conf.errorBoundMode = SZ3::EB_ABS; // refer to def.hpp for all supported error bound mode
50
+ conf.absErrorBound = 1E-3; // absolute error bound 1e-3
51
+ char *compressedData = SZ_compress(conf, data, outSize);
52
+ */
53
+ template<class T>
54
+ char *SZ_compress(const SZ3::Config &conf, const T *data, size_t &cmpSize) {
55
+ using namespace SZ3;
56
+ Config confCopy(conf);
57
+ char *cmpData;
58
+ if (conf.N == 1) {
59
+ cmpData = SZ_compress_impl<T, 1>(confCopy, data, cmpSize);
60
+ } else if (conf.N == 2) {
61
+ cmpData = SZ_compress_impl<T, 2>(confCopy, data, cmpSize);
62
+ } else if (conf.N == 3) {
63
+ cmpData = SZ_compress_impl<T, 3>(confCopy, data, cmpSize);
64
+ } else if (conf.N == 4) {
65
+ cmpData = SZ_compress_impl<T, 4>(confCopy, data, cmpSize);
66
+ } else {
67
+ printf("Data dimension higher than 4 is not supported.\n");
68
+ exit(0);
69
+ }
70
+ {
71
+ //save config
72
+ uchar *cmpDataPos = (uchar *) cmpData + cmpSize;
73
+ confCopy.save(cmpDataPos);
74
+ size_t newSize = (char *) cmpDataPos - cmpData;
75
+ write(int(newSize - cmpSize), cmpDataPos);
76
+ cmpSize = (char *) cmpDataPos - cmpData;
77
+ }
78
+ return cmpData;
79
+ }
80
+
81
+
82
+ /**
83
+ * API for decompression
84
+ * Similar with SZ_decompress(SZ3::Config &conf, char *cmpData, size_t cmpSize)
85
+ * The only difference is this one needs pre-allocated decData as input
86
+ * @tparam T decompressed data type
87
+ * @param conf configuration placeholder. It will be overwritten by the compression configuration
88
+ * @param cmpData compressed data
89
+ * @param cmpSize compressed data size in bytes
90
+ * @param decData pre-allocated memory space for decompressed data
91
+
92
+ example:
93
+ auto decData = new float[100*200*300];
94
+ SZ3::Config conf;
95
+ SZ_decompress(conf, cmpData, cmpSize, decData);
96
+
97
+ */
98
+ template<class T>
99
+ void SZ_decompress(SZ3::Config &conf, char *cmpData, size_t cmpSize, T *&decData) {
100
+ using namespace SZ3;
101
+ {
102
+ //load config
103
+ int confSize;
104
+ memcpy(&confSize, cmpData + (cmpSize - sizeof(int)), sizeof(int));
105
+ uchar const *cmpDataPos = (uchar *) cmpData + (cmpSize - sizeof(int) - confSize);
106
+ conf.load(cmpDataPos);
107
+ }
108
+ if (decData == nullptr) {
109
+ decData = new T[conf.num];
110
+ }
111
+ if (conf.N == 1) {
112
+ SZ_decompress_impl<T, 1>(conf, cmpData, cmpSize, decData);
113
+ } else if (conf.N == 2) {
114
+ SZ_decompress_impl<T, 2>(conf, cmpData, cmpSize, decData);
115
+ } else if (conf.N == 3) {
116
+ SZ_decompress_impl<T, 3>(conf, cmpData, cmpSize, decData);
117
+ } else if (conf.N == 4) {
118
+ SZ_decompress_impl<T, 4>(conf, cmpData, cmpSize, decData);
119
+ } else {
120
+ printf("Data dimension higher than 4 is not supported.\n");
121
+ exit(0);
122
+ }
123
+ }
124
+
125
+ /**
126
+ * API for decompression
127
+ * @tparam T decompressed data type
128
+ * @param conf configuration placeholder. It will be overwritten by the compression configuration
129
+ * @param cmpData compressed data
130
+ * @param cmpSize compressed data size in bytes
131
+ * @return decompressed data, remember to 'delete []' when the data is no longer needed.
132
+
133
+ example:
134
+ SZ3::Config conf;
135
+ float decompressedData = SZ_decompress(conf, cmpData, cmpSize)
136
+ */
137
+ template<class T>
138
+ T *SZ_decompress(SZ3::Config &conf, char *cmpData, size_t cmpSize) {
139
+ using namespace SZ3;
140
+ T *decData = nullptr;
141
+ SZ_decompress<T>(conf, cmpData, cmpSize, decData);
142
+ return decData;
143
+ }
144
+
145
+ #endif
@@ -0,0 +1,267 @@
1
+ //
2
+ // Created by Kai Zhao on 4/28/20.
3
+ //
4
+
5
+ #ifndef SZ_Config_HPP
6
+ #define SZ_Config_HPP
7
+
8
+ #include <iostream>
9
+ #include <vector>
10
+ #include <numeric>
11
+ #include <cstdint>
12
+ #include "SZ3/def.hpp"
13
+ #include "MemoryUtil.hpp"
14
+ #include "SZ3/utils/inih/INIReader.h"
15
+
16
+ #define SZ_FLOAT 0
17
+ #define SZ_DOUBLE 1
18
+ #define SZ_UINT8 2
19
+ #define SZ_INT8 3
20
+ #define SZ_UINT16 4
21
+ #define SZ_INT16 5
22
+ #define SZ_UINT32 6
23
+ #define SZ_INT32 7
24
+ #define SZ_UINT64 8
25
+ #define SZ_INT64 9
26
+
27
+ namespace SZ3 {
28
+ enum EB {
29
+ EB_ABS, EB_REL, EB_PSNR, EB_L2NORM, EB_ABS_AND_REL, EB_ABS_OR_REL
30
+ };
31
+
32
+ constexpr const char *EB_STR[] = {"ABS", "REL", "PSNR", "NORM", "ABS_AND_REL", "ABS_OR_REL"};
33
+ constexpr EB EB_OPTIONS[] = {EB_ABS, EB_REL, EB_PSNR, EB_L2NORM, EB_ABS_AND_REL, EB_ABS_OR_REL};
34
+
35
+ enum ALGO {
36
+ ALGO_LORENZO_REG, ALGO_INTERP_LORENZO, ALGO_INTERP, ALGO_BIOMD, ALGO_BIOMDXTC
37
+ };
38
+ constexpr const char *ALGO_STR[] = {
39
+ "ALGO_LORENZO_REG", "ALGO_INTERP_LORENZO", "ALGO_INTERP", "ALGO_BIOMD", "ALGO_BIOMDXTC"
40
+ };
41
+ constexpr const ALGO ALGO_OPTIONS[] = {
42
+ ALGO_LORENZO_REG, ALGO_INTERP_LORENZO, ALGO_INTERP, ALGO_BIOMD, ALGO_BIOMDXTC
43
+ };
44
+
45
+ enum INTERP_ALGO {
46
+ INTERP_ALGO_LINEAR, INTERP_ALGO_CUBIC
47
+ };
48
+
49
+ constexpr const char *INTERP_ALGO_STR[] = {"INTERP_ALGO_LINEAR", "INTERP_ALGO_CUBIC"};
50
+ constexpr INTERP_ALGO INTERP_ALGO_OPTIONS[] = {INTERP_ALGO_LINEAR, INTERP_ALGO_CUBIC};
51
+
52
+ template<class T>
53
+ const char *enum2Str(T e) {
54
+ if (std::is_same<T, ALGO>::value) {
55
+ return ALGO_STR[e];
56
+ } else if (std::is_same<T, INTERP_ALGO>::value) {
57
+ return INTERP_ALGO_STR[e];
58
+ } else if (std::is_same<T, EB>::value) {
59
+ return EB_STR[e];
60
+ } else {
61
+ printf("invalid enum type for enum2Str()\n ");
62
+ exit(0);
63
+ }
64
+ }
65
+
66
+ class Config {
67
+ public:
68
+ template<class... Dims>
69
+ Config(Dims... args) {
70
+ dims = std::vector<size_t>{static_cast<size_t>(std::forward<Dims>(args))...};
71
+ setDims(dims.begin(), dims.end());
72
+ }
73
+
74
+ template<class Iter>
75
+ size_t setDims(Iter begin, Iter end) {
76
+ auto dims_ = std::vector<size_t>(begin, end);
77
+ dims.clear();
78
+ for (auto dim : dims_) {
79
+ if (dim > 1) {
80
+ dims.push_back(dim);
81
+ }
82
+ }
83
+ if (dims.empty()) {
84
+ dims = {1};
85
+ }
86
+ N = dims.size();
87
+ num = std::accumulate(dims.begin(), dims.end(), (size_t) 1, std::multiplies<size_t>());
88
+ pred_dim = N;
89
+ blockSize = (N == 1 ? 128 : (N == 2 ? 16 : 6));
90
+ stride = blockSize;
91
+ return num;
92
+ }
93
+
94
+ void loadcfg(const std::string &cfgpath) {
95
+ INIReader cfg(cfgpath);
96
+
97
+ if (cfg.ParseError() != 0) {
98
+ std::cout << "Can't load cfg file " << cfgpath << std::endl;
99
+ exit(0);
100
+ }
101
+
102
+ auto cmprAlgoStr = cfg.Get("GlobalSettings", "CmprAlgo", "");
103
+ if (cmprAlgoStr == ALGO_STR[ALGO_LORENZO_REG]) {
104
+ cmprAlgo = ALGO_LORENZO_REG;
105
+ } else if (cmprAlgoStr == ALGO_STR[ALGO_INTERP_LORENZO]) {
106
+ cmprAlgo = ALGO_INTERP_LORENZO;
107
+ } else if (cmprAlgoStr == ALGO_STR[ALGO_INTERP]) {
108
+ cmprAlgo = ALGO_INTERP;
109
+ } else if (cmprAlgoStr == ALGO_STR[ALGO_BIOMD]) {
110
+ cmprAlgo = ALGO_BIOMD;
111
+ } else if (cmprAlgoStr == ALGO_STR[ALGO_BIOMDXTC]) {
112
+ cmprAlgo = ALGO_BIOMDXTC;
113
+ }
114
+ auto ebModeStr = cfg.Get("GlobalSettings", "ErrorBoundMode", "");
115
+ if (ebModeStr == EB_STR[EB_ABS]) {
116
+ errorBoundMode = EB_ABS;
117
+ } else if (ebModeStr == EB_STR[EB_REL]) {
118
+ errorBoundMode = EB_REL;
119
+ } else if (ebModeStr == EB_STR[EB_PSNR]) {
120
+ errorBoundMode = EB_PSNR;
121
+ } else if (ebModeStr == EB_STR[EB_L2NORM]) {
122
+ errorBoundMode = EB_L2NORM;
123
+ } else if (ebModeStr == EB_STR[EB_ABS_AND_REL]) {
124
+ errorBoundMode = EB_ABS_AND_REL;
125
+ } else if (ebModeStr == EB_STR[EB_ABS_OR_REL]) {
126
+ errorBoundMode = EB_ABS_OR_REL;
127
+ }
128
+ absErrorBound = cfg.GetReal("GlobalSettings", "AbsErrorBound", absErrorBound);
129
+ relErrorBound = cfg.GetReal("GlobalSettings", "RelErrorBound", relErrorBound);
130
+ psnrErrorBound = cfg.GetReal("GlobalSettings", "PSNRErrorBound", psnrErrorBound);
131
+ l2normErrorBound = cfg.GetReal("GlobalSettings", "L2NormErrorBound", l2normErrorBound);
132
+
133
+ openmp = cfg.GetBoolean("GlobalSettings", "OpenMP", openmp);
134
+ lorenzo = cfg.GetBoolean("AlgoSettings", "Lorenzo", lorenzo);
135
+ lorenzo2 = cfg.GetBoolean("AlgoSettings", "Lorenzo2ndOrder", lorenzo2);
136
+ regression = cfg.GetBoolean("AlgoSettings", "Regression", regression);
137
+ regression2 = cfg.GetBoolean("AlgoSettings", "Regression2ndOrder", regression2);
138
+
139
+ auto interpAlgoStr = cfg.Get("AlgoSettings", "InterpolationAlgo", "");
140
+ if (interpAlgoStr == INTERP_ALGO_STR[INTERP_ALGO_LINEAR]) {
141
+ interpAlgo = INTERP_ALGO_LINEAR;
142
+ } else if (interpAlgoStr == INTERP_ALGO_STR[INTERP_ALGO_CUBIC]) {
143
+ interpAlgo = INTERP_ALGO_CUBIC;
144
+ }
145
+ interpDirection = cfg.GetInteger("AlgoSettings", "InterpolationDirection", interpDirection);
146
+ interpBlockSize = cfg.GetInteger("AlgoSettings", "InterpolationBlockSize", interpBlockSize);
147
+ blockSize = cfg.GetInteger("AlgoSettings", "BlockSize", blockSize);
148
+ quantbinCnt = cfg.GetInteger("AlgoSettings", "QuantizationBinTotal", quantbinCnt);
149
+ }
150
+
151
+ void save(unsigned char *&c) {
152
+ write(N, c);
153
+ write(dims.data(), dims.size(), c);
154
+ write(num, c);
155
+ write(cmprAlgo, c);
156
+ write(errorBoundMode, c);
157
+ write(absErrorBound, c);
158
+ write(relErrorBound, c);
159
+ write(lorenzo, c);
160
+ write(lorenzo2, c);
161
+ write(regression, c);
162
+ write(regression2, c);
163
+ write(interpAlgo, c);
164
+ write(interpDirection, c);
165
+ write(interpBlockSize, c);
166
+ write(lossless, c);
167
+ write(encoder, c);
168
+ write(quantbinCnt, c);
169
+ write(blockSize, c);
170
+ write(stride, c);
171
+ write(pred_dim, c);
172
+ write(openmp, c);
173
+ write(dataType, c);
174
+ };
175
+
176
+ void load(const unsigned char *&c) {
177
+ read(N, c);
178
+ dims.resize(N);
179
+ read(dims.data(), N, c);
180
+ read(num, c);
181
+ read(cmprAlgo, c);
182
+ read(errorBoundMode, c);
183
+ read(absErrorBound, c);
184
+ read(relErrorBound, c);
185
+ read(lorenzo, c);
186
+ read(lorenzo2, c);
187
+ read(regression, c);
188
+ read(regression2, c);
189
+ read(interpAlgo, c);
190
+ read(interpDirection, c);
191
+ read(interpBlockSize, c);
192
+ read(lossless, c);
193
+ read(encoder, c);
194
+ read(quantbinCnt, c);
195
+ read(blockSize, c);
196
+ read(stride, c);
197
+ read(pred_dim, c);
198
+ read(openmp, c);
199
+ read(dataType, c);
200
+ }
201
+
202
+ void print() {
203
+ printf("===================== Begin SZ3 Configuration =====================\n");
204
+ printf("N = %d\n", N);
205
+ printf("dims = ");
206
+ for (auto dim : dims) {
207
+ printf("%zu ", dim);
208
+ }
209
+ printf("\nnum = %zu\n", num);
210
+ printf("CmprAlgo = %s\n", enum2Str((ALGO) cmprAlgo));
211
+ printf("ErrorBoundMode = %s\n", enum2Str((EB) errorBoundMode));
212
+ printf("AbsErrorBound = %f\n", absErrorBound);
213
+ printf("RelErrorBound = %f\n", relErrorBound);
214
+ printf("PSNRErrorBound = %f\n", psnrErrorBound);
215
+ printf("L2NormErrorBound = %f\n", l2normErrorBound);
216
+ printf("Lorenzo = %d\n", lorenzo);
217
+ printf("Lorenzo2ndOrder = %d\n", lorenzo2);
218
+ printf("Regression = %d\n", regression);
219
+ printf("Regression2ndOrder = %d\n", regression2);
220
+ printf("OpenMP = %d\n", openmp);
221
+ printf("DataType = %d\n", dataType);
222
+ printf("Lossless = %d\n", lossless);
223
+ printf("Encoder = %d\n", encoder);
224
+ printf("InterpolationAlgo = %s\n", enum2Str((INTERP_ALGO) interpAlgo));
225
+ printf("InterpolationDirection = %d\n", interpDirection);
226
+ printf("InterpolationBlockSize = %d\n", interpBlockSize);
227
+ printf("QuantizationBinTotal = %d\n", quantbinCnt);
228
+ printf("BlockSize = %d\n", blockSize);
229
+ printf("Stride = %d\n", stride);
230
+ printf("PredDim = %d\n", pred_dim);
231
+ printf("===================== End SZ3 Configuration =====================\n");
232
+ }
233
+
234
+ static size_t size_est() {
235
+ return sizeof(Config) + sizeof(size_t) * 5 + 32; //sizeof(size_t) * 5 is for dims vector, 32 is for redundancy
236
+ return sizeof(size_t) * 5 + sizeof(double) * 4 + sizeof(bool) * 5 + sizeof(uint8_t) * 7 + sizeof(int) * 5 +
237
+ 50; //50 is for redundancy
238
+ }
239
+
240
+ char N;
241
+ std::vector<size_t> dims;
242
+ size_t num;
243
+ uint8_t cmprAlgo = ALGO_INTERP_LORENZO;
244
+ uint8_t errorBoundMode = EB_ABS;
245
+ double absErrorBound = 1e-3;
246
+ double relErrorBound = 0;
247
+ double psnrErrorBound = 0;
248
+ double l2normErrorBound = 0;
249
+ bool lorenzo = true;
250
+ bool lorenzo2 = false;
251
+ bool regression = true;
252
+ bool regression2 = false;
253
+ bool openmp = false;
254
+ uint8_t dataType = SZ_FLOAT; // dataType is only used in HDF5 filter
255
+ uint8_t lossless = 1; // 0-> skip lossless(use lossless_bypass); 1-> zstd
256
+ uint8_t encoder = 1; // 0-> skip encoder; 1->HuffmanEncoder; 2->ArithmeticEncoder
257
+ uint8_t interpAlgo = INTERP_ALGO_CUBIC;
258
+ uint8_t interpDirection = 0;
259
+ int interpBlockSize = 32;
260
+ int quantbinCnt = 65536;
261
+ int blockSize;
262
+ int stride; //not used now
263
+ int pred_dim; // not used now
264
+ };
265
+ }
266
+
267
+ #endif //SZ_CONFIG_HPP
@@ -0,0 +1,74 @@
1
+ //
2
+ // Created by Kai Zhao on 12/9/19.
3
+ //
4
+
5
+ #ifndef _SZ_FILE_UTIL
6
+ #define _SZ_FILE_UTIL
7
+
8
+ #include <iostream>
9
+ #include <fstream>
10
+ #include <iomanip>
11
+ #include <cassert>
12
+ #include <random>
13
+ #include <sstream>
14
+ #include <memory>
15
+
16
+ namespace SZ3 {
17
+
18
+ template<typename Type>
19
+ void readfile(const char *file, const size_t num, Type *data) {
20
+ std::ifstream fin(file, std::ios::binary);
21
+ if (!fin) {
22
+ std::cout << " Error, Couldn't find the file: " << file << "\n";
23
+ exit(0);
24
+ }
25
+ fin.seekg(0, std::ios::end);
26
+ const size_t num_elements = fin.tellg() / sizeof(Type);
27
+ assert(num_elements == num && "File size is not equals to the input setting");
28
+ fin.seekg(0, std::ios::beg);
29
+ fin.read(reinterpret_cast<char *>(data), num_elements * sizeof(Type));
30
+ fin.close();
31
+ }
32
+
33
+ template<typename Type>
34
+ std::unique_ptr<Type[]> readfile(const char *file, size_t &num) {
35
+ std::ifstream fin(file, std::ios::binary);
36
+ if (!fin) {
37
+ std::cout << " Error, Couldn't find the file: " << file << std::endl;
38
+ exit(0);
39
+ }
40
+ fin.seekg(0, std::ios::end);
41
+ const size_t num_elements = fin.tellg() / sizeof(Type);
42
+ fin.seekg(0, std::ios::beg);
43
+ // auto data = SZ3::compat::make_unique<Type[]>(num_elements);
44
+ auto data = std::make_unique<Type[]>(num_elements);
45
+ fin.read(reinterpret_cast<char *>(&data[0]), num_elements * sizeof(Type));
46
+ fin.close();
47
+ num = num_elements;
48
+ return data;
49
+ }
50
+
51
+ template<typename Type>
52
+ void writefile(const char *file, Type *data, size_t num_elements) {
53
+ std::ofstream fout(file, std::ios::binary);
54
+ fout.write(reinterpret_cast<const char *>(&data[0]), num_elements * sizeof(Type));
55
+ fout.close();
56
+ }
57
+
58
+ template<typename Type>
59
+ void writeTextFile(const char *file, Type *data, size_t num_elements) {
60
+ std::ofstream fout(file);
61
+ if (fout.is_open()) {
62
+ for (size_t i = 0; i < num_elements; i++) {
63
+ fout << data[i] << std::endl;
64
+ }
65
+ fout.close();
66
+ } else {
67
+ std::cout << "Error, unable to open file for output: " << file << std::endl;
68
+ exit(0);
69
+ }
70
+ }
71
+
72
+ }
73
+
74
+ #endif