[Pythonmac-SIG] [SciPy-user] Best/Safest way to parse NumPy array in C extension?

Lou Pecora lou_boog2000 at yahoo.com
Tue Dec 12 17:28:31 CET 2006


YIKES.  That one line should read

mat=PyArray_ContiguousFromObject(Pymat,NPY_DOUBLE,2,2);

Very sorry.

--- Lou Pecora <lou_boog2000 at yahoo.com> wrote:

> I've done this two ways.  Which is better or safer?
> 
> Say I'm passing a NumPy array (float) to a C
> extension.  One way to "parse" it is (ignoring
> checks
> on return values, etc. for now),
> 
>   PyArrayObject *mat;
>   PyArg_ParseTuple(args, "O!", &PyArray_Type, &mat);
> 
> or is this better,
> 
>   PyObject *Pymat;
>   PyArrayObject *mat;
>   PyArg_ParseTuple(args, "O", &Pymat);
>   mat=PyArray_ContiguousFromObject(objin,NPY_DOUBLE,
> 2,2);
> 
> The latter appears to have the constraint that the
> array be contiguous.  Or is that an illusion and
> it's
> saying it _expects_ a Python object that has
> contiguous data?
> 
> I've done both.  Pointing C arrays to the resulting
> PyArrays' data works fine, but I fear one way or the
> other might be courting disaster.
> 
> BTW, I do other checks on dimension, type, etc., but
> I
> left those out here for clarity.  (I hope.)
> 
> 
> 
> 
> 
> -- Lou Pecora
>       My views are my own.
> 
> 
>  
>
____________________________________________________________________________________
> Do you Yahoo!?
> Everyone is raving about the all-new Yahoo! Mail
> beta.
> http://new.mail.yahoo.com
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
>
http://projects.scipy.org/mailman/listinfo/scipy-user
> 


-- Lou Pecora
      My views are my own.


 
____________________________________________________________________________________
Have a burning question?  
Go to www.Answers.yahoo.com and get answers from real people who know.


More information about the Pythonmac-SIG mailing list