[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Getfem-commits] r5057 - /trunk/getfem/interface/src/python/getfem_pytho
From: |
logari81 |
Subject: |
[Getfem-commits] r5057 - /trunk/getfem/interface/src/python/getfem_python.c |
Date: |
Mon, 27 Jul 2015 10:30:56 -0000 |
Author: logari81
Date: Mon Jul 27 12:30:56 2015
New Revision: 5057
URL: http://svn.gna.org/viewcvs/getfem?rev=5057&view=rev
Log:
use of the new numpy API again
Modified:
trunk/getfem/interface/src/python/getfem_python.c
Modified: trunk/getfem/interface/src/python/getfem_python.c
URL:
http://svn.gna.org/viewcvs/getfem/trunk/getfem/interface/src/python/getfem_python.c?rev=5057&r1=5056&r2=5057&view=diff
==============================================================================
--- trunk/getfem/interface/src/python/getfem_python.c (original)
+++ trunk/getfem/interface/src/python/getfem_python.c Mon Jul 27 12:30:56 2015
@@ -18,6 +18,8 @@
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
===========================================================================*/
+#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
+
#include <Python.h>
#include "numpy/arrayobject.h"
#include "structmember.h"
@@ -318,16 +320,16 @@
case NPY_ULONGLONG:
t->storage.type = GFI_INT32;
- if (1==((PyArrayObject *)o)->nd)// there is a bug in
PyArray_CheckFromAny ?
+ if (PyArray_NDIM((PyArrayObject *)o) == 1) // is there a bug in
PyArray_CheckFromAny ?
po = PyArray_CheckFromAny(o,PyArray_DescrFromType(NPY_INT),0,0,
- NPY_FORCECAST|NPY_OUT_ARRAY|NPY_ELEMENTSTRIDES,NULL);
+
NPY_ARRAY_FORCECAST|NPY_ARRAY_OUT_ARRAY|NPY_ARRAY_ELEMENTSTRIDES,NULL);
else
po = PyArray_CheckFromAny(o,PyArray_DescrFromType(NPY_INT),0,0,
- NPY_FORCECAST|NPY_OUT_FARRAY|NPY_ELEMENTSTRIDES,NULL);
+
NPY_ARRAY_FORCECAST|NPY_ARRAY_OUT_FARRAY|NPY_ARRAY_ELEMENTSTRIDES,NULL);
if(!po) { PyErr_NoMemory(); return NULL;}
gc_ref(gc,po);
- TGFISTORE(int32,val) = (int *)((PyArrayObject *)po)->data; // no new
copy
+ TGFISTORE(int32,val) = (int *)PyArray_DATA((PyArrayObject *)po); // no
new copy
break;
case NPY_FLOAT:
case NPY_DOUBLE:
@@ -335,16 +337,16 @@
t->storage.type = GFI_DOUBLE;
t->storage.gfi_storage_u.data_double.is_complex = 0;
- if (1==((PyArrayObject *)o)->nd)// there is a bug in
PyArray_CheckFromAny ?
+ if (PyArray_NDIM((PyArrayObject *)o) == 1)// is there a bug in
PyArray_CheckFromAny ?
po = PyArray_CheckFromAny(o,PyArray_DescrFromType(NPY_DOUBLE),0,0,
- NPY_FORCECAST|NPY_OUT_ARRAY|NPY_ELEMENTSTRIDES,NULL);
+
NPY_ARRAY_FORCECAST|NPY_ARRAY_OUT_ARRAY|NPY_ARRAY_ELEMENTSTRIDES,NULL);
else
po = PyArray_CheckFromAny(o,PyArray_DescrFromType(NPY_DOUBLE),0,0,
- NPY_FORCECAST|NPY_OUT_FARRAY|NPY_ELEMENTSTRIDES,NULL);
+
NPY_ARRAY_FORCECAST|NPY_ARRAY_OUT_FARRAY|NPY_ARRAY_ELEMENTSTRIDES,NULL);
if(!po) { PyErr_NoMemory(); return NULL;}
gc_ref(gc,po);
- TGFISTORE(double,val) = (double *)((PyArrayObject *)po)->data; // no
new copy
+ TGFISTORE(double,val) = (double *)PyArray_DATA((PyArrayObject *)po);
// no new copy
break;
case NPY_CFLOAT:
case NPY_CDOUBLE:
@@ -352,16 +354,16 @@
t->storage.type = GFI_DOUBLE;
t->storage.gfi_storage_u.data_double.is_complex = 1;
- if (1==((PyArrayObject *)o)->nd)// there is a bug in
PyArray_CheckFromAny ?
+ if (PyArray_NDIM((PyArrayObject *)o) == 1) // is there a bug in
PyArray_CheckFromAny ?
po = PyArray_CheckFromAny(o,PyArray_DescrFromType(NPY_CDOUBLE),0,0,
- NPY_FORCECAST|NPY_OUT_ARRAY|NPY_ELEMENTSTRIDES,NULL);
+
NPY_ARRAY_FORCECAST|NPY_ARRAY_OUT_ARRAY|NPY_ARRAY_ELEMENTSTRIDES,NULL);
else
po = PyArray_CheckFromAny(o,PyArray_DescrFromType(NPY_CDOUBLE),0,0,
- NPY_FORCECAST|NPY_OUT_FARRAY|NPY_ELEMENTSTRIDES,NULL);
+
NPY_ARRAY_FORCECAST|NPY_ARRAY_OUT_FARRAY|NPY_ARRAY_ELEMENTSTRIDES,NULL);
if(!po) { PyErr_NoMemory(); return NULL;}
gc_ref(gc,po);
- TGFISTORE(double,val) = (double *)((PyArrayObject *)po)->data; // no
new copy
+ TGFISTORE(double,val) = (double *)PyArray_DATA((PyArrayObject *)po);
// no new copy
break;
default: {
PyObject *sdtype =
PyObject_Str((PyObject*)PyArray_DescrFromType(dtype));
@@ -371,12 +373,12 @@
return NULL;
}
}
- t->dim.dim_len = ((PyArrayObject *)po)->nd;
+ t->dim.dim_len = PyArray_NDIM((PyArrayObject *)po);
t->dim.dim_val = (u_int *)gc_alloc(gc, t->dim.dim_len * sizeof(u_int));
int i;
for (i=0; i < t->dim.dim_len; ++i)
- t->dim.dim_val[i] = (u_int)((PyArrayObject *)po)->dimensions[i];
+ t->dim.dim_val[i] = (u_int)PyArray_DIM((PyArrayObject *)po,i);
} else if (PyTuple_Check(o) || PyList_Check(o)) {
//printf("Tuple or List\n");
/* python tuples and lists are stored in 'cell arrays' (i.e. matlab's
lists of inhomogeneous elements) */
@@ -476,9 +478,9 @@
if (!(o = PyArray_EMPTY(t->dim.dim_len, dim, NPY_INT, 1))) return NULL;
PyDimMem_FREE(dim);
- npy_intp itemsize = PyArray_ITEMSIZE(o); /*size of elements*/
- npy_intp size = PyArray_Size(o); /*number of elements*/
- memcpy(((PyArrayObject*)o)->data, TGFISTORE(int32,val), size*itemsize);
// new copy
+ npy_intp itemsize = PyArray_ITEMSIZE((PyArrayObject *)o); /*size of
elements*/
+ npy_intp size = PyArray_Size(o); /*number of
elements*/
+ memcpy(PyArray_DATA((PyArrayObject *)o), TGFISTORE(int32,val),
size*itemsize); // new copy
}
} break;
case GFI_DOUBLE: {
@@ -504,9 +506,9 @@
PyDimMem_FREE(dim);
}
}
- npy_intp itemsize = PyArray_ITEMSIZE(o); /*size of elements*/
- npy_intp size = PyArray_Size(o); /*number of elements*/
- memcpy(((PyArrayObject*)o)->data, TGFISTORE(double,val), size*itemsize);
// new copy
+ npy_intp itemsize = PyArray_ITEMSIZE((PyArrayObject *)o); /*size of
elements*/
+ npy_intp size = PyArray_Size(o); /*number of
elements*/
+ memcpy(PyArray_DATA((PyArrayObject *)o), TGFISTORE(double,val),
size*itemsize); // new copy
} break;
case GFI_CHAR: {
//printf("GFI_CHAR\n");
@@ -532,15 +534,15 @@
int i;
for(i=0; i< t->dim.dim_len; i++)
dim[i] = (npy_intp)t->dim.dim_val[i];
- if (!(o = PyArray_EMPTY(t->dim.dim_len, dim, PyArray_OBJECT,1))) return
NULL;
-
- if (!PyArray_ISFARRAY((PyArrayObject*)o)) { // I'm just too lazy to
transpose matrices
+ if (!(o = PyArray_EMPTY(t->dim.dim_len, dim, NPY_OBJECT,1))) return NULL;
+
+ if (!PyArray_ISFARRAY(PyArray_DATA((PyArrayObject *)o))) { // I'm just
too lazy to transpose matrices
PyErr_Format(PyExc_RuntimeError, "cannot return %d-D array of %d
getfem objects",
t->dim.dim_len, nb);
return NULL;
}
for (i = 0; i<nb; ++i) {
- ((PyObject**)(((PyArrayObject*)o)->data))[i] =
+ (PyObject*)PyArray_GETPTR1((PyArrayObject*)o,i) = // not compiling
PyGetfemObject_FromObjId(t->storage.gfi_storage_u.objid.objid_val[i],
in__init__);
}
#else
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Getfem-commits] r5057 - /trunk/getfem/interface/src/python/getfem_python.c,
logari81 <=