传递一个数组的dtype np.float64_t工作正常(下面),但我不能传递字符串数组.
这是有用的:
# 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)
但我不能这样做:
我找不到匹配的’类型标识符’为numpy字符串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)
编译错误是:
Error compiling Cython file:
------------------------------------------------------------
ctypedef np.string_t dtype_str_t
^
------------------------------------------------------------
cython_testing.pyx:9:9: 'string_t' is not a type identifier
UPDATE
通过查看numpy.pxd,我看到以下ctypedef语句.也许这足以说我可以使用uint8_t,假装一切正常,只要我可以做一些铸造?
ctypedef unsigned char npy_uint8
ctypedef npy_uint8 uint8_t
只需看看铸造将会有多昂贵.