我正在尝试对此代码进行Cython化(GDTest.pyx
):
cimport numpy as np
import numpy as np
DTYPE = np.float64
ctypedef np.float64_t DTYPE_t
# Generates a matrix of Dirichlet random variates of size K
# Argument alpha: J x K matrix of Dirichlet parameters
# Returns g: J x K matrix of J Dirichlet draws, each of dimension K
# (each row sums to 1)
def GenerateDirich(np.ndarray alpha):
assert alpha.dtype==np.float64
cdef double fuzz = pow(10,-200)
cdef np.ndarray g=np.zeros((alpha.shape[0],alpha.shape[1]), dtype=DTYPE)
cdef np.ndarray gSum
g[:,:] = np.maximum(np.random.gamma(alpha[:,:]),fuzz)
gSum = np.sum(g,axis=1)
gSum = gSum[:,np.newaxis]
g = np.copy(g/(np.kron(np.ones((1,alpha.shape[1])),gSum)))
g=np.copy(g/np.repeat(gSum,alpha.shape[1]).reshape((gSum.shape[0],alpha.shape[1])))
return g
这是我的setup.py
:
from distutils.core import setup
from Cython.Build import cythonize
import numpy
setup(
ext_modules=cythonize('GDTest.pyx'),
include_dirs=[numpy.get_include()]
)
当我跑线时:
python setup.py -c mingw64 --inplace
我收到了一堆警告(不推荐使用的numpy API,以及一些与_Pyx_RaiseTooManyValuesError
相关的警告)但是它会创建GDTest.pyd
。当我尝试导入它时,我收到错误:
ImportError:DLL Load Failed: A dynamic link library (DLL) initialization routine failed.
我运行了依赖性walker,这就是它列为缺失的内容:
API-MS-WIN-CORE-KERNEL32-PRIVATE-L1-1-1.DLL
API-MS-WIN-CORE-PRIVATEPROFILE-L1-1-1.DLL
API-MS-WIN-SERVICE-PRIVATE-L1-1-1.DLL
MSVCR90.DLL
API-MS-WIN-CORE-SHUTDOWN-L1-1-1.DLL
EXT-MS-WIN-NTUSER-UICONTEXT-EXT-L1-1-0.DLL
IESHIMS.DLL
奇怪的是,如果我再次尝试导入它(import GDTest
),它就可以了。有关如何解决此问题的任何想法?
谢谢!
答案 0 :(得分:1)
我通过完全卸载遮篷修复了我的问题。然后,我安装了32位版本的anaconda和MS visual studio 2008 express版。它现在有效。万岁!