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

WIP: new DFT api #6193

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
slightly smaller FFT twiddle arrays, fix disabled radix-2 step, inclu…
…de twiddlw Bluestein in tests
stevengj committed May 29, 2015

Verified

This commit was signed with the committer’s verified signature.
snyk-bot Snyk bot
commit 14f15d2f1c867abec95e3690faed7311232a35b2
17 changes: 9 additions & 8 deletions base/fft/ctfft.jl
Original file line number Diff line number Diff line change
@@ -174,7 +174,7 @@ macro twiddle(T, forward, n)
@inbounds @simd for i in 0:vn-1
$(fftgen(Complex{eval(T)}, forward, n,
j -> j == 0 ? :(X[(x0 + xvs*i) + xs*$j]) :
forward ? :(W[$(j+1),i+1] * X[(x0 + xvs*i) + xs*$j]) : :(mulconj(W[$(j+1),i+1], X[(x0 + xvs*i) + xs*$j])),
forward ? :(W[$j,i+1] * X[(x0 + xvs*i) + xs*$j]) : :(mulconj(W[$j,i+1], X[(x0 + xvs*i) + xs*$j])),
j -> :(X[(x0 + xvs*i) + xs*$j])))
end
X
@@ -222,7 +222,7 @@ end

Nontwiddle(T, n::Int, forw::Bool) = (T <: CTComplex && n in fft_kernel_sizes) || n in generic_kernel_sizes ? NontwiddleKernelStep{T}(n, forw) : NontwiddleBluesteinStep{T}(n, forw)

Twiddle(T, n::Int, r::Int, forw::Bool) = (T <: CTComplex && r in fft_kernel_sizes) || r == 4 ? TwiddleKernelStep{T}(n, r, forw) : TwiddleBluesteinStep{T}(n, r, forw)
Twiddle(T, n::Int, r::Int, forw::Bool) = (T <: CTComplex && r in fft_kernel_sizes) || r == 4 || r == 2 ? TwiddleKernelStep{T}(n, r, forw) : TwiddleBluesteinStep{T}(n, r, forw)

#############################################################################
# Combining pregenerated kernels into generic-size FFT plans:
@@ -322,7 +322,7 @@ immutable TwiddleKernelStep{T} <: TwiddleStep{T}
m = div(n, r)
Tr = promote_type(Float64, real(T))
twopi_n = -2/convert(Tr,n))
W = T[exp((twopi_n*mod(j1*k2,n))*im) for j1=0:r-1, k2=0:m-1]
W = T[exp((twopi_n*mod(j1*k2,n))*im) for j1=1:r-1, k2=0:m-1]
TwiddleKernelStep{T}(m, r, forward, W)
end
end
@@ -462,7 +462,7 @@ inv{T}(s::NontwiddleBluesteinStep{T}) =
NontwiddleBluesteinStep{T}(s.n, !s.forward)

show(io::IO, s::NontwiddleBluesteinStep) =
print(io, "size ", s.n, "Bluestein-", s.n2)
print(io, "size ", s.n, " Bluestein-", s.n2)

function applystep{T}(ns::NontwiddleBluesteinStep{T}, r,
x::AbstractArray{T}, x0, xs,
@@ -526,13 +526,13 @@ immutable TwiddleBluesteinStep{T} <: TwiddleStep{T}
b = bluestein_b(T, forward, r, r2)
B = p * b
new(r, m,
T[exp((twopi_n*mod(j1*k2,n))*im) for j1=0:r-1, k2=0:m-1],
T[exp((twopi_n*mod(j1*k2,n))*im) for j1=1:r-1, k2=0:m-1],
r2, p, a, A, b, B, forward)
end
end

show(io::IO, s::TwiddleBluesteinStep) =
print(io, "radix ", s.r, "Bluestein-", s.r2)
print(io, "radix ", s.r, " Bluestein-", s.r2)

inv{T}(s::TwiddleBluesteinStep{T}) =
TwiddleBluesteinStep{T}(s.r*s.m, s.r, !s.forward)
@@ -546,8 +546,9 @@ function applystep{T}(ts::TwiddleBluesteinStep{T}, y::AbstractArray{T}, y0,ys)
z = zero(T)
ys_ = ys*ts.m
for i = 1:ts.m
@inbounds for j = 1:ts.r
a[j] = W[j,i] * y[y0 + ys_*(j-1)] * b[j]'
a[1] = y[y0] * b[1]'
@inbounds for j = 2:ts.r
a[j] = W[j-1,i] * y[y0 + ys_*(j-1)] * b[j]'
end
@inbounds for j = ts.r+1:ts.r2
a[j] = z
2 changes: 1 addition & 1 deletion test/fft.jl
Original file line number Diff line number Diff line change
@@ -278,7 +278,7 @@ function fft_test{T<:Complex}(p::Base.DFT.Plan{T}, ntrials=4,
end

for T in (Complex64, Complex128)
for n in [1:100, 1000, 1024, 1031, 2000, 2048]
for n in [1:100, 121, 143, 1000, 1024, 1031, 2000, 2048]
x = zeros(T, n)
fft_test(plan_fft(x))
fft_test(plan_fft_(x))