[Numpy-discussion] checking for array type in C extension

Pauli Virtanen pav at iki.fi
Fri Jun 18 09:26:55 EDT 2010


pe, 2010-06-18 kello 12:49 +0200, Berthold Hoellmann kirjoitti:
[clip]
> tst.inttestfunc(np.array((1,2),dtype=np.int))
> tst.inttestfunc(np.array((1,2),dtype=np.int8))
> tst.inttestfunc(np.array((1,2),dtype=np.int16))
> tst.inttestfunc(np.array((1,2),dtype=np.int32))
> tst.inttestfunc(np.array((1,2),dtype=np.int64))
> 
> hoel at pc090498 ~/pytest $ PYTHONPATH=build/lib.win32-2.5/ python xx.py
> 1.4.1 ['C:\\Python25\\lib\\site-packages\\numpy']
> PyArray_TYPE(array): 7; NPY_INT: 5
> NPY_INT not found
> PyArray_TYPE(array): 1; NPY_INT: 5
> NPY_INT not found
> PyArray_TYPE(array): 3; NPY_INT: 5
> NPY_INT not found
> PyArray_TYPE(array): 7; NPY_INT: 5
> NPY_INT not found
> PyArray_TYPE(array): 9; NPY_INT: 5
> NPY_INT not found
>
> NPY_INT32 is 7, but shouldn't NPY_INT correspond to numpy.int. And what
> kind of int is NPY_INT in this case?

I think the explanation is the following:

- NPY_INT is a virtual type that is either int32 or int64, depending on
  the native platform size.

- It has its own type code, distinct from NPY_SHORT (= 3 = int32) and
  NPY_LONG (= 7 = int64).

- But the type specifier is replaced either by NPY_SHORT or NPY_LONG
  on array creation, so no array is of this dtype.

	Pauli





More information about the NumPy-Discussion mailing list