【发布时间】:2012-06-12 18:59:10
【问题描述】:
传递一个 dtype np.float64_t 的 numpy 数组可以正常工作(如下),但我不能传递字符串数组。
这是有效的:
# 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
更新
通过查看numpy.pxd,我看到了以下ctypedef 语句。也许这足以说明我可以使用 uint8_t 并假装一切正常,只要我能做一些演员表?
ctypedef unsigned char npy_uint8
ctypedef npy_uint8 uint8_t
只需要看看这个选角会有多贵。
【问题讨论】: