[SciPy-dev] fftpack: building all backends and setting them at runtime (was dropping djbfft)
Pearu Peterson
pearu@cens.ioc...
Fri May 16 02:04:26 CDT 2008
David Cournapeau wrote:
> Hi,
>
> After some more work, I have modified scipy.fftpack such as backends
> are truely independent code-wise, and can be selected at runtime. I hope
> it adresses all remarks comments made in the previous thread:
>
> http://projects.scipy.org/scipy/scipy/browser/branches/refactor_fft/
>
> Concretely:
> - all fftw/fftw3/djbfft/mkl code has been put in
> scipy/fftpack/backends directory.
looks good to me.
> - All module .pyf files are almost duplication, but since we want to
> have them independent, I am not sure how to do better.
I agree on the independence. On the other hand, the signatures of
wrapper functions should be identical for all backends and I think
it can be ensured at the build time (and so saves some unittests).
The content of signature files that can be different for different
backends, is the callprotoargument and callstatement sections in .pyf files.
Other parts of the signature files should be identical (except the
module name). So, to minimize code duplication at the expense of
introducing two auxiliary files, one can organize the .pyf files as follows:
! File backends/fftw/fftw.pyf:
python module _fftw
include ../common/fft_part0.pyf
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(_fftw_error, &
"inconsistency in x.shape and s argument"); &
} &
}
include ../common/fft_part1.pyf
end python module _fftw
! File backends/fftw3/fftw3.pyf:
python module _fftw3
include ../common/fft_part0.pyf
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(_fftw3_error, &
"inconsistency in x.shape and s argument"); &
} &
}
include ../common/fft_part1.pyf
end python module _fftw3
Etc for the pyf files of mkl, djbfft backends. In fact,
also for the default fftpack backend.
I hope it is obvious what the fft_part0.pyf, .. files should contain.
Note that the wrapper function names do not need to contain the name
of a backend.
Pearu
More information about the Scipy-dev
mailing list