Debian Codegraph @

pywt/_extensions/c/common.h

raw symbols SCIP
1 /* Copyright (c) 2006-2012 Filip Wasilewski <http://en.ig.ma/>
2 * Copyright (c) 2012-2016 The PyWavelets Developers
3 * <https://github.com/PyWavelets/pywt>
4 * See COPYING for license details.
5 */
6
7 /* Common constants, typedefs and functions */
8
9 #pragma once
10
11 #include <stdlib.h>
12 #include <memory.h>
13
14 #ifdef HAVE_C99_COMPLEX
15 /* For templating, we need typedefs without spaces for complex types. */
16 typedef float _Complex float_complex;
17 typedef double _Complex double_complex;
18 #endif
19
20 /* ##### Typedefs ##### */
21
22 #ifdef PY_EXTENSION
23 /* another declaration is in .c file generated by Pyrex */
24 #ifndef PY_SSIZE_T_CLEAN
25 #define PY_SSIZE_T_CLEAN
26 #include "Python.h"
27 #include "structmember.h"
28 #ifndef PY_LONG_LONG
29 #define PY_LONG_LONG LONG_LONG
30 #endif
31 #else
32 #include "Python.h"
33 #endif
34
35 /* on Solaris/SmartOS system, index_t is used in sys/types.h, so use pytw_index_t */
36 typedef Py_ssize_t pywt_index_t;
37
38 #else
39 typedef int pywt_index_t;
40 #endif
41
42 /* standard c memory management */
43 #define wtmalloc(size) malloc(size)
44 #define wtfree(ptr) free(ptr)
45 #define wtcalloc(len, size) calloc(len, size)
46
47 #ifdef _MSC_VER
48 #include <intrin.h>
49 #endif
50
51 typedef struct {
52 size_t * shape;
53 pywt_index_t * strides;
54 size_t ndim;
55 } ArrayInfo;
56
57 typedef enum {
58 COEF_APPROX = 0,
59 COEF_DETAIL = 1,
60 } Coefficient;
61
62 typedef enum {
63 DWT_TRANSFORM = 0,
64 SWT_TRANSFORM = 1,
65 } DiscreteTransformType;
66
67 /* Signal extension modes */
68 typedef enum {
69 MODE_INVALID = -1,
70 MODE_ZEROPAD = 0, /* default, signal extended with zeros */
71 MODE_SYMMETRIC, /* signal extended symmetrically (mirror)
72 * also known as half-sample symmetric
73 * For extensions greater than signal length,
74 * mirror back and forth:
75 * 2 3 3 2 1 | 1 2 3 | 3 2 1 1 2
76 */
77 MODE_CONSTANT_EDGE, /* signal extended with the border value */
78 MODE_SMOOTH, /* linear extrapolation (first derivative) */
79 MODE_PERIODIC, /* signal is treated as being periodic */
80 MODE_PERIODIZATION, /* signal is treated as being periodic, minimal output length */
81 MODE_REFLECT, /* signal extended symmetrically (reflect)
82 * also known as whole-sample symmetric
83 * For extensions greater than signal length,
84 * reflect back and forth without repeating edge values:
85 * 1 2 3 2 | 1 2 3 | 2 1 2 3
86 */
87 MODE_ANTISYMMETRIC, /* antisymmetric version of "MODE_SYMMETRIC"
88 * also known as half-sample antisymmetric
89 * 2 3 -3 -2 -1 | 1 2 3 | -3 -2 -1 1 2
90 */
91 MODE_ANTIREFLECT, /* antisymmetric version of "MODE_REFLECT"
92 * also known as whole-sample antisymmetric
93 * 0 -1 -2 -1 0 | 1 2 3 | 4 5 6 5 4
94 */
95 MODE_MAX,
96 } MODE;
97
98
99 /* ##### Calculating buffer lengths for various operations ##### */
100
101 /*
102 * Length of DWT coeffs for specified input data length, filter length and
103 * signal extension mode.
104 */
105 size_t dwt_buffer_length(size_t input_len, size_t filter_len, MODE mode);
106
107 /*
108 * Length of reconstructed signal for specified input coeffs length and filter
109 * length. It is used for direct reconstruction from coefficients (normal
110 * convolution of upsampled coeffs with filter).
111 */
112 size_t reconstruction_buffer_length(size_t coeffs_len, size_t filter_len);
113
114 /*
115 * Length of IDWT reconstructed signal for specified input coeffs length, filter
116 * length and extension mode.
117 */
118 size_t idwt_buffer_length(size_t coeffs_len, size_t filter_len, MODE mode);
119
120 /* Length of SWT coefficients for specified input signal length (== input_len) */
121 size_t swt_buffer_length(size_t input_len);
122
123 /* Maximum useful level of DWT decomposition. */
124 unsigned char dwt_max_level(size_t input_len, size_t filter_len);
125
126 /* Maximum useful level of SWT decomposition. */
127 unsigned char swt_max_level(size_t input_len);