我试图加快答案在这里使用用Cython.我尝试编译代码(在执行此处cygwinccompiler.py解释的hack 之后),但是出错了.任何人都可以告诉我,如果这是我的代码的问题,或Cython的一些深奥的微妙?fatal error: numpy/arrayobject.h: No such file or directory...compilation terminated
以下是我的代码.提前致谢:
import numpy as np
import scipy as sp
cimport numpy as np
cimport cython
cdef inline np.ndarray[np.int, ndim=1] fbincount(np.ndarray[np.int_t, ndim=1] x):
cdef int m = np.amax(x)+1
cdef int n = x.size
cdef unsigned int i
cdef np.ndarray[np.int_t, ndim=1] c = np.zeros(m, dtype=np.int)
for i in xrange(n):
c[<unsigned int>x[i]] += 1
return c
cdef packed struct Point:
np.float64_t f0, f1
@cython.boundscheck(False)
def sparsemaker(np.ndarray[np.float_t, ndim=2] …Run Code Online (Sandbox Code Playgroud) 在我的安装中,numpy arrayobject.h位于…/site-packages/numpy/core/include/numpy/arrayobject.h.我写了一个使用numpy的简单Cython脚本:
cimport numpy as np
def say_hello_to(name):
print("Hello %s!" % name)
Run Code Online (Sandbox Code Playgroud)
我也有以下distutils setup.py(从Cython用户指南复制):
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension("hello", ["hello.pyx"])]
setup(
name = 'Hello world app',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)
Run Code Online (Sandbox Code Playgroud)
当我尝试构建时python setup.py build_ext --inplace,Cython尝试执行以下操作:
gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd \
-fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DMACOSX \
-I/usr/include/ffi -DENABLE_DTRACE -arch i386 -arch ppc -pipe \
-I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 …Run Code Online (Sandbox Code Playgroud)