Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

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

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

    print A 

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

My Guesses

I am guessing that a type identifier is what's created explicitly w/ the Cython C-like typedef syntax

ctypedef np.float64_t dtype_t

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

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

The Numpy documentation on dtypes doesn't help me. http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html

like image 860
HeyWatchThis Avatar asked Jun 12 '12 20:06

HeyWatchThis


1 Answers

in your cython code, you do:

import numpy as np
cimport numpy as np

the first line import numpy module in python space, but the second line just include numpy.pxd in cython space.

you can found numpy.pxd in you cython install folder. It define float64_t as:

ctypedef double       npy_float64
ctypedef npy_float64    float64_t
like image 85
HYRY Avatar answered Sep 28 '22 02:09

HYRY