麻烦的cython内存视图...我如何在这里实现?

时间:2015-04-06 12:27:08

标签: 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_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

int[:]签名中删除use_lut类型声明编译正确。

我在这里做错了什么?

0 个答案:

没有答案