34 #define EPSILON 1.0e-7
35 #define MAX_ALLOWABLE_ERROR 0.3
37 int test_chunk_creation(
void)
39 const double samples[] = { 1.0, 2.0, 3.0, 4.0 };
40 const size_t num_of_samples =
sizeof(samples) /
sizeof(samples[0]);
42 const double poly[] = { 3.0, 2.0 };
43 const size_t num_of_poly =
sizeof(poly) /
sizeof(poly[0]);
45 const uint8_t cheby_mask[] = { 0xFF };
47 const double cheby[] = { -1.0, -2.0, -3.0, -4.0 };
48 const size_t num_of_cheby =
sizeof(cheby) /
sizeof(cheby[0]);
56 assert(chunk != NULL);
63 &poly[0], num_of_cheby,
64 &cheby_mask[0], &cheby[0]);
65 assert(chunk != NULL);
71 assert(values[idx] == poly[idx]);
77 assert(values[idx] == cheby[idx]);
85 int test_no_compression(
void)
90 = { 1.0, -2.0, 3.0, -4.0, 5.0, 6.0, 7.0, -8.0, 9.0, -10.0 };
91 size_t input_size =
sizeof(input) /
sizeof(input[0]);
92 double* decompr = malloc(
sizeof(
double) * input_size);
109 for (idx = 0; idx < input_size; ++idx) {
110 assert(input[idx] == decompr[idx]);
121 int test_no_chebyshev(
void)
125 = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };
126 size_t input_size =
sizeof(input) /
sizeof(input[0]);
127 double* decompr = malloc(
sizeof(
double) * input_size);
147 for (idx = 0; idx < input_size; ++idx) {
148 assert(fabs(input[idx] - decompr[idx]) < EPSILON);
159 int test_complete_compression_and_decompression(
void)
162 = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 11.0 };
163 size_t input_size =
sizeof(input) /
sizeof(input[0]);
164 double* decompr = malloc(
sizeof(
double) * input_size);
182 for (idx = 0; idx < input_size; ++idx) {
183 assert(fabs(input[idx] - decompr[idx]) < MAX_ALLOWABLE_ERROR);
198 result = test_chunk_creation();
202 result = test_no_compression();
206 result = test_no_chebyshev();
210 result = test_complete_compression_and_decompression();
const double * pcomp_chunk_cheby_coeffs(const pcomp_polycomp_chunk_t *chunk)
If the chunks contain compressed data, returns a pointer to the first element of the Chebyshev transf...
pcomp_chebyshev_t * pcomp_init_chebyshev(size_t num_of_samples, pcomp_transform_direction_t dir)
Allocate a new instance of the pcomp_chebyshev_t structure on the heap.
int pcomp_decompress_polycomp_chunk(double *output, const pcomp_polycomp_chunk_t *chunk, pcomp_chebyshev_t *inv_chebyshev)
Decompress the data in a chunk.
Compute a backward Chebyshev transform, with a normalization factor equal to one. ...
const double * pcomp_chunk_poly_coeffs(const pcomp_polycomp_chunk_t *chunk)
If the chunks contain compressed data, returns a pointer to the first element of the array of coeffic...
pcomp_polycomp_chunk_t * pcomp_init_compressed_chunk(pcomp_chunk_size_t num_of_samples, pcomp_poly_size_t num_of_poly_coeffs, const double *poly_coeffs, pcomp_chunk_size_t num_of_cheby_coeffs, const uint8_t *chebyshev_mask, const double *cheby_coeffs)
Allocate memory for a pcomp_polycomp_chunk_t object and fill it with data compressed using the polyno...
void pcomp_free_polycomp(pcomp_polycomp_t *params)
Free the memory allocated by pcomp_init_polycomp for a pcomp_polycomp_t structure.
pcomp_polycomp_chunk_t * pcomp_init_chunk(pcomp_chunk_size_t num_of_samples)
Allocate memory for a pcomp_polycomp_chunk_t object.
pcomp_chunk_size_t pcomp_chunk_num_of_samples(const pcomp_polycomp_chunk_t *chunk)
Return the number of samples in a chunk.
pcomp_poly_size_t pcomp_chunk_num_of_poly_coeffs(const pcomp_polycomp_chunk_t *chunk)
If the chunks contain compressed data, returns the number of polynomial coefficients used in the comp...
When needed, apply the Chebyshev transform to the residuals of the polynomial fit.
void pcomp_free_chebyshev(pcomp_chebyshev_t *plan)
Free the memory allocated by a previous call to pcomp_init_chebyshev.
pcomp_polycomp_chunk_t * pcomp_init_uncompressed_chunk(pcomp_chunk_size_t num_of_samples, const double *samples)
Allocate memory for a pcomp_polycomp_chunk_t object and fill it with data in uncompressed form...
int pcomp_run_polycomp_on_chunk(pcomp_polycomp_t *params, const double *input, pcomp_chunk_size_t num_of_samples, pcomp_polycomp_chunk_t *chunk, double *max_error)
Compress the first num_of_samples elements in input and store them in chunk.
size_t pcomp_chunk_cheby_mask_size(pcomp_chunk_size_t chunk_size)
Return the number of bytes required for the bitmask of nonzero Chebyshev coefficients.
void pcomp_free_chunk(pcomp_polycomp_chunk_t *chunk)
Free memory associated with a pcomp_poly_chunk_t.
pcomp_polycomp_t * pcomp_init_polycomp(pcomp_chunk_size_t samples_per_chunk, pcomp_poly_size_t num_of_coeffs, double max_allowable_error, pcomp_polycomp_algorithm_t algorithm)
Allocate space for a pcomp_polycomp_t structure.
int pcomp_chunk_is_compressed(const pcomp_polycomp_chunk_t *chunk)
Return nonzero if the chunk holds data in uncompressed form.
Header file for Libpolycomp.
pcomp_chunk_size_t pcomp_chunk_num_of_cheby_coeffs(const pcomp_polycomp_chunk_t *chunk)
If the chunks contain compressed data, returns the number of nonzero Chebyshev coefficients held in t...