[Numpy-discussion] Access dtype kind from cython

Valentin Haenel valentin at haenel.co
Tue Dec 30 18:03:39 EST 2014


* Eric Moore <ewm at redtetrahedron.org> [2014-12-30]:
> 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.

That would be nice, but I am refactoring existing code and it is
specifically asking for the kind character.

V-



More information about the NumPy-Discussion mailing list