Inplace fft convolution


#1

Dear all,

I would like to perform an inplace fft-based convolution. But somehow my inplace convolution is slower than the regular one. Can anyone give me hint why?

Thank you for your help,

Best regards

Jf(x) = 0.5exp(-abs(x))
N = 2^12;L = 100
const hx = 2L/N
const X = -L + hx*collect(0:N-1)
const wHat = fft(Jf(X))*hx

function convolution(x)
    return ifftshift(real(ifft(wHat .* fft(x))))
end

function convolution!(x)
    x_ = fft(x)
    @. x_ .= wHat .* x_
    ifft!(x_)
    @. x .= real(x_)
    x .= ifftshift(x)
end

x1 = rand(N)
    y1 = @time convolution(x1)
    @time convolution!(x1)

#2

The in-place version is faster on Julia 0.7 (perhaps also on 0.6). So, update the version.
Reminder, the FFT and friends functions have moved into FFTW package, which forgot to add some exports, so to get your example to work I had to:

Pkg.add("FFTW")
import FFTW: fft, ifft, ifftshift, ifft!

and then the code goes through.


#3

Thank you!!