source: trunk/anuga_core/source/anuga/utilities/numpy_shim.h @ 7876

Last change on this file since 7876 was 7276, checked in by ole, 15 years ago

Merged numpy branch back into the trunk.

In ~/sandpit/anuga/anuga_core/source
svn merge -r 6246:HEAD ../../branches/numpy .

In ~/sandpit/anuga/anuga_validation
svn merge -r 6417:HEAD ../branches/numpy_anuga_validation .

In ~/sandpit/anuga/misc
svn merge -r 6809:HEAD ../branches/numpy_misc .

For all merges, I used numpy version where conflicts existed

The suites test_all.py (in source/anuga) and validate_all.py passed using Python2.5 with numpy on my Ubuntu Linux box.

File size: 1.7 KB
Line 
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
20static PyObject *
21anuga_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
38static PyObject *
39anuga_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
Note: See TracBrowser for help on using the repository browser.