[Python-talk] Generator Question

bruce.labitt at autoliv.com bruce.labitt at autoliv.com
Wed Aug 12 10:41:18 EDT 2009


I have a couple questions on generators.  I have a requirement to 
synthesize a complicated (and complex) waveform.  I have been able to 
construct it using concatenation of arrays.  A problem arises when the 
arrays are very large - they fill my memory.  I have already maxed out my 
RAM on this machine (8GB), so I am looking to break up the problem into 
chunks.  This is similar to what I needed to do in my FFT engine that I 
wrote using FFTW.

Anyways, here are the questions:
1. Can a generator output an array instead of a single value at every 
call?
2. It is my understanding that once a generator has 'finished' the output 
is null?  Is that true?
3. Can a generator be reset or restarted?  How?

To give a context to my questions...

I'm intending to run an optimizer/search algorithm that finds the 
sequences that satisfy a power condition.  It appears there are a few 
choices that might work in scipy.optimize.  (Actually, the scipy package 
is VERY COOL.  Check it out if you ever have to do any number crunching. 
Lots of optimized code, syntax is a lot like matlab, and unlike matlab, it 
is quite free.)

The power condition is calculated by computing FFTs of the generator 
output.  The generator will be required to make say 100 arrays.  Once all 
100 arrays have been FFT'd, and the power computed, the optimizer will 
make a decision as to how to change the sequence to get the desired power 
output.  The generator will be reset and asked to use a new sequence as 
its input.   Wash, lather, repeat until done...  I can tell that this is 
going to be fun to debug...

OK, I'm asking for it now...  Is this an OK approach?  Or am I out in the 
weeds again?  I am bracing myself now...

Oh yeah, if someone could answer the specific questions, that would be 
good too ;)

I have read David Beazley's "Generator Tricks for Systems Programmers" 
www.dabeaz.com/generators although I have yet to absorb it all.

Be gentle...

Thanks for all your suggestions (and corrections) todate, they have been 
very helpful!

Bruce

******************************
Neither the footer nor anything else in this E-mail is intended to or constitutes an <br>electronic signature and/or legally binding agreement in the absence of an <br>express statement or Autoliv policy and/or procedure to the contrary.<br>This E-mail and any attachments hereto are Autoliv property and may contain legally <br>privileged, confidential and/or proprietary information.<br>The recipient of this E-mail is prohibited from distributing, copying, forwarding or in any way <br>disseminating any material contained within this E-mail without prior written <br>permission from the author. If you receive this E-mail in error, please <br>immediately notify the author and delete this E-mail.  Autoliv disclaims all <br>responsibility and liability for the consequences of any person who fails to <br>abide by the terms herein. <br>
******************************


More information about the Python-talk mailing list