[Numpy-discussion] python eats memory like the cookie monster eats cookies

Robert Kern robert.kern at gmail.com
Sun Feb 4 15:20:52 EST 2007


Niels Provos wrote:
> Good morning,
> 
> not sure if I got the right list, but I hope that somebody here will
> be able to shed some light on a Python-related memory problem.  The
> following code eats over >2GB of memory and fails with MemoyError
> after just a few iterations.
> 
> def ZeroPadData(A, shape):
>     a = Numeric.zeros(shape, 'w')
>     a.savespace()
> 
>     for y in xrange(A.shape[0]):
>         for x in xrange(A.shape[1]):
>             a[y, x] = A[y, x]
> 
>     return a
> 
> def EatMemoryLikeTheCookieMonster(limit=10):
>     A = Numeric.ones([1998, 3022])
> 
>     count = 0
>     a = A
>     while count < limit:
>         print count
>         count += 1
> 
>         a = ZeroPadData(a, [2048, 4096])
> 
>         b = fft2(a)
>         b = ifft2(b)
> 
>         a = b[:1998,:3022].real
> 
> EatMemoryLikeTheCookieMonster()
> 
> This is for Python 2.4.3 on Mac OS X 10.4.8 (intel) using SciPy 0.5.2.

Could you also post a complete example? Why are you using Numeric? scipy 0.5.2
requires numpy, not Numeric. Where are the fft2() and ifft2() functions coming
from, scipy.fftpack or numpy?

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list