Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8035297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:16:16+00:00 2026-06-05T02:16:16+00:00

In a cdef where I allocate a numpy array for my results I get

  • 0

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(),],
    )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:16:17+00:00Added an answer on June 5, 2026 at 2:16 am

    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:

    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 
    

    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?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider the following: import numpy as np cimport numpy as np DTYPE = np.float
I have a numpy array which came from a cv2.imread and so has dtype
I'd like to do the following: cdef extern from foo.h namespace foo: int bar(int,
I am using the following Jamfile ( in directory /home/morpheus/base/CDef ) : lib CDef
I want to speed up the following code using cython: class A(object): cdef fun(self):
I have this Cython class: cdef class Sprite: def __init__(self, someargument): pass And I
I have the following program. module C def self.included(base) base.extend(ClassMethods) end module ClassMethods def
How do I expose the following class using Boost.Python? class C { public: static
For the following Python 2.7 code: #!/usr/bin/python def func_a(): print "func_a" c = 0
Example : S1 : abcde S2: cdef Answer : cde

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.