-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved FFTW interface #1805
Comments
We may want to have an FFTW_Plan type, and then dispatch on that. |
So would there be a "default fftw plan" that is created during the sysimg.jl call, or would this have to be recomputed every time julia starts up? |
The plan depends on the size of the input. |
Oh, of course. So the current |
@staticfloat The only potential shortcomings of implementing fft(x) as plan_fft(x)(x) are One solution to (b) would be to internally have an unsafe_plan_fft(x) function which produces a function that does not check the shape/strides/alignment of its argument. You would then implement
and something like
Actually, on second thought (a) is not a problem---the lack of immediate garbage collection is actually a good thing. If the user calls fft(x) several times in a row, then if the previous plan is not yet garbage-collected FFTW will automatically re-use its table of trigonometric constants (which is destroyed when the last plan of a given size is fftw_destroy'ed). |
As mentioned in issue #1806, it would also be good to
And similarly for And for completeness you should probably have |
Agree. The FFTW interface is ripe for an overhaul. I propose using an We can then even have interfaces that allow reusing a plan by providing it as the first input argument.
|
I don't quite understand the point of an It seems like the only reason to have a separate |
The only reason I find the
That way, |
Effectively a plan is a function, so you might as well make it one for real since you have closures; aren't higher-order functions idiomatic too? Also, it has slightly different arguments from |
It would be good if the FFTWPlan would inherit from AbstractMatrix{T}. Then one can overload the operators * and \ like *{T}(A::FFTWPlan, x::Array{T,1}) = fftn(reshape(x, A.shape)) Note that this would require to store the shape of the underlying multidimensional fft in the plan, since the operator * should act on a vector, which however can represent a multidimensional structure. FFTWPlan may then be actually better named FFTMatrix or something like that. It would be cool if one could implement this for the common linear transformations in a consistent fashion (DCT, DST, Wavelet transform, ...) My intention for a matrix type for common structured linear transformations is that then one can for instance write iterative linear solvers and use them without any modifications on structured transformations. I have written some compressed sensing algorithms using an AbstractMatrix{T} type as argument and applied a SparseFFTMatrix to it, which implements * and \ and this worked nicely. |
@tknopp: You are missing the point: an FFTPlan is specific to a particular direction of transform, so a single plan cannot perform both Furthermore, this opens up a can of worms, I think. For one thing, one should really be able to multiply and add linear operators to produce new ones, so you need to make sure to define a bunch of new operations if you want this to be a general feature as opposed to an application-specific representation. (In some cases operators can be combined and simplified, and in other cases you will internally just compose the functions.) Furthermore, if you have a linear operator on 1d vectors and act it on a higher-dimensional array, it would make the most sense for it to act as a tensor contraction, i.e. act on the first dimension of the higher-dimensional array and loop over the other dimensions. And if you have a linear operator on higher-dimensional arrays and act it on a lower-dimensional one, it should just throw an error. Reshaping does not make sense to me in general, except for application-specific cases as mentioned below. Furthermore, in the former case of acting a 1d operator on a higher-dimensional array, using an FFTWPlan here does not work, because the whole point of an FFTWPlan (or an FFT function, or whatever) is that it is an optimized FFT for one particular size and shape (and alignment, etc.); performing a loop of FFT operations is best done with a separate plan. I totally agree that iterative linear solvers should work on AbstractMatrices that can be opaque functions, much like PETSc does. But you are really best off letting the user define such functions herself rather than trying to guess what that function will look like. For example, if one is using an iterative solver with a spectral method, the operator is almost certainly not just an FFT, it will be FFTs combined with other operations, so a predefined FFTOperator by itself will be pretty useless. So I think it makes the most sense to keep the the |
@stevengj: Ok, I wasn't aware anymore that the plan is only for one direction. Then, one probably should put the Matrix abstraction in a higher level package. On a first sight it seemed to be redundant to provide a low level plan and a matrix type when one type can do both. But you have proven me wrong. About the reshaping thing: My proposal was for a multidimensional Fourier Matrix (i.e. how to build a matrix type for fftn). The reshaping is only used to apply fftn with the right shape. It would not be sensible to operate for the * operator on a multidimensional array, when the FFTMatrix is supposed to be usable in iterative linear solvers, which I really like to implement in a generic way. I still think that it is useful to provide for common linear transformations a matrix type even when the users application might need more specialized transformations. As you propose, it should be possible to compose linear transformations. This could be done by a matrix product type. Simplification would be very cool, but would make it a very complex feature. Don't know if this is really necessary as these simplifications are usually carried out by hand. |
Fixed by #1856. |
Relevant discussion on julia-users https://groups.google.com/forum/#!topic/julia-users/kV-sKVFR2n0 |
From the discussion in #1617, @stevengj suggests updating the FFTW interface as follows.
The text was updated successfully, but these errors were encountered: