33%include <typemaps.i>
44
55%{
6+ #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
67#include < numpy/arrayobject.h>
78#include < math.h>
89#include < assert.h>
2829
2930// _reg: Inverse-Wishart prior on variance (with hard-coded
3031// variance prior I), with strength alpha.
31- static int em_fit_1d_samples_reg (PyObject* np_x ,
32- PyObject* np_amp ,
33- PyObject* np_mean ,
34- PyObject* np_var ,
32+ static int em_fit_1d_samples_reg (PyObject* po_x ,
33+ PyObject* po_amp ,
34+ PyObject* po_mean ,
35+ PyObject* po_var ,
3536 double alpha,
3637 int steps) {
3738 npy_intp i, N, K, k;
@@ -42,9 +43,11 @@ static int em_fit_1d_samples_reg(PyObject* np_x,
4243 double tpd;
4344 int result;
4445
45- PyArray_Descr* dtype = PyArray_DescrFromType (PyArray_DOUBLE);
46- int req = NPY_C_CONTIGUOUS | NPY_ALIGNED;
47- int reqout = req | NPY_WRITEABLE | NPY_UPDATEIFCOPY;
46+ PyArray_Descr* dtype = PyArray_DescrFromType (NPY_DOUBLE);
47+ int req = NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_ALIGNED;
48+ int reqout = req | NPY_ARRAY_WRITEABLE | NPY_ARRAY_UPDATEIFCOPY;
49+
50+ PyArrayObject *np_x, *np_amp, *np_mean, *np_var;
4851
4952 double * amp;
5053 double * mean;
@@ -54,22 +57,22 @@ static int em_fit_1d_samples_reg(PyObject* np_x,
5457 tpd = pow (2 .*M_PI, D);
5558
5659 Py_INCREF (dtype);
57- np_x = PyArray_FromAny (np_x , dtype, 1 , 1 , req, NULL );
60+ np_x = (PyArrayObject*) PyArray_FromAny (po_x , dtype, 1 , 1 , req, NULL );
5861 if (!np_x) {
5962 ERR (" x wasn't the type expected" );
6063 Py_DECREF (dtype);
6164 return -1 ;
6265 }
6366 Py_INCREF (dtype);
64- np_amp = PyArray_FromAny (np_amp , dtype, 1 , 1 , reqout, NULL );
67+ np_amp = (PyArrayObject*) PyArray_FromAny (po_amp , dtype, 1 , 1 , reqout, NULL );
6568 if (!np_amp) {
6669 ERR (" amp wasn't the type expected" );
6770 Py_DECREF (np_x);
6871 Py_DECREF (dtype);
6972 return -1 ;
7073 }
7174 Py_INCREF (dtype);
72- np_mean = PyArray_FromAny (np_mean , dtype, 1 , 1 , reqout, NULL );
75+ np_mean = (PyArrayObject*) PyArray_FromAny (po_mean , dtype, 1 , 1 , reqout, NULL );
7376 if (!np_mean) {
7477 ERR (" mean wasn't the type expected" );
7578 Py_DECREF (np_x);
@@ -78,7 +81,7 @@ static int em_fit_1d_samples_reg(PyObject* np_x,
7881 return -1 ;
7982 }
8083 Py_INCREF (dtype);
81- np_var = PyArray_FromAny (np_var , dtype, 1 , 1 , reqout, NULL );
84+ np_var = (PyArrayObject*) PyArray_FromAny (po_var , dtype, 1 , 1 , reqout, NULL );
8285 if (!np_var) {
8386 ERR (" var wasn't the type expected" );
8487 Py_DECREF (np_x);
@@ -243,10 +246,10 @@ static int em_fit_1d_samples(PyObject* np_x,
243246
244247// _reg: Inverse-Wishart prior on variance (with hard-coded
245248// variance prior I), with strength alpha.
246- static int em_fit_2d_reg (PyObject* np_img , int x0, int y0,
247- PyObject* np_amp ,
248- PyObject* np_mean ,
249- PyObject* np_var ,
249+ static int em_fit_2d_reg (PyObject* po_img , int x0, int y0,
250+ PyObject* po_amp ,
251+ PyObject* po_mean ,
252+ PyObject* po_var ,
250253 double alpha,
251254 int steps) {
252255 npy_intp i, N, K, k;
@@ -259,9 +262,11 @@ static int em_fit_2d_reg(PyObject* np_img, int x0, int y0,
259262 double tpd;
260263 int result;
261264
262- PyArray_Descr* dtype = PyArray_DescrFromType (PyArray_DOUBLE);
263- int req = NPY_C_CONTIGUOUS | NPY_ALIGNED;
264- int reqout = req | NPY_WRITEABLE | NPY_UPDATEIFCOPY;
265+ PyArray_Descr* dtype = PyArray_DescrFromType (NPY_DOUBLE);
266+ int req = NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_ALIGNED;
267+ int reqout = req | NPY_ARRAY_WRITEABLE | NPY_ARRAY_UPDATEIFCOPY;
268+
269+ PyArrayObject *np_img, *np_amp, *np_mean, *np_var;
265270
266271 double * amp;
267272 double * mean;
@@ -271,22 +276,22 @@ static int em_fit_2d_reg(PyObject* np_img, int x0, int y0,
271276 tpd = pow (2 .*M_PI, D);
272277
273278 Py_INCREF (dtype);
274- np_img = PyArray_FromAny (np_img , dtype, 2 , 2 , req, NULL );
279+ np_img = (PyArrayObject*) PyArray_FromAny (po_img , dtype, 2 , 2 , req, NULL );
275280 if (!np_img) {
276281 ERR (" img wasn't the type expected" );
277282 Py_DECREF (dtype);
278283 return -1 ;
279284 }
280285 Py_INCREF (dtype);
281- np_amp = PyArray_FromAny (np_amp , dtype, 1 , 1 , reqout, NULL );
286+ np_amp = (PyArrayObject*) PyArray_FromAny (po_amp , dtype, 1 , 1 , reqout, NULL );
282287 if (!np_amp) {
283288 ERR (" amp wasn't the type expected" );
284289 Py_DECREF (np_img);
285290 Py_DECREF (dtype);
286291 return -1 ;
287292 }
288293 Py_INCREF (dtype);
289- np_mean = PyArray_FromAny (np_mean , dtype, 2 , 2 , reqout, NULL );
294+ np_mean = (PyArrayObject*) PyArray_FromAny (po_mean , dtype, 2 , 2 , reqout, NULL );
290295 if (!np_mean) {
291296 ERR (" mean wasn't the type expected" );
292297 Py_DECREF (np_img);
@@ -295,7 +300,7 @@ static int em_fit_2d_reg(PyObject* np_img, int x0, int y0,
295300 return -1 ;
296301 }
297302 Py_INCREF (dtype);
298- np_var = PyArray_FromAny (np_var , dtype, 3 , 3 , reqout, NULL );
303+ np_var = (PyArrayObject*) PyArray_FromAny (po_var , dtype, 3 , 3 , reqout, NULL );
299304 if (!np_var) {
300305 ERR (" var wasn't the type expected" );
301306 Py_DECREF (np_img);
0 commit comments