[SciPy-dev] fftpack: building all backends and setting them at runtime (was dropping djbfft)

Pearu Peterson pearu@cens.ioc...
Fri May 16 09:44:46 CDT 2008


On Fri, May 16, 2008 4:45 pm, Pearu Peterson wrote:

> I'll take a look at the branch and see if I can figure something
> easier out..

Ok, here follows a simpler solution that uses numpy.distutils pyf.src
templating tools. I'll give an example using fftw3 backend only because
exactly the same technique applies to other backends. Below follows
the corresponding diff and it works.
If you find it a reasonable approach, I can
commit the diff to the refactor_fft branch.

Pearu

pearu@utlaan-laptop:~/svn/refactor_fft/scipy/fftpack/backends$ svn diff
Index: fftw3/setup.py
===================================================================
--- fftw3/setup.py      (revision 4373)
+++ fftw3/setup.py      (working copy)
@@ -13,7 +13,10 @@
                            sources = src,
                            include_dirs = ["../common",
                                            info['include_dirs']])
-        config.add_extension("_fftw3", sources = ["fftw3.pyf"],
extra_info = info, libraries = ["fftw3_backend"])
+        config.add_extension("_fftw3", sources = ["fftw3.pyf.src"],
+                             depends = ['../fft_template.pyf.src'],
+                             extra_info = info,
+                             libraries = ["fftw3_backend"])

 def configuration(parent_package='',top_path=None):
     from numpy.distutils.misc_util import Configuration
Index: fftw3/fftw3.pyf.src
===================================================================
--- fftw3/fftw3.pyf.src (revision 0)
+++ fftw3/fftw3.pyf.src (revision 0)
@@ -0,0 +1,9 @@
+! -*- f90 -*-
+
+! <modulename=_fftw3>
+
+python module _fftw3
+  interface
+include '../fft_template.pyf.src'
+  end interface
+end python module _fftw3
Index: fft_template.pyf.src
===================================================================
--- fft_template.pyf.src        (revision 0)
+++ fft_template.pyf.src        (revision 0)
@@ -0,0 +1,72 @@
+!%f90 -*- f90 -*-
+! Author: Pearu Peterson, August 2002
+! This file is included by the files <backend>/<backend>.pyf.src
+
+       subroutine zfft<modulename>(x,n,direction,howmany,normalize)
+         ! y = fft(x[,n,direction,normalize,overwrite_x])
+         intent(c) zfft<modulename>
+         complex*16 intent(c,in,out,copy,out=y) :: x(*)
+         integer optional,depend(x),intent(c,in) :: n=size(x)
+         check(n>0) n
+         integer depend(x,n),intent(c,hide) :: howmany = size(x)/n
+         check(n*howmany==size(x)) howmany
+         integer optional,intent(c,in) :: direction = 1
+         integer optional,intent(c,in),depend(direction) &
+              :: normalize = (direction<0)
+       end subroutine zfft<modulename>
+
+       subroutine drfft<modulename>(x,n,direction,howmany,normalize)
+         ! y = drfft(x[,n,direction,normalize,overwrite_x])
+         intent(c) drfft<modulename>
+         real*8 intent(c,in,out,copy,out=y) :: x(*)
+         integer optional,depend(x),intent(c,in) :: n=size(x)
+         check(n>0&&n<=size(x)) n
+         integer depend(x,n),intent(c,hide) :: howmany = size(x)/n
+         check(n*howmany==size(x)) howmany
+         integer optional,intent(c,in) :: direction = 1
+         integer optional,intent(c,in),depend(direction) &
+              :: normalize = (direction<0)
+       end subroutine drfft<modulename>
+
+!       subroutine zrfft<modulename>(x,n,direction,howmany,normalize)
+!         ! y = zrfft(x[,n,direction,normalize,overwrite_x])
+!         intent(c) zrfft<modulename>
+!         complex*16 intent(c,in,out,overwrite,out=y) :: x(*)
+!         integer optional,depend(x),intent(c,in) :: n=size(x)
+!         check(n>0&&n<=size(x)) n
+!         integer depend(x,n),intent(c,hide) :: howmany = size(x)/n
+!         check(n*howmany==size(x)) howmany
+!         integer optional,intent(c,in) :: direction = 1
+!         integer optional,intent(c,in),depend(direction) &
+!              :: normalize = (direction<0)
+!       end subroutine zrfft<modulename>
+
+       subroutine zfftnd<modulename>(x,r,s,direction,howmany,normalize,j)
+         ! y = zfftnd(x[,s,direction,normalize,overwrite_x])
+         intent(c) zfftnd<modulename>
+         complex*16 intent(c,in,out,copy,out=y) :: x(*)
+         integer intent(c,hide),depend(x) :: r=old_rank(x)
+         integer intent(c,hide) :: j=0
+         integer optional,depend(r),dimension(r),intent(c,in) &
+              :: s=old_shape(x,j++)
+         check(r>=len(s)) s
+         integer intent(c,hide) :: howmany = 1
+         integer optional,intent(c,in) :: direction = 1
+         integer optional,intent(c,in),depend(direction) :: &
+              normalize = (direction<0)
+         callprotoargument complex_double*,int,int*,int,int,int
+         callstatement {&
+              int i,sz=1,xsz=size(x); &
+              for (i=0;i<r;++i) sz *= s[i]; &
+              howmany = xsz/sz; &
+              if (sz*howmany==xsz) &
+                (*f2py_func)(x,r,s,direction,howmany,normalize); &
+              else {&
+                f2py_success = 0; &
+                PyErr_SetString(<modulename>_error, &
+                  "inconsistency in x.shape and s argument"); &
+                } &
+              }
+       end subroutine zfftnd<modulename>
+
+! See http://cens.ioc.ee/projects/f2py2e/






More information about the Scipy-dev mailing list