[Numpy-discussion] how to work with numpy.int8 in c
Wed Mar 3 11:06:01 CST 2010
Thanks all for your help, I think I'm on my way again.
The catch in the first place was not being confident that a
PyArray_Scalar was the thing I needed. I grep'd the code for uint8,
int8 and so on and could not find their definitions.
On first reading I overlooked the PyArray_Scalar link in this section:
But now that it has been pointed out, I think the reference docs are
good enough for me to do what I wanted.
So the docs are pretty good. I guess the only thing that I managed to
miss was the initial connection that a numpy.int8(6) is a
PyArray_Scalar instance. Seems obvious enough in hindsight...
On Wed, Mar 3, 2010 at 4:40 AM, David Cournapeau <email@example.com> wrote:
> 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);
>>> ^^^^ 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).
> NumPy-Discussion mailing list
More information about the NumPy-Discussion