带有类型提示的 cython 纯 python

rob*_*obm 5 python cython

我已经开发了 biopython 代码,我想通过添加 .pxd 文件并使用 cython 编译来加速我自己的应用程序。在此过程中,我添加了类型提示,因为我认为这将是一个改进(实际上我希望 cython 会自动使用它们,但事实并非如此)。现在我发现类型提示代码与我想要的 cython 增强不兼容。例如,采用cython numpy 教程中的 convolve_py.py 示例:

def naive_convolve(f, g):
Run Code Online (Sandbox Code Playgroud)

更改为:

def naive_convolve(f: np.ndarray, g: np.ndarray) -> np.ndarray:
Run Code Online (Sandbox Code Playgroud)

当我然后把

cpdef np.ndarray[np.int_t, ndim=2] naive_convolve(np.ndarray[np.int_t, ndim=2] f, np.ndarray[np.int_t, ndim=2] g)
Run Code Online (Sandbox Code Playgroud)

在相应的 .pxd 文件中(它适用于上面没有类型提示的情况)我得到:

def naive_convolve(f: np.ndarray, g: np.ndarray) -> np.ndarray:
              ^
------------------------------------------------------------

convolve_py.py:4:19: Compiler crash in AnalyseDeclarationsTransform
Run Code Online (Sandbox Code Playgroud)

我在自己的代码中使用更简单的类型得到了相同的结果。我的理解是 cython 应该处理 3.x 功能,并且文档引用了类型提示,我是否缺少其他方法或选项?我的编译行是:

cythonize -3 -i convolve_py.py convolve_py.pxd
Run Code Online (Sandbox Code Playgroud)