36 #define DEFINE_QUANT_TEST(fn_name, pcomp_fn, datatype_t) \
39 datatype_t input_buf[] = { 3.06, 5.31, 2.25, 7.92, 4.86 }; \
40 size_t input_size = sizeof(input_buf) / sizeof(input_buf[0]); \
41 size_t output_size = 4; \
42 uint8_t* output_buf = malloc(output_size); \
44 pcomp_quant_params_t* params \
45 = pcomp_init_quant_params(sizeof(datatype_t), 5); \
47 assert(pcomp_fn(output_buf, &output_size, input_buf, \
48 input_size, params) == PCOMP_STAT_SUCCESS); \
50 assert(output_buf[0] == 36); \
51 assert(output_buf[1] == 65); \
52 assert(output_buf[2] == 247); \
53 assert(output_buf[3] == 0); \
56 pcomp_free_quant_params(params); \
59 DEFINE_QUANT_TEST(test_quant_compression_float,
61 DEFINE_QUANT_TEST(test_quant_compression_double,
69 #define DEFINE_QUANT_DECOMPR_TEST(fn_name, compr_fn, decompr_fn, \
73 datatype_t input_buf[] = { 3.06, 5.31, 2.25, 7.92, 4.86 }; \
74 size_t input_size = sizeof(input_buf) / sizeof(input_buf[0]); \
75 size_t compr_size = 4; \
76 uint8_t* compr_buf = malloc(compr_size); \
77 datatype_t decompr_buf[5]; \
80 pcomp_quant_params_t* params \
81 = pcomp_init_quant_params(sizeof(datatype_t), 5); \
83 assert(compr_fn(compr_buf, &compr_size, input_buf, input_size, \
84 params) == PCOMP_STAT_SUCCESS); \
86 assert(decompr_fn(&decompr_buf[0], input_size, compr_buf, \
87 compr_size, params) == PCOMP_STAT_SUCCESS); \
89 for (idx = 0; idx < input_size; ++idx) { \
90 assert(fabs(input_buf[idx] - decompr_buf[idx]) < 0.186); \
96 DEFINE_QUANT_DECOMPR_TEST(test_quant_decompression_float,
98 pcomp_decompress_quant_float,
float)
99 DEFINE_QUANT_DECOMPR_TEST(test_quant_decompression_double,
100 pcomp_compress_quant_double,
101 pcomp_decompress_quant_double,
double)
105 test_quant_compression_float();
106 test_quant_compression_double();
108 test_quant_decompression_float();
109 test_quant_decompression_double();
int pcomp_compress_quant_float(void *output_buf, size_t *output_size, const float *input_buf, size_t input_size, pcomp_quant_params_t *params)
Quantize a stream of 32-bit floating point numbers.
int pcomp_compress_quant_double(void *output_buf, size_t *output_size, const double *input_buf, size_t input_size, pcomp_quant_params_t *params)
Quantize a stream of 64-bit floating point numbers.
Header file for Libpolycomp.