<p>多亏了所有有用的评论,我写了我自己的summator,看起来运行得很快。如果任何人有任何建议,使它更好,我将乐意接受他们。在</p>
<p>我将在我正在处理的问题上测试这个问题,一旦它证明成功,我将声称它是有效的。在</p>
<pre><code>def integers(blk_size=100):
x = arange(0, blk_size)
while True:
yield x
yield -x -1
x += blk_size
#
# For convergent summation
# on not necessarily finite sequences
# processes in blocks which can be any size
# shape that the function can handle
#
def converge_sum(f, x_strm, eps=1e-5, axis=0):
total = sum(f(x_strm.next()), axis=axis)
for x_blk in x_strm:
diff = sum(f(x_blk), axis=axis)
if abs(linalg.norm(diff)) <= eps:
# Converged
return total + diff
else:
total += diff
</code></pre>