From 1458de5218ce62307074b6a973aa1104f9e7e990 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 10 Jul 2012 19:41:33 -0600 Subject: [PATCH] aubio-types.h, aubiomodule.c: update for numpy 1.8 --- interfaces/python/aubio-types.h | 1 + interfaces/python/aubiomodule.c | 13 +++++++------ interfaces/python/aubioproxy.c | 12 ++++++------ interfaces/python/py-cvec.c | 28 ++++++++++++++-------------- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/interfaces/python/aubio-types.h b/interfaces/python/aubio-types.h index 236e3a75..d63bbcd4 100644 --- a/interfaces/python/aubio-types.h +++ b/interfaces/python/aubio-types.h @@ -1,6 +1,7 @@ #include #include #define NO_IMPORT_ARRAY +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #include #define AUBIO_UNSTABLE 1 #include diff --git a/interfaces/python/aubiomodule.c b/interfaces/python/aubiomodule.c index 27e8e51a..df5787e1 100644 --- a/interfaces/python/aubiomodule.c +++ b/interfaces/python/aubiomodule.c @@ -1,5 +1,6 @@ #include #define PY_ARRAY_UNIQUE_SYMBOL PyArray_API +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #include #include "aubio-types.h" @@ -131,6 +132,12 @@ init_aubio (void) return; } + m = Py_InitModule3 ("_aubio", aubio_methods, aubio_module_doc); + + if (m == NULL) { + return; + } + err = _import_array (); if (err != 0) { @@ -138,12 +145,6 @@ init_aubio (void) "Unable to import Numpy C API from aubio module (error %d)\n", err); } - m = Py_InitModule3 ("_aubio", aubio_methods, aubio_module_doc); - - if (m == NULL) { - return; - } - Py_INCREF (&Py_cvecType); PyModule_AddObject (m, "cvec", (PyObject *) & Py_cvecType); Py_INCREF (&Py_filterType); diff --git a/interfaces/python/aubioproxy.c b/interfaces/python/aubioproxy.c index b6285465..94a54193 100644 --- a/interfaces/python/aubioproxy.c +++ b/interfaces/python/aubioproxy.c @@ -12,19 +12,19 @@ PyAubio_ArrayToCFvec (PyObject *input) { if (PyArray_Check(input)) { // we got an array, convert it to an fvec - if (PyArray_NDIM (input) == 0) { + if (PyArray_NDIM ((PyArrayObject *)input) == 0) { PyErr_SetString (PyExc_ValueError, "input array is a scalar"); goto fail; - } else if (PyArray_NDIM (input) > 1) { + } else if (PyArray_NDIM ((PyArrayObject *)input) > 1) { PyErr_SetString (PyExc_ValueError, "input array has more than one dimensions"); goto fail; } - if (!PyArray_ISFLOAT (input)) { + if (!PyArray_ISFLOAT ((PyArrayObject *)input)) { PyErr_SetString (PyExc_ValueError, "input array should be float"); goto fail; - } else if (PyArray_TYPE (input) != AUBIO_NPY_SMPL) { + } else if (PyArray_TYPE ((PyArrayObject *)input) != AUBIO_NPY_SMPL) { PyErr_SetString (PyExc_ValueError, "input array should be float32"); goto fail; } else { @@ -35,8 +35,8 @@ PyAubio_ArrayToCFvec (PyObject *input) { // vec = new_fvec (vec->length); // no need to really allocate fvec, just its struct member vec = (fvec_t *)malloc(sizeof(fvec_t)); - vec->length = PyArray_SIZE (array); - vec->data = (smpl_t *) PyArray_GETPTR1 (array, 0); + vec->length = PyArray_SIZE ((PyArrayObject *)array); + vec->data = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)array, 0); } else if (PyObject_TypeCheck (input, &PyList_Type)) { PyErr_SetString (PyExc_ValueError, "does not convert from list yet"); diff --git a/interfaces/python/py-cvec.c b/interfaces/python/py-cvec.c index 5de5175c..940508fb 100644 --- a/interfaces/python/py-cvec.c +++ b/interfaces/python/py-cvec.c @@ -125,7 +125,7 @@ Py_cvec_get_phas (Py_cvec * self, void *closure) static int Py_cvec_set_norm (Py_cvec * vec, PyObject *input, void * closure) { - PyObject * array; + PyArrayObject * array; if (input == NULL) { PyErr_SetString (PyExc_ValueError, "input array is not a python object"); goto fail; @@ -133,23 +133,23 @@ Py_cvec_set_norm (Py_cvec * vec, PyObject *input, void * closure) if (PyArray_Check(input)) { // we got an array, convert it to a cvec.norm - if (PyArray_NDIM (input) == 0) { + if (PyArray_NDIM ((PyArrayObject *)input) == 0) { PyErr_SetString (PyExc_ValueError, "input array is a scalar"); goto fail; - } else if (PyArray_NDIM (input) > 2) { + } else if (PyArray_NDIM ((PyArrayObject *)input) > 2) { PyErr_SetString (PyExc_ValueError, "input array has more than two dimensions"); goto fail; } - if (!PyArray_ISFLOAT (input)) { + if (!PyArray_ISFLOAT ((PyArrayObject *)input)) { PyErr_SetString (PyExc_ValueError, "input array should be float"); goto fail; - } else if (PyArray_TYPE (input) != AUBIO_NPY_SMPL) { + } else if (PyArray_TYPE ((PyArrayObject *)input) != AUBIO_NPY_SMPL) { PyErr_SetString (PyExc_ValueError, "input array should be float32"); goto fail; } - array = input; + array = (PyArrayObject *)input; // check input array dimensions if (PyArray_NDIM (array) != 1) { @@ -161,7 +161,7 @@ Py_cvec_set_norm (Py_cvec * vec, PyObject *input, void * closure) if (vec->o->length != PyArray_SIZE (array)) { PyErr_Format (PyExc_ValueError, "input array has length %d, but cvec has length %d", - PyArray_SIZE (array), vec->o->length); + (int)PyArray_SIZE (array), vec->o->length); goto fail; } } @@ -183,7 +183,7 @@ fail: static int Py_cvec_set_phas (Py_cvec * vec, PyObject *input, void * closure) { - PyObject * array; + PyArrayObject * array; if (input == NULL) { PyErr_SetString (PyExc_ValueError, "input array is not a python object"); goto fail; @@ -191,23 +191,23 @@ Py_cvec_set_phas (Py_cvec * vec, PyObject *input, void * closure) if (PyArray_Check(input)) { // we got an array, convert it to a cvec.phas - if (PyArray_NDIM (input) == 0) { + if (PyArray_NDIM ((PyArrayObject *)input) == 0) { PyErr_SetString (PyExc_ValueError, "input array is a scalar"); goto fail; - } else if (PyArray_NDIM (input) > 2) { + } else if (PyArray_NDIM ((PyArrayObject *)input) > 2) { PyErr_SetString (PyExc_ValueError, "input array has more than two dimensions"); goto fail; } - if (!PyArray_ISFLOAT (input)) { + if (!PyArray_ISFLOAT ((PyArrayObject *)input)) { PyErr_SetString (PyExc_ValueError, "input array should be float"); goto fail; - } else if (PyArray_TYPE (input) != AUBIO_NPY_SMPL) { + } else if (PyArray_TYPE ((PyArrayObject *)input) != AUBIO_NPY_SMPL) { PyErr_SetString (PyExc_ValueError, "input array should be float32"); goto fail; } - array = input; + array = (PyArrayObject *)input; // check input array dimensions if (PyArray_NDIM (array) != 1) { @@ -219,7 +219,7 @@ Py_cvec_set_phas (Py_cvec * vec, PyObject *input, void * closure) if (vec->o->length != PyArray_SIZE (array)) { PyErr_Format (PyExc_ValueError, "input array has length %d, but cvec has length %d", - PyArray_SIZE (array), vec->o->length); + (int)PyArray_SIZE (array), vec->o->length); goto fail; } } -- 2.26.2