<html><head></head><body bgcolor="#FFFFFF"><div><br></div><blockquote type="cite"><div>
<p dir="ltr">c = a + b: 3N<br>
c = a + 2*b: 4N<br></p></div></blockquote><div>Does python garbage collect mid-expression? I.e. :</div><div><br></div><div>C = (a + 2*b) + b</div><div><br></div><div>4 or 5 N?</div><div><br></div><div>Also note that when memory gets tight, fragmentation can be a problem. I.e. if two size-n arrays where just freed, you still may not be able to allocate a size-2n array. This seems to be worse on windows, not sure why.</div>
<br><blockquote type="cite"><div><p dir="ltr">
a += b: 2N<br>
np.add(a, b, out=a): 2N<br>
b *= 2; a += b: 2N</p>
<p dir="ltr">Note that simply loading a and b requires 2N memory, so the latter code samples are near-optimal.</p></div></blockquote><div>And will run quite a bit faster for large arrays--pushing that memory around takes time.</div>
<div><br></div><div>-Chris</div><div><br></div></body></html>