In a cdef where I allocate a numpy array for my results I get the following error.
---> 56 cdef np.ndarray[DTYPE_t, ndim=2] alignpmf = np.zeros([bin_len, out_len*bin_len],dtype=float)
MemoryError:
The relevant code is:
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)
...
Any clues on what is causing the error? If I write up the same code in python I don’t get a memory error. When I run either the pure numpy or cython code it doesn’t consume hardly any of my ram(12gb on this box). For reference, bin_len might be around 20 and out_len might be 80,000.
The pyx is compiled with 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(),],
)
I could not reconstruct the error – after removing the trailing “)” in your code (when you calculate the residues // 2) and calling it in the following way:
This works fine for me.
How are you calling the function exactly? Also, sometimes cython error messages can be a bit misplaced in my experience, maybe it’s the statement after?