[Numpy-discussion] numpy FFT memory accumulation
Ray S
subscriber100@rjs....
Thu Nov 1 14:16:03 CDT 2007
At 09:00 AM 11/1/2007, Chuck wrote:
In Python, collections.deque makes a pretty good circular buffer.
Numpy will
make an array out of it, which involves a copy, but it might be
better than what you are doing now.
hmmm, I'll think more about that - and the copy is only at program
start, it seems
the fft can always be fft(d[:-N])
>>> from collections import deque
>>> import numpy as N
>>> d = deque(N.zeros(10,))
>>> d.extend(N.ones(4,))
>>> d
deque([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0,
1.0, 1.0])
>>> [d.pop() for i in range(4)]
[1.0, 1.0, 1.0, 1.0]
>>> d
deque([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
An additional complication is that I pass the numpy (or Numeric)
array address to the ctypes library call so that the data is placed
directly into the array from the call. I use the if/else end wrap
logic to determine whether I need to do a split and copy if the new
data wraps.
Thanks,
Ray
More information about the Numpy-discussion
mailing list