Skip to content
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

implement fft and related functions #60

Closed
ViralBShah opened this issue Jun 18, 2011 · 18 comments
Closed

implement fft and related functions #60

ViralBShah opened this issue Jun 18, 2011 · 18 comments
Assignees

Comments

@ViralBShah
Copy link
Member

We need fft before launch. I assume FFTW is the only realistic library we can use. If it is too much of a pain to integrate until our full C FFI is ready, we can go with FFTPACK.

@JeffBezanson
Copy link
Member

How does this look:

http://sourceforge.net/projects/kissfft/

Or is FFTPACK the kind of code that's really hard to beat?

@StefanKarpinski
Copy link
Member

My understanding is that FFTW is the kind of code that's hard to beat, but I suspect Viral and others know much more about it than I do.

@ViralBShah
Copy link
Member Author

FFTPACK is an old well known code that many projects use. I don't think it is particularly fast or anything.

It may also be possible to write a useful fft in julia, as a placeholder until we get fftw.

If kissfft is not used by at least a few projects, we will end up becoming beta testers.

-viral

On Jun 19, 2011, at 2:01 AM, JeffBezanson wrote:

How does this look:

http://sourceforge.net/projects/kissfft/

Or is FFTPACK the kind of code that's really hard to beat?

Reply to this email directly or view it on GitHub:
#60 (comment)

@StefanKarpinski
Copy link
Member

I just pushed bc774de which lets you download, compile and setup FFTW. Haven't tried actually using it yet, but it's a start.

@ViralBShah
Copy link
Member Author

From the manual, this is what the code looks like. So, either, we need to write a simple thin wrapper that is callable from julia, or wait until julia can support a more general C FFI.

Another benefit of FFTW could be that we can use their matrix transpose routines too, which are quite fast.

#include <fftw3.h>
...
{
    fftw_complex *in, *out;
    fftw_plan p;
    ...
    in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
    ...
    fftw_execute(p); /* repeat as needed */
    ...
    fftw_destroy_plan(p);
    fftw_free(in); fftw_free(out);
}

-viral

@ViralBShah
Copy link
Member Author

Coming to think of it, we can just use the Fortran calling interface, and get fftw to work immediately.

http://fftw.org/fftw3_doc/Calling-FFTW-from-Fortran.html#Calling-FFTW-from-Fortran

-viral

On Jun 19, 2011, at 4:31 AM, StefanKarpinski wrote:

I just pushed bc774de which lets you download, compile and setup FFTW. Haven't tried actually using it yet, but it's a start.

Reply to this email directly or view it on GitHub:
#60 (comment)

@StefanKarpinski
Copy link
Member

I don't get why we can't use the C interface. Because of the data layout or because of the plan bit? The data layout is actually not a problem since fftw_complex is just a pair of doubles, so a Julia array of Complex128's has the desired layout. Not sure about the plan bit admittedly. Why is the Fortran interface better?

@ViralBShah
Copy link
Member Author

How do we create all the structs that fftw defines in fftw.h in julia and pass them through the C interface? If we can, then we can use the C interface - but I always thought this was not possible.

-viral

On Jun 19, 2011, at 5:14 AM, StefanKarpinski wrote:

I don't get why we can't use the C interface. Because of the data layout or because of the plan bit? The data layout is actually not a problem since fftw_complex is just a pair of doubles, so a Julia array of Complex128's has the desired layout. Not sure about the plan bit admittedly. Why is the Fortran interface better?

Reply to this email directly or view it on GitHub:
#60 (comment)

@ViralBShah
Copy link
Member Author

The only reason to use the fortran interface is that it is likely to be free of passing the C structs around.

-viral

On Jun 19, 2011, at 5:14 AM, StefanKarpinski wrote:

I don't get why we can't use the C interface. Because of the data layout or because of the plan bit? The data layout is actually not a problem since fftw_complex is just a pair of doubles, so a Julia array of Complex128's has the desired layout. Not sure about the plan bit admittedly. Why is the Fortran interface better?

Reply to this email directly or view it on GitHub:
#60 (comment)

ViralBShah added a commit that referenced this issue Jun 22, 2011
@ViralBShah
Copy link
Member Author

Well, seems like I can just treat all fftw data structures as void * and pass them around. Keeping this bug open until we implement most of the fft related functions - FFT2, FFTN, FFTSHIFT, IFFT, IFFT2, IFFTN.. We probably also need to do some saving of the plans and such.

julia> x = complex(ones(8),ones(8))
[1.0 + 1.0im,1.0 + 1.0im,1.0 + 1.0im,1.0 + 1.0im,1.0 + 1.0im,1.0 + 1.0im,1.0 + 1.0im,1.0 + 1.0im]

julia> fft(x)
[8.0 + 8.0im,0.0 + 0.0im,0.0 + 0.0im,0.0 + 0.0im,0.0 + 0.0im,0.0 + 0.0im,0.0 + 0.0im,0.0 + 0.0im]

@JeffBezanson
Copy link
Member

Excellent!
Don't forget fftw_destroy_plan.

@ViralBShah
Copy link
Member Author

Good catch - fixed.

Commit 021afbf also makes includes fft in the regular julia build and startup.

@StefanKarpinski
Copy link
Member

This is awesome. Just what I hoped might happen if I setup the download and compilation bit :-)

@ViralBShah
Copy link
Member Author

Yes - I wouldn't have gone through all this just to try out and see if it would work. However, with your download and compile done, I found myself sitting on a plane, and thought, what the heck, let's try it out.

-viral

On Jun 22, 2011, at 12:37 PM, StefanKarpinski wrote:

This is awesome. Just what I hoped might happen if I setup the download and compilation bit :-)

Reply to this email directly or view it on GitHub:
#60 (comment)

@StefanKarpinski
Copy link
Member

Excellent :-D

@ViralBShah
Copy link
Member Author

Discussion on subarray relevant here, for ability to compute fft on slices of arrays.

http://groups.google.com/group/julia-math/browse_thread/thread/f07b1f6047d98a8c/

@ViralBShah
Copy link
Member Author

Good discussion on real valued FFT, and general stuff - including posts by Steve Johnson:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/39968

@StefanKarpinski
Copy link
Member

Yeah, that is an awesome thread. Gives a lot of faith in the quality of the FFTW implementation. Glad we're using it :-)

@ghost ghost assigned ViralBShah Jul 8, 2011
ViralBShah added a commit that referenced this issue Jul 10, 2011
StefanKarpinski pushed a commit that referenced this issue Feb 8, 2018
Fixes #60 (unless there are strong objections)
StefanKarpinski pushed a commit that referenced this issue Feb 8, 2018
* implement "garbage collection"
Keno pushed a commit that referenced this issue Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants