diff options
author | wfspotz@sandia.gov <wfspotz@sandia.gov@localhost> | 2007-04-01 01:06:47 +0000 |
---|---|---|
committer | wfspotz@sandia.gov <wfspotz@sandia.gov@localhost> | 2007-04-01 01:06:47 +0000 |
commit | fd85bb29c7f18dbae1fbfe439b692fce7d4e7618 (patch) | |
tree | b072ab7591971f86fa59e42f837006896402b326 /numpy/doc/swig/numpy.i | |
parent | cf82afda47fa40cff108942f92ff8ce5865592b2 (diff) | |
download | numpy-fd85bb29c7f18dbae1fbfe439b692fce7d4e7618.tar.gz |
Added tests for ARGOUT_ARRAY1 and ARGOUT_ARRAY2 typemaps
Diffstat (limited to 'numpy/doc/swig/numpy.i')
-rw-r--r-- | numpy/doc/swig/numpy.i | 47 |
1 files changed, 12 insertions, 35 deletions
diff --git a/numpy/doc/swig/numpy.i b/numpy/doc/swig/numpy.i index f19b4b0ef..656ed98f3 100644 --- a/numpy/doc/swig/numpy.i +++ b/numpy/doc/swig/numpy.i @@ -292,6 +292,7 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) { } return success; } + /* End John Hunter translation (with modifications by Bill Spotz) */ @@ -617,56 +618,32 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) { */ %typemap(in,numinputs=0) (DATA_TYPE ARGOUT_ARRAY1[ANY]) + (PyObject * array = NULL) { - $1 = (DATA_TYPE*) malloc($1_dim0*sizeof(DATA_TYPE)); - if (!$1) { - PyErr_SetString(PyExc_RuntimeError, "Failed to allocate memory"); - SWIG_fail; - } + npy_intp dims[1] = { $1_dim0 }; + array = PyArray_SimpleNew(1, dims, DATA_TYPECODE); + $1 = ($1_ltype)((PyArrayObject*)array)->data; } %typemap(argout) (DATA_TYPE ARGOUT_ARRAY1[ANY]) { - PyObject * obj = NULL; - npy_intp dimensions[1] = { $1_dim0 }; - PyObject* outArray = PyArray_FromDimsAndData(1, dimensions, DATA_TYPECODE, (char*)$1); - if ($result == Py_None) { - Py_DECREF($result); - $result = outArray; - } - else { - if (!PyTuple_Check($result)) $result = Py_BuildValue("(O)", $result); - obj = Py_Build_Value("(O)", outArray); - $result = PySequence_Concat($result, obj); - } + $result = SWIG_Python_AppendOutput($result,array$argnum); } /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY]) */ %typemap(in,numinputs=0) (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY]) + (PyObject * array = NULL) { - $1 = (DATA_TYPE*) malloc($1_dim0 * $1_dim1 * sizeof(DATA_TYPE)); - if (!$1) { - PyErr_SetString(PyExc_RuntimeError, "Failed to allocate memory"); - SWIG_fail; - } + npy_intp dims[2] = { $1_dim0, $1_dim1 }; + array = PyArray_SimpleNew(2, dims, DATA_TYPECODE); + $1 = ($1_ltype)((PyArrayObject*)array)->data; } %typemap(argout) - (DATA_TYPE ARGOUT_ARRAY1[ANY][ANY]) + (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY]) { - PyObject * obj = NULL; - npy_intp dimensions[2] = { $1_dim0, $1_dim1 }; - PyObject* outArray = PyArray_FromDimsAndData(1, dimensions, DATA_TYPECODE, (char*)$1); - if ($result == Py_None) { - Py_DECREF($result); - $result = outArray; - } - else { - if (!PyTuple_Check($result)) $result = Py_BuildValue("(O)", $result); - obj = Py_Build_Value("(O)", outArray); - $result = PySequence_Concat($result, obj); - } + $result = SWIG_Python_AppendOutput($result,array$argnum); } %enddef /* %numpy_typemaps() macro */ |