[Numpy-discussion] Access dtype kind from cython

Eric Moore ewm at redtetrahedron.org
Mon Dec 29 20:55:05 EST 2014


On Monday, December 29, 2014, Valentin Haenel <valentin at haenel.co> wrote:

> Hi,
>
> how do I access the kind of the data from cython, i.e. the single
> character string:
>
> 'b' boolean
> 'i' (signed) integer
> 'u' unsigned integer
> 'f' floating-point
> 'c' complex-floating point
> 'O' (Python) objects
> 'S', 'a' (byte-)string
> 'U' Unicode
> 'V' raw data (void)
>
> In regular Python I can do:
>
> In [7]: d = np.dtype('S')
>
> In [8]: d.kind
> Out[8]: 'S'
>
> Looking at the definition of dtype that comes with cython, I see:
>
>   ctypedef class numpy.dtype [object PyArray_Descr]:
>       # Use PyDataType_* macros when possible, however there are no macros
>       # for accessing some of the fields, so some are defined. Please
>       # ask on cython-dev if you need more.
>       cdef int type_num
>       cdef int itemsize "elsize"
>       cdef char byteorder
>       cdef object fields
>       cdef tuple names
>
> I.e. no kind.
>
> Also, i looked for an appropriate PyDataType_* macro but couldn't find one.
>
> Perhaps there is something simple I could use?
>
> best,
>
> V-
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org <javascript:;>
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>From C or cython I'd just use the typenum. Compare against the appropriate
macros, NPY_DOUBLE e.g.

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


More information about the NumPy-Discussion mailing list