Skip to content

FFT convolutions ​

Loading FFTW lets a Convolution built with method = FFTMethod() run its lag sum by a fast Fourier transform (FFTMethod). It covers a fixed kernel on Float32 or Float64 arrays, and matches the direct method to a relative 1e-10, or 1e-4 in Float32. The transform is worth asking for with a long kernel, of hundreds of lags, over a long series.

julia
using ComposableRecurrences, FFTW
using ComposableRecurrences: Direct, FFTMethod
kernel = exp.(-(0:399) ./ 50) ./ 50
x = abs.(sin.(1:2000))
Convolution(kernel; method = FFTMethod())(x) ≈
    Convolution(kernel; method = Direct())(x)

# output

true

The reverse pass runs inside the package's own rule, so no AD backend needs FFT rules.