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