0
在我为结果分配numpy数组的cdef中,出现以下错误。Cython MemoryError
---> 56 cdef np.ndarray[DTYPE_t, ndim=2] alignpmf = np.zeros([bin_len, out_len*bin_len],dtype=float)
MemoryError:
相关的代码是:
from __future__ import division
import numpy as np
cimport numpy as np
cimport cython
DTYPE = np.int
DTYPE_f = np.float
ctypedef np.float_t DTYPE_t
ctypedef np.int_t DTYPE_i
...
@cython.boundscheck(False)
@cython.wraparound(False)
def full_pmfs(np.ndarray[DTYPE_i, ndim=2] align, np.ndarray[DTYPE_i, ndim=1] bins):
assert align.dtype == DTYPE
assert bins.dtype == DTYPE
cdef int loop_ind_i, loop_ind_j, inner_count, inner_count_start, inner_count_stop
cdef int bin_len = bins.shape[0]
cdef int i_start_ind, i_stop_ind
cdef int seqs = align.shape[0]
cdef int residues = align.shape[1]
cdef int size = residues * bin_len
cdef int out_len = residues**2 - residues // 2)
cdef np.ndarray[DTYPE_t, ndim=2] alignpmf = np.zeros([bin_len,
out_len*bin_len],dtype=float)
...
是什么原因造成的错误任何线索?如果我用python编写相同的代码,我不会收到内存错误。当我运行纯粹的numpy或者cython代码时,它几乎不会消耗我的内存(这个盒子上的12GB)。作为参考,bin_len可能在20左右,out_len可能是80,000。
的PYX与蟒蛇编译setup.py build_ext --inplace:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy
ext_modules = [Extension("mi", ["mi.pyx"])]
setup(
name = 'MI calcs',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules,
include_dirs = [numpy.get_include(),],
)
你确定bin_len和out_len是你认为的值吗?也许之前插入一个打印语句? – tillsten 2012-06-04 19:24:38