Libpolycomp  1.0
A compression/decompression library that implements the polynomial compression and other simple compression schemes
test_chebyshev.c
1 /* test_chebyshev.c - Tests for Chebyshev transform functions
2  *
3  * Copyright (c) 2015 Maurizio Tomasi
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use, copy,
9  * modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #include <libpolycomp.h>
27 #include <assert.h>
28 #include <math.h>
29 
30 #define EPSILON 1.0e-7
31 
32 int main(void)
33 {
34  double points[] = { 0.0, 1.0, 3.0 };
35  double coeffs[3];
36  double inv_coeffs[3];
37 
39  sizeof(points) / sizeof(points[0]), PCOMP_TD_DIRECT);
40  assert(pcomp_run_chebyshev(chebyshev, PCOMP_TD_DIRECT, coeffs,
41  points) == PCOMP_STAT_SUCCESS);
42 
43  /* These values have been calculated by hand */
44  assert(fabs(coeffs[0] - (+5.0 / 2.0)) < EPSILON);
45  assert(fabs(coeffs[1] - (-3.0 / 2.0)) < EPSILON);
46  assert(fabs(coeffs[2] - (+1.0 / 2.0)) < EPSILON);
47 
48  /* Now check that the inverse transform reconstructs the points
49  * correctly */
50  assert(pcomp_run_chebyshev(chebyshev, PCOMP_TD_INVERSE, inv_coeffs,
51  coeffs) == PCOMP_STAT_SUCCESS);
52 
53  assert(fabs(points[0] - inv_coeffs[0]) < EPSILON);
54  assert(fabs(points[1] - inv_coeffs[1]) < EPSILON);
55  assert(fabs(points[2] - inv_coeffs[2]) < EPSILON);
56 
57  pcomp_free_chebyshev(chebyshev);
58  return 0;
59 }
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.
Definition: poly.c:365
Compute a backward Chebyshev transform, with a normalization factor equal to one. ...
Definition: libpolycomp.h:326
Compute a forward Chebyshev transform, with a normalization factor 1/(N + 1)
Definition: libpolycomp.h:323
void pcomp_free_chebyshev(pcomp_chebyshev_t *plan)
Free the memory allocated by a previous call to pcomp_init_chebyshev.
Definition: poly.c:390
int pcomp_run_chebyshev(pcomp_chebyshev_t *plan, pcomp_transform_direction_t dir, double *output, const double *input)
Compute a forward/backward Chebyshev discrete transform.
Definition: poly.c:491
Header file for Libpolycomp.