Re: subtle error slows code by 10x (builtin sum()) - replace builtin sum without using import?

2011-07-01 Thread Chris Torek
In article bdb112 wrote: >First a trap for new players, then a question to developers > >Code accelerated by numpy can be slowed down by a large factor is you >neglect to import numpy.sum . > >from timeit import Timer >frag = 'x=sum(linspace(0,1,1000))' >Timer(frag ,setup='from numpy import lins

Re: subtle error slows code by 10x (builtin sum()) - replace builtin sum without using import?

2011-07-01 Thread Albert Hopkins
On Friday, July 1 at 19:17 (-0700), bdb112 said: > Question: > Can I replace the builtin sum function globally for test purposes so > that my large set of codes uses the replacement? > > The replacement would simply issue warnings.warn() if it detected an > ndarray argument, then call the origi

subtle error slows code by 10x (builtin sum()) - replace builtin sum without using import?

2011-07-01 Thread bdb112
First a trap for new players, then a question to developers Code accelerated by numpy can be slowed down by a large factor is you neglect to import numpy.sum . from timeit import Timer frag = 'x=sum(linspace(0,1,1000))' Timer(frag ,setup='from numpy import linspace').timeit(1000) # 0.6 sec Timer(