What is the difference between numpy "type identifiers" and "types" in Cython?

What is confusing is that if you want to create an array that you use

chunk = np.array ( [[94.,3.],[44.,4.]], dtype=np.float64) 

But if you want to determine the type inside the buffer reference, you use

 cdef func1 (np.ndarray[np.float64_t, ndim=2] A): print A 

Note the difference between np.float64 and np.float64_t .

My fortune-telling

I assume a type identifier is what is explicitly created by the w / Cython C-like typedef syntax

 ctypedef np.float64_t dtype_t 

But the numpy type is just a Python <type 'type'> .

 >>> type ( np.float64) <type 'type'> 

Numpy's dtype doesn't help me. http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html

+7
source share
1 answer

in your cython code:

 import numpy as np cimport numpy as np 

the numper input module is the first line in python space, but the second line includes numpy.pxd in cython space.

you can find numpy.pxd in the cython installation folder. It defines float64_t as:

 ctypedef double npy_float64 ctypedef npy_float64 float64_t 
+6
source

All Articles