Passing a numpy array of dtype np.float64_t
works fine ( below), but I can't pass string arrays.
This is what works :
# cython_testing.pyx
import numpy as np
cimport numpy as np
ctypedef np.float64_t dtype_t
cdef func1 (np.ndarray[dtype_t, ndim=2] A):
print A
def testing():
chunk = np.array ( [[94.,3.],[44.,4.]], dtype=np.float64)
func1 (chunk)
But I can't make this work: I can't find the matching 'type identifiers' for numpy string dtypes.
# cython_testing.pyx
import numpy as np
cimport numpy as np
ctypedef np.string_t dtype_str_t
cdef func1 (np.ndarray[dtype_str_t, ndim=2] A):
print A
def testing():
chunk = np.array ( [['huh','yea'],['swell','ray']], dtype=np.string_)
func1 (chunk)
The compilation error is :
Error compiling Cython file:
------------------------------------------------------------
ctypedef np.string_t dtype_str_t
^
------------------------------------------------------------
cython_testing.pyx:9:9: 'string_t' is not a type identifier
UPDATE
Per looking through numpy.pxd
, I see the following ctypedef
statements. Maybe that's enough to say I can use uint8_t
and pretend everything is normal, as long as I can do some casting?
ctypedef unsigned char npy_uint8
ctypedef npy_uint8 uint8_t
Just have to see how expensive that casting will be.