[Numpy-discussion] slow numpy.clip ?

David Cournapeau david at ar.media.kyoto-u.ac.jp
Mon Dec 18 03:45:09 EST 2006


Stefan van der Walt wrote:
> Hi David
>
> The benchmark below isn't quite correct.  In clip2_bench the data is
> effectively only clipped once.  I attach a slightly modified version,
> for which the benchmark results look like this:
Yes, I of course mistyped the < and the copy. But the function is still 
moderately faster on my workstation:

  ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.003    0.003    3.944    3.944 slowclip.py:10(bench_clip)
        1    0.011    0.011    2.001    2.001 slowclip.py:16(clip1_bench)
       10    1.990    0.199    1.990    0.199 
/home/david/local/lib/python2.4/site-packages/numpy/core/fromnumeric.py:372(clip)
        1    1.682    1.682    1.682    1.682 slowclip.py:19(clip2_bench)
        1    0.258    0.258    0.258    0.258 
slowclip.py:6(generate_data_2d)
        0    0.000             0.000          profile:0(profiler)

I agree this is not really much a difference, though. The question is 
then, in the context of matplotlib, is there really a need to copy ? 
Because if I do not copy the array before clipping, then the function is 
really faster (for those wondering, this is one bottleneck when calling 
matplotlib.imshow, used in specgram and so on),

cheers,

David




More information about the NumPy-Discussion mailing list