[SciPy-dev] reimplementation of lfilter

Sturla Molden sturla at molden.no
Tue Sep 22 20:25:13 EDT 2009


Ralf Gommers skrev:
> Sure, I know. The docs I linked have improvements over svn. If you 
> merge your changes, there'll be a conflict and those docs will not get 
> merged soon - I was hoping to avoid that.
>
> I also wanted to draw your attention to the doc wiki, since in this 
> case you redid work that was already done by someone else on the wiki 
> before. Hopefully this will save you some effort next time.

Well, I changed all the code to C++, to use the std::complex type, 
std::vector instead of malloc, and templates for specializing the filter 
functions to all dtypes supported by lfilter. I'm quite happy with the 
way the C++ looks :-)

It seems to be faster than signal.lfilter in most circumstances, except 
one (annoyingly the most common). The most extreme case were complex64 
dtype with inplace filtering, for which I got 369% speed improvement.

Here are some timings (speed improvement over signal.lfilter in percent):

<type 'numpy.float32'>
axis=0, shape=(1000000,),   speed: 240
axis=0, shape=(1000, 1000), speed: 149
axis=1, shape=(1000, 1000), speed: 238

<type 'numpy.float64'>
axis=0, shape=(1000000,),   speed: 151
axis=0, shape=(1000, 1000), speed:  93
axis=1, shape=(1000, 1000), speed: 146

<type 'numpy.complex64'>
axis=0, shape=(1000000,),   speed: 297
axis=0, shape=(1000, 1000), speed: 204
axis=1, shape=(1000, 1000), speed: 292

<type 'numpy.complex128'>
axis=0, shape=(1000000,),   speed: 209
axis=0, shape=(1000, 1000), speed: 137
axis=1, shape=(1000, 1000), speed: 193


Inplace filter:

<type 'numpy.float32'>
axis=0, shape=(1000000,), speed:   291
axis=0, shape=(1000, 1000), speed: 182
axis=1, shape=(1000, 1000), speed: 300

<type 'numpy.float64'>
axis=0, shape=(1000000,), speed:   227
axis=0, shape=(1000, 1000), speed: 137
axis=1, shape=(1000, 1000), speed: 228

<type 'numpy.complex64'>
axis=0, shape=(1000000,), speed:   369
axis=0, shape=(1000, 1000), speed: 257
axis=1, shape=(1000, 1000), speed: 345

<type 'numpy.complex128'>
axis=0, shape=(1000000,), speed:   288
axis=0, shape=(1000, 1000), speed: 179
axis=1, shape=(1000, 1000), speed: 276


To build on Windows I did this, using GCC 4.4.1 from 
http://www.equation.com/servlet/equation.cmd?fa=fortran

g++ -c -O3 -ffast-math -msse3 -march=core2 -Ic:/Python26/include 
-Ic:/Python26/Lib/site-packages/numpy/core/include _linear_filter.cpp
cython.py linear_filter.pyx
gcc -c -O2 -ffast-math -msse3 -march=core2 -Ic:/Python26/include 
-Ic:/Python26/Lib/site-packages/numpy/core/include linear_filter.c
g++ -shared -o linear_filter.pyd -Lc:/Python26/libs _linear_filter.o 
linear_filter.o -lpython26 -lmsvcr90



Best regards,

Sturla Molden













-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: _linear_filter.cpp
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20090923/2bdb4076/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: linear_filter.pyx
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20090923/2bdb4076/attachment-0001.ksh>


More information about the SciPy-Dev mailing list