1 | #include "aubio-types.h" |
---|
2 | |
---|
3 | static void unwrap2pi(char **args, npy_intp *dimensions, |
---|
4 | npy_intp* steps, void* data) |
---|
5 | { |
---|
6 | npy_intp i; |
---|
7 | npy_intp n = dimensions[0]; |
---|
8 | char *in = args[0], *out = args[1]; |
---|
9 | npy_intp in_step = steps[0], out_step = steps[1]; |
---|
10 | |
---|
11 | for (i = 0; i < n; i++) { |
---|
12 | /*BEGIN main ufunc computation*/ |
---|
13 | *((double *)out) = aubio_unwrap2pi(*(double *)in); |
---|
14 | /*END main ufunc computation*/ |
---|
15 | |
---|
16 | in += in_step; |
---|
17 | out += out_step; |
---|
18 | } |
---|
19 | } |
---|
20 | |
---|
21 | static void unwrap2pif(char **args, npy_intp *dimensions, |
---|
22 | npy_intp* steps, void* data) |
---|
23 | { |
---|
24 | npy_intp i; |
---|
25 | npy_intp n = dimensions[0]; |
---|
26 | char *in = args[0], *out = args[1]; |
---|
27 | npy_intp in_step = steps[0], out_step = steps[1]; |
---|
28 | |
---|
29 | for (i = 0; i < n; i++) { |
---|
30 | /*BEGIN main ufunc computation*/ |
---|
31 | *((float *)out) = aubio_unwrap2pi(*(float *)in); |
---|
32 | /*END main ufunc computation*/ |
---|
33 | |
---|
34 | in += in_step; |
---|
35 | out += out_step; |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | static char Py_unwrap2pi_doc[] = "map angle to unit circle [-pi, pi["; |
---|
40 | |
---|
41 | PyUFuncGenericFunction unwrap2pi_functions[] = { |
---|
42 | &unwrap2pif, &unwrap2pi, |
---|
43 | //PyUFunc_f_f_As_d_d, PyUFunc_d_d, |
---|
44 | //PyUFunc_g_g, PyUFunc_OO_O_method, |
---|
45 | }; |
---|
46 | |
---|
47 | static void* unwrap2pi_data[] = { |
---|
48 | (void *)aubio_unwrap2pi, |
---|
49 | (void *)aubio_unwrap2pi, |
---|
50 | //(void *)unwrap2pil, |
---|
51 | //(void *)unwrap2pio, |
---|
52 | }; |
---|
53 | |
---|
54 | static char unwrap2pi_types[] = { |
---|
55 | NPY_FLOAT, NPY_FLOAT, |
---|
56 | NPY_DOUBLE, NPY_DOUBLE, |
---|
57 | //NPY_LONGDOUBLE, NPY_LONGDOUBLE, |
---|
58 | //NPY_OBJECT, NPY_OBJECT, |
---|
59 | }; |
---|
60 | |
---|
61 | void add_ufuncs ( PyObject *m ) |
---|
62 | { |
---|
63 | int err = _import_umath(); |
---|
64 | |
---|
65 | if (err != 0) { |
---|
66 | fprintf (stderr, |
---|
67 | "Unable to import Numpy C API Ufunc from aubio module (error %d)\n", err); |
---|
68 | } |
---|
69 | |
---|
70 | PyObject *f, *dict; |
---|
71 | dict = PyModule_GetDict(m); |
---|
72 | f = PyUFunc_FromFuncAndData(unwrap2pi_functions, |
---|
73 | unwrap2pi_data, unwrap2pi_types, 2, 1, 1, |
---|
74 | PyUFunc_None, "unwrap2pi", Py_unwrap2pi_doc, 0); |
---|
75 | PyDict_SetItemString(dict, "unwrap2pi", f); |
---|
76 | Py_DECREF(f); |
---|
77 | |
---|
78 | return; |
---|
79 | } |
---|