[SciPy-dev] PyArray_FromDims and friends

Zachary Pincus zachary.pincus@yale....
Fri Aug 15 12:26:40 CDT 2008

> OK, then the patch in:
> http://scipy.org/scipy/scipy/ticket/723
> should do it for scipy.interpolate. It includes the proper casting-to-
> (*npy_intp) for 64-bit platforms.
> No, no, you can't just cast the pointer to a different type, it  
> needs to point to npy_intp instead of int to start with, i.e., n has  
> to be an array of npy_intp.

Thanks for looking that over. This is of course what happens when I  
try to deal with C too late at night.

For cases where the dimension was 1, I had originally had:

[whatever] = (PyArrayObject  

But I got compiler warnings to the tune of "The argument to & is not  
strictly an lvalue. This will be a hard error in the future." Which  
makes sense, (npy_intp)n isn't a proper lvalue... So I changed it to:

[whatever] = (PyArrayObject *)PyArray_SimpleNew(1, 

which, as you point out, is pretty daft.

Is there a correct, portable, and warning-free way to do this in one  
line? I'm guessing not. Anyhow, I'll fix the patch with a multi-line  
npy_int intp_n;
intp_n = (npy_intp) n;
[whatever] = (PyArrayObject  

Sorry for the noise, and thanks Chuck for the catch.


More information about the Scipy-dev mailing list