[Numpy-discussion] how to work with numpy.int8 in c

David Cournapeau david@silveregg.co...
Wed Mar 3 03:40:45 CST 2010


Francesc Alted wrote:
> A Wednesday 03 March 2010 02:58:31 David Cournapeau escrigué:
>>> PyObject *ret;
>>> PyArray_Descr *typecode;
>>>
>>>
>>> typecode = PyArray_DescrFromType(PyArray_UINT8);
>>> ret = PyArray_Scalar(NULL, typecode, NULL);
>>> Py_DECREF(typecode);
>> ^^^^ Sorry, this is wrong, this does not work on my machine, but I am
>> not sure to understand why.
> 
> Well, at least the next works in Cython:
> 
> cdef npy_int8 next
> cdef dtype int8
> cdef object current
> 
> [...]
> int8 = PyArray_DescrFromType(NPY_INT8)
> current = PyArray_Scalar(&next, int8, None)

Yes, what does not work is the Py_DECREF on typecode. Maybe I 
misunderstand the comment on PyArray_Scalar (typecode is not used but 
cannot be NULL).

cheers,

David



More information about the NumPy-Discussion mailing list