[SciPy-user] Getting PyArray_Resize to work under weave
Travis E. Oliphant
Tue Jun 10 14:56:47 CDT 2008
Orest Kozyar wrote:
> I originally posted this on Numpy, but did not get any feedback. I've
> set up a temporary workaround by ensuring the Numpy array I pass to
> weave is much, much larger than I really expect it needs to be.
> However, I'd like to try and figure out why resize is not working.
> Any guidance?
> The following code fails:
> from scipy import weave
> from numpy import zeros
> arr = zeros((10,2))
> code = """
> PyArray_Dims dims;
> dims.len = 2;
> dims.ptr = Narr;
> dims.ptr += 10;
> PyArray_Resize(arr_array, &dims, 1);
> weave.inline(code, ['arr'], verbose=1)
> The error message is:
> In function 'PyObject* compiled_func(PyObject*, PyObject*)':
> <filename>:678: error: too few arguments to function
> 678 is the line number for PyArray_Resize. According to the NumPy
> Handbook, PyArray_Resize requires three arguments, which I am
> providing. Am I missing something obvious here? There are times when
> I need to be able to resize the array in C++ because I cannot predict
> exactly how big the array needs to be before I pass it to weave. Any
> advice or pointers greatly appreciated!
The function was updated ahead of the book. There is a NPY_order
fortran argument at the end that must be supplied to PyArray_Resize.
Use this for the last line of your C-code.
PyArray_Resize(arr_array, &dims, 1, NPY_ANYORDER);
More information about the SciPy-user