Skip to content

Commit

Permalink
update stateNum in preprocess_encode
Browse files Browse the repository at this point in the history
  • Loading branch information
ayzk committed Oct 27, 2023
1 parent f420554 commit ab7896e
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/SZ3/compressor/SZGeneralCompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace SZ {

std::vector<int> quant_inds = frontend.compress(data);

encoder.preprocess_encode(quant_inds, 0);
encoder.preprocess_encode(quant_inds, frontend.get_radius() * 2);
size_t bufferSize = 1.2 * (frontend.size_est() + encoder.size_est() + sizeof(T) * quant_inds.size());

uchar *buffer = new uchar[bufferSize];
Expand Down
2 changes: 1 addition & 1 deletion include/SZ3/compressor/SZInterpolationCompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace SZ {

// writefile("pred.dat", preds.data(), num_elements);
// writefile("quant.dat", quant_inds.data(), num_elements);
encoder.preprocess_encode(quant_inds, 0);
encoder.preprocess_encode(quant_inds, quantizer.get_radius() * 2);
size_t bufferSize = 1.2 * (quantizer.size_est() + encoder.size_est() + sizeof(T) * quant_inds.size());

uchar *buffer = new uchar[bufferSize];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace SZ {
quantizer.postcompress_data();
// predictor.print();

encoder.preprocess_encode(quant_inds, 0);
encoder.preprocess_encode(quant_inds, quantizer.get_radius() * 2);
size_t bufferSize = 1.2 * (quantizer.size_est() + encoder.size_est() + sizeof(T) * quant_inds.size());

uchar *buffer = new uchar[bufferSize];
Expand Down
6 changes: 6 additions & 0 deletions include/SZ3/encoder/Encoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ namespace SZ {

virtual ~EncoderInterface() = default;

/**
* init the encoder
* E.g., Huffman will build tree in this step
* @param bins to-be-encoded integers
* @param stateNum stateNum > 0 indicates the bins has a range of [0, stateNum). stateNum == 0 means no such guarantee
*/
virtual void preprocess_encode(const std::vector<T> &bins, int stateNum) = 0;

/**
Expand Down
4 changes: 2 additions & 2 deletions include/SZ3/encoder/HuffmanEncoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace SZ {
/**
* build huffman tree using bins
* @param bins
* @param stateNum is no longer needed
* @param stateNum
*/
void preprocess_encode(const std::vector<T> &bins, int stateNum) {
preprocess_encode(bins.data(), bins.size(), stateNum);
Expand All @@ -97,7 +97,7 @@ namespace SZ {
* build huffman tree using bins
* @param bins
* @param num_bin
* @param stateNum is no longer needed
* @param stateNum
*/
void preprocess_encode(const T *bins, size_t num_bin, int stateNum) {
nodeCount = 0;
Expand Down
2 changes: 1 addition & 1 deletion include/SZ3/frontend/SZFastFrontend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ namespace SZ {

if (reg_count) {
reg_huffman = HuffmanEncoder<int>();
reg_huffman.preprocess_encode(reg_params_type, RegCoeffNum3d * reg_count, 0);
reg_huffman.preprocess_encode(reg_params_type, RegCoeffNum3d * reg_count, RegCoeffRadius * 2);
}
indicator_huffman = HuffmanEncoder<int>();
indicator_huffman.preprocess_encode(indicator, SELECTOR_RADIUS);
Expand Down
2 changes: 1 addition & 1 deletion include/SZ3/predictor/ComposedPredictor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace SZ {
c += sizeof(size_t);
if (selection.size()) {
HuffmanEncoder<int> selection_encoder;
selection_encoder.preprocess_encode(selection, 0);
selection_encoder.preprocess_encode(selection, predict_error.size());
selection_encoder.save(c);
selection_encoder.encode(selection, c);
selection_encoder.postprocess_encode();
Expand Down
5 changes: 4 additions & 1 deletion include/SZ3/predictor/PolyRegressionPredictor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ namespace SZ {
quantizer_liner.save(c);
quantizer_poly.save(c);
HuffmanEncoder<int> encoder = HuffmanEncoder<int>();
encoder.preprocess_encode(regression_coeff_quant_inds, 0);

encoder.preprocess_encode(regression_coeff_quant_inds,
2 * std::max(std::max(quantizer_independent.get_radius(), quantizer_liner.get_radius()),
quantizer_poly.get_radius()));
encoder.save(c);
encoder.encode(regression_coeff_quant_inds, c);
encoder.postprocess_encode();
Expand Down
3 changes: 2 additions & 1 deletion include/SZ3/predictor/RegressionPredictor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ namespace SZ {
quantizer_independent.save(c);
quantizer_liner.save(c);
HuffmanEncoder<int> encoder = HuffmanEncoder<int>();
encoder.preprocess_encode(regression_coeff_quant_inds,0);
encoder.preprocess_encode(regression_coeff_quant_inds,
2 * std::max(quantizer_independent.get_radius(), quantizer_liner.get_radius()));
encoder.save(c);
encoder.encode(regression_coeff_quant_inds, c);
encoder.postprocess_encode();
Expand Down
2 changes: 1 addition & 1 deletion tools/mdz/include/ExaaltCompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace SZ {
quantizer.save(compressed_data_pos);
// quantizer.print();

encoder.preprocess_encode(quant_inds, 4 * quantizer.get_radius());
encoder.preprocess_encode(quant_inds, 2 * quantizer.get_radius());
encoder.save(compressed_data_pos);
encoder.encode(quant_inds, compressed_data_pos);
encoder.postprocess_encode();
Expand Down
2 changes: 1 addition & 1 deletion tools/sz3/deprecated/test_huffman_coding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int main() {
unsigned char *compressed = (unsigned char *) malloc(N * sizeof(int));
{
SZ::HuffmanEncoder<int> encoder;
encoder.preprocess_encode(type, 0);
encoder.preprocess_encode(type, capacity);
unsigned char *compressed_pos = compressed;
cout << "save encoder" << endl;
encoder.save(compressed_pos);
Expand Down

0 comments on commit ab7896e

Please sign in to comment.