Python 赛顿记忆者

Python 赛顿记忆者,python,memory,numpy,cython,Python,Memory,Numpy,Cython,在为结果分配numpy数组的cdef中,我得到以下错误 ---> 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

在为结果分配numpy数组的cdef中,我得到以下错误

---> 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代码时,它几乎不消耗我的任何ram(在这个框中为12gb)。作为参考,bin_len可能在20左右,out_len可能在80000左右

pyx是使用python 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(),],
    )

在删除代码中的尾随“)”并以以下方式调用它后(当您计算余数//2时),我无法重建错误:

from numpy import *
import mi
if __name__ == '__main__':
    a = ones((20,300),mi.DTYPE)
    b = ones(20,mi.DTYPE)
    mi.full_pmfs(a,b) # gives you bin_len = 20 and out_len = 89850 
这对我来说很好


你到底是如何调用这个函数的?此外,有时cython错误消息在我的经验中可能有点错位,可能是后面的语句?

您确定bin_len和out_len是您认为的值吗?可能在之前插入打印语句?