[6780] | 1 | //****************************************************************************** |
---|
| 2 | // 'shim' code to use old Numeric API without deprecation warnings. |
---|
| 3 | // |
---|
| 4 | // This file is #included into every file that uses deprecated Numeric |
---|
| 5 | // functions. The entry points here are static, so no clash occurs. |
---|
| 6 | // |
---|
| 7 | // The deprecated Numeric functions are renamed from |
---|
| 8 | // PyArray_****() |
---|
| 9 | // to |
---|
| 10 | // anuga_****() |
---|
| 11 | // to pick up the definitions here. |
---|
| 12 | //****************************************************************************** |
---|
| 13 | |
---|
| 14 | #include "numpy/noprefix.h" |
---|
| 15 | |
---|
| 16 | #define anuga_FromDimsAndData(nd, d, type, data) \ |
---|
| 17 | anuga_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), data) |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | static PyObject * |
---|
| 21 | anuga_FromDimsAndDataAndDescr(int nd, int *d, PyArray_Descr *descr, char *data) |
---|
| 22 | { |
---|
| 23 | int i; |
---|
| 24 | npy_intp newd[MAX_DIMS]; |
---|
| 25 | |
---|
| 26 | if (!PyArray_ISNBO(descr->byteorder)) |
---|
| 27 | descr->byteorder = '='; |
---|
| 28 | |
---|
| 29 | for (i = 0; i < nd; i++) |
---|
| 30 | { |
---|
| 31 | newd[i] = (npy_intp) d[i]; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | return PyArray_NewFromDescr(&PyArray_Type, descr, nd, newd, NULL, data, |
---|
| 35 | (data ? CARRAY : 0), NULL); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | static PyObject * |
---|
| 39 | anuga_FromDims(int nd, int *d, int type) |
---|
| 40 | { |
---|
| 41 | PyObject *result; |
---|
| 42 | |
---|
| 43 | result = anuga_FromDimsAndDataAndDescr(nd, d, |
---|
| 44 | PyArray_DescrFromType(type), NULL); |
---|
| 45 | |
---|
| 46 | /* |
---|
| 47 | * Old FromDims set memory to zero --- some algorithms |
---|
| 48 | * relied on that. Better keep it the same. If |
---|
| 49 | * Object type, then it's already been set to zero, though. |
---|
| 50 | */ |
---|
| 51 | |
---|
| 52 | if (result && (PyArray_DESCR(result)->type_num != PyArray_OBJECT)) |
---|
| 53 | { |
---|
| 54 | memset(PyArray_DATA(result), 0, PyArray_NBYTES(result)); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | return result; |
---|
| 58 | } |
---|
| 59 | |
---|