在cython记忆视图中摸索的麻烦。。。我如何在这里实现?

在cython记忆视图中摸索的麻烦。。。我如何在这里实现?,cython,Cython,两个函数:一个用于创建3200万整数数组,另一个用于数百万次查找 from cpython cimport array as c_array from array import array def get_lut(file_location): cdef c_array.array lut with open(file_location, "rb") as f: lut = array("I", f.read()) return lut def use

两个函数:一个用于创建3200万整数数组,另一个用于数百万次查找

from cpython cimport array as c_array
from array import array

def get_lut(file_location):
    cdef c_array.array lut
    with open(file_location, "rb") as f:
        lut = array("I", f.read())
    return lut

def use_lut(int[:] lut):
    // Do a whole bunch of lookups.
使用以下命令编译:

c:\Users\Michael\Documents\Poker>set DISTUTILS_USE_SDK=1
c:\Users\Michael\Documents\Poker>python setup.py build_ext -i --compiler=msvc
生成以下输出:

Compiling handeval.pyx because it changed.
Cythonizing handeval.pyx
warning: View.MemoryView:288:5: Cannot profile nogil function.
warning: View.MemoryView:763:5: Cannot profile nogil function.
warning: View.MemoryView:899:5: Cannot profile nogil function.
warning: View.MemoryView:1063:5: Cannot profile nogil function.
warning: View.MemoryView:1070:5: Cannot profile nogil function.
warning: View.MemoryView:1124:5: Cannot profile nogil function.
warning: View.MemoryView:1131:5: Cannot profile nogil function.
warning: View.MemoryView:1142:5: Cannot profile nogil function.
warning: View.MemoryView:1163:5: Cannot profile nogil function.
warning: View.MemoryView:1223:5: Cannot profile nogil function.
warning: View.MemoryView:1295:5: Cannot profile nogil function.
warning: View.MemoryView:1317:5: Cannot profile nogil function.
warning: View.MemoryView:1352:5: Cannot profile nogil function.
warning: View.MemoryView:1362:5: Cannot profile nogil function.
running build_ext
building 'handeval' extension
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\amd64\cl.exe /c /nolo
go /Ox /MD /W3 /GS- /DNDEBUG -IC:\Users\Michael\Anaconda3\include -IC:\Users\Mic
hael\Anaconda3\include /Tchandeval.c /Fobuild\temp.win-amd64-3.4\Release\handeva
l.obj
handeval.c
handeval.c(2391) : warning C4244: '+=' : conversion from 'Py_ssize_t' to 'long',
 possible loss of data
handeval.c(2420) : warning C4244: '+=' : conversion from 'Py_ssize_t' to 'int',
possible loss of data
handeval.c(2449) : warning C4244: '+=' : conversion from 'Py_ssize_t' to 'int',
possible loss of data
handeval.c(2478) : warning C4244: '+=' : conversion from 'Py_ssize_t' to 'int',
possible loss of data
handeval.c(2507) : warning C4244: '+=' : conversion from 'Py_ssize_t' to 'int',
possible loss of data
handeval.c(2536) : warning C4244: '+=' : conversion from 'Py_ssize_t' to 'int',
possible loss of data
handeval.c(2565) : warning C4244: '+=' : conversion from 'Py_ssize_t' to 'int',
possible loss of data
handeval.c(12955) : error C2275: 'PyGILState_STATE' : illegal use of this type a
s an expression
        C:\Users\Michael\Anaconda3\include\pystate.h(191) : see declaration of '
PyGILState_STATE'
handeval.c(12955) : error C2146: syntax error : missing ';' before identifier '_
_pyx_gilstate_save'
handeval.c(12955) : error C2065: '__pyx_gilstate_save' : undeclared identifier
handeval.c(13026) : error C2065: '__pyx_gilstate_save' : undeclared identifier
handeval.c(13052) : error C2275: 'PyGILState_STATE' : illegal use of this type a
s an expression
        C:\Users\Michael\Anaconda3\include\pystate.h(191) : see declaration of '
PyGILState_STATE'
handeval.c(13052) : error C2146: syntax error : missing ';' before identifier '_
_pyx_gilstate_save'
handeval.c(13052) : error C2065: '__pyx_gilstate_save' : undeclared identifier
handeval.c(13125) : error C2065: '__pyx_gilstate_save' : undeclared identifier
handeval.c(13152) : error C2275: 'PyGILState_STATE' : illegal use of this type a
s an expression
        C:\Users\Michael\Anaconda3\include\pystate.h(191) : see declaration of '
PyGILState_STATE'
handeval.c(13152) : error C2146: syntax error : missing ';' before identifier '_
_pyx_gilstate_save'
handeval.c(13152) : error C2065: '__pyx_gilstate_save' : undeclared identifier
handeval.c(13242) : error C2065: '__pyx_gilstate_save' : undeclared identifier
handeval.c(13909) : error C2275: 'PyGILState_STATE' : illegal use of this type a
s an expression
        C:\Users\Michael\Anaconda3\include\pystate.h(191) : see declaration of '
PyGILState_STATE'
handeval.c(13909) : error C2146: syntax error : missing ';' before identifier '_
_pyx_gilstate_save'
handeval.c(13909) : error C2065: '__pyx_gilstate_save' : undeclared identifier
handeval.c(13935) : error C2065: '__pyx_gilstate_save' : undeclared identifier
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\Bin\\
amd64\\cl.exe' failed with exit status 2
然而,从use_lut签名中删除int[:]类型声明可以很好地编译


这里我做错了什么?

您的代码缺少以下导入:从cpython cimport array作为c_array,从array import array-如果我替换//执行一系列查找。顺便说一句,您的代码在OSXApologies上编译得很好,请从我复制/粘贴的代码中删除这些代码。它们就在那里。运行cython handeval.pyx生成C文件,然后添加handeval.C的第12955行和它周围的几行,作为问题的上下文,可能是值得的。我怀疑诊断仍然是一个挑战…您必须使用array.array吗?我用np.arraydata,dtype=np.int32做了类似的例子