[SciPy-Dev] replacing integrate.cumtrapz with numpy.trapz

Ralf Gommers ralf.gommers@googlemail....
Sat Jul 17 10:52:30 CDT 2010


On Sat, Jul 17, 2010 at 9:52 PM, Jonathan Stickel <jjstickel@vcn.com> wrote:

> On 7/17/10 07:38 , Ralf Gommers wrote:
>
>>
>>
>> On Sat, Jul 17, 2010 at 8:57 PM, Charles R Harris
>> <charlesr.harris@gmail.com <mailto:charlesr.harris@gmail.com>> wrote:
>>
>>
>>
>>    On Sat, Jul 17, 2010 at 2:42 AM, Ralf Gommers
>>    <ralf.gommers@googlemail.com <mailto:ralf.gommers@googlemail.com>>
>>
>>    wrote:
>>
>>        integrate.cumtrapz and numpy.trapz do exactly the same thing and
>>        the code is very similar but not identical, as pointed out in
>>        http://projects.scipy.org/scipy/ticket/720. Assuming numpy.trapz
>>        is not going anywhere, can we replace the scipy version with it?
>>
>>        For a small bonus, the numpy version is about 10% faster (tested
>>        for several array shapes):
>>         >>> a = np.arange(1e4).reshape(500, 20)
>>         >>> %timeit np.trapz(a, axis=1)
>>        10000 loops, best of 3: 182 us per loop
>>         >>> %timeit sp.integrate.cumtrapz(a, axis=1)
>>        1000 loops, best of 3: 209 us per loop
>>
>>
>>    Replacement seems reasonable to me. We should try to prune duplicate
>>    functionality with numpy taking precedence.
>>
>> Just to double check, that also means deprecating the name cumtrapz right?
>>
>>
> Uh, you do realize that trapz and cumtrapz provide different functionality,
> right?
>
> Actually no, sorry for the noise. Now I'm not sure what the point of that
ticket was. Maybe to replace part of the code in cumtrapz with trapz? Or the
submitter made the same mistake as I just did.

Ralf



> In [5]: import scipy.integrate as igt
>
> In [8]: a = np.arange(10)
>
> In [9]: igt.cumtrapz(a)
> Out[9]: array([  0.5,   2. ,   4.5,   8. ,  12.5,  18. ,  24.5,  32. ,
> 40.5])
>
> In [10]: np.trapz(a)
> Out[10]: 40.5
>
> In [11]: igt.trapz(a)
> Out[11]: 40.5
>
> This is numpy-1.4.1 and scipy-0.7.2.
>
> Jonathan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-dev/attachments/20100717/2d1d2979/attachment-0001.html 


More information about the SciPy-Dev mailing list