这是我的cython程序
cdef struct Node:
int v
Node* next
Node* pre
def f(int N):
cdef:
vector[Node*] narray
int i
narray.assign(N, 0)
for i in xrange(N):
narray[i] = 0
Cython编译结果:
Error compiling Cython file:
------------------------------------------------------------
...
cdef:
vector[Node*] narray
int i
narray.assign(N, 0)
for i in xrange(N):
narray[i] = 0
^
------------------------------------------------------------
testLinkList.pyx:107:14: Compiler crash in AnalyseExpressionsTransform
但我可以使用 push_back()
在向量末尾追加值,或者使用 int
代替 Node*
。
怎么了?
最佳答案
您使用的是哪个版本的 Cython? 0.20.1 版适用于我的代码:
# distutils: language=c++
from libcpp.vector cimport vector
cdef struct Node:
int v
Node* next
Node* pre
def f(int N):
cdef:
vector[Node*] narray
int i
narray.assign(N, NULL)
for i in range(N):
narray[i] = NULL
使用这个 setup.py
文件:
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules=cythonize("test_vector.pyx"))
关于python - Cython 中的矢量分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15071786/