6

これが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*。なにが問題ですか?

4

1 に答える 1

2

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"))
于 2014-05-15T14:54:11.737 に答える