Python Cython中的向量赋值
这是我的赛昂节目Python Cython中的向量赋值,python,pointers,vector,cython,Python,Pointers,Vector,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 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"))
“编译器崩溃”是指一个bug。向cython用户ML或他们的GitHub提交错误报告。写入narray[i]=NULL或重新解释\u cast(0)是否有区别?(尽管同意larsmans将此报告为bug,因为它是以编译器崩溃的形式出现的),但他们没有在Github上启用问题跟踪器。