[Numpy-discussion] PyInt and Numpy's int64 conversion

xantares 09 xantares09 at hotmail.com
Sat Dec 24 03:11:42 EST 2011




> From: wesmckinn at gmail.com
> Date: Fri, 23 Dec 2011 12:31:45 -0500
> To: numpy-discussion at scipy.org
> Subject: Re: [Numpy-discussion] PyInt and Numpy's int64 conversion
> 
> On Fri, Dec 23, 2011 at 4:37 AM, xantares 09 <xantares09 at hotmail.com> wrote:
> > Hi,
> >
> > I'm using Numpy from the C python api side while tweaking my SWIG interface
> > to work with numpy array types.
> > I want to convert a numpy array of integers (whose elements are numpy's
> > 'int64')
> > The problem is that it this int64 type is not compatible with the standard
> > python integer type:
> > I cannot use PyInt_Check, and PyInt_AsUnsignedLongMask to check and convert
> > from int64: basically PyInt_Check returns false.
> > I checked the numpy config header and npy_int64 does have a size of 8o,
> > which should be the same as int on my x86_64.
> > What is the correct way to do that ?
> > I checked for a Int64_Check function and didn't find any in numpy headers.
> >
> > Regards,
> >
> > x.
> >
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion at scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> >
> 
> hello,
> 
> I think you'll want to use the C macro PyArray_IsIntegerScalar, e.g.
> in pandas I have the following function exposed to my Cython code:
> 
> PANDAS_INLINE int
> is_integer_object(PyObject* obj) {
>   return PyArray_IsIntegerScalar(obj);
> }
> 
> last time I checked that macro detects Python int, long, and all of
> the NumPy integer hierarchy (int8, 16, 32, 64). If you ONLY want to
> check for int64 I am not 100% sure the best way.
> 
> - Wes

Hi,

Thank you for your reply !

That's the thing : I want to check/convert every type of integer, numpy's int64 and also python standard ints.
Is there a way to avoid to use only the python api ? ( and avoid to depend on numpy's PyArray_* functions ) 

Regards.

x.





 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20111224/f5efd5d4/attachment.html>


More information about the NumPy-Discussion mailing list