Skip to content

Commit 9e73ae1

Browse files
authored
Merge pull request #61 from JuliaMath/an/fewermethods
Remove singleton FFT types and some methods
2 parents ac171b5 + 5ee2aaa commit 9e73ae1

File tree

3 files changed

+26
-82
lines changed

3 files changed

+26
-82
lines changed

src/algos.jl

Lines changed: 26 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
fft!(::AbstractVector{T}, ::AbstractVector{T}, ::Int, ::Int, ::Direction, ::AbstractFFTType, ::CallGraph{T}, ::Int) where {T} = nothing
2-
31
@inline function direction_sign(d::Direction)
42
Int(d)
53
end
64

75
@inline _conj(w::Complex, d::Direction) = ifelse(direction_sign(d) === 1, w, conj(w))
86

9-
function (g::CallGraph{T})(out::AbstractVector{T}, in::AbstractVector{U}, start_out::Int, start_in::Int, v::Direction, t::FFTEnum, idx::Int) where {T,U}
10-
fft!(out, in, start_out, start_in, v, t, g, idx)
11-
end
12-
13-
14-
function fft!(out::AbstractVector, in::AbstractVector, start_out::Int, start_in::Int, d::Direction, e::FFTEnum, g::CallGraph, idx::Int)
15-
if e === compositeFFT
16-
fft!(out, in, start_out, start_in, d, CompositeFFT(), g, idx)
17-
elseif e == dft
18-
fft!(out, in, start_out, start_in, d, DFT(), g, idx)
19-
elseif e === pow2FFT
20-
fft!(out, in, start_out, start_in, d, Pow2FFT(), g, idx)
21-
elseif e === pow3FFT
22-
fft!(out, in, start_out, start_in, d, Pow3FFT(), g, idx)
23-
elseif e === pow4FFT
24-
fft!(out, in, start_out, start_in, d, Pow4FFT(), g, idx)
7+
function fft!(out::AbstractVector{T}, in::AbstractVector{T}, start_out::Int, start_in::Int, d::Direction, t::FFTEnum, g::CallGraph{T}, idx::Int) where T
8+
if t === compositeFFT
9+
fft_composite!(out, in, start_out, start_in, d, g, idx)
2510
else
26-
throw(ArgumentError("kernel not implemented"))
11+
root = g[idx]
12+
if t == dft
13+
fft_dft!(out, in, root.sz, start_out, root.s_out, start_in, root.s_in, _conj(root.w, d))
14+
else
15+
N = root.sz
16+
s_in = root.s_in
17+
s_out = root.s_out
18+
if t === pow2FFT
19+
fft_pow2!(out, in, N, start_out, s_out, start_in, s_in, _conj(root.w, d))
20+
elseif t === pow3FFT
21+
p_120 = convert(T, cispi(2/3))
22+
m_120 = convert(T, cispi(4/3))
23+
_p_120, _m_120 = d == FFT_FORWARD ? (p_120, m_120) : (m_120, p_120)
24+
fft_pow3!(out, in, N, start_out, s_out, start_in, s_in, _conj(root.w, d), _m_120, _p_120)
25+
elseif t === pow4FFT
26+
fft_pow4!(out, in, N, start_out, s_out, start_in, s_in, _conj(root.w, d))
27+
else
28+
throw(ArgumentError("kernel not implemented"))
29+
end
30+
end
2731
end
2832
end
2933

@@ -42,7 +46,7 @@ Cooley-Tukey composite FFT, with a pre-computed call graph
4246
`idx`: Index of the current transform in the call graph
4347
4448
"""
45-
function fft!(out::AbstractVector{T}, in::AbstractVector{U}, start_out::Int, start_in::Int, d::Direction, ::CompositeFFT, g::CallGraph{T}, idx::Int) where {T,U}
49+
function fft_composite!(out::AbstractVector{T}, in::AbstractVector{U}, start_out::Int, start_in::Int, d::Direction, g::CallGraph{T}, idx::Int) where {T,U}
4650
root = g[idx]
4751
left_idx = idx + root.left
4852
right_idx = idx + root.right
@@ -59,7 +63,7 @@ function fft!(out::AbstractVector{T}, in::AbstractVector{U}, start_out::Int, sta
5963
tmp = g.workspace[idx]
6064
@inbounds for j1 in 0:N1-1
6165
wk2 = wj1
62-
g(tmp, in, N2*j1+1, start_in + j1*s_in, d, right.type, right_idx)
66+
fft!(tmp, in, N2*j1+1, start_in + j1*s_in, d, right.type, g, right_idx)
6367
j1 > 0 && @inbounds for k2 in 1:N2-1
6468
tmp[N2*j1 + k2 + 1] *= wk2
6569
wk2 *= wj1
@@ -68,7 +72,7 @@ function fft!(out::AbstractVector{T}, in::AbstractVector{U}, start_out::Int, sta
6872
end
6973

7074
@inbounds for k2 in 0:N2-1
71-
g(out, tmp, start_out + k2*s_out, k2+1, d, left.type, left_idx)
75+
fft!(out, tmp, start_out + k2*s_out, k2+1, d, left.type, g, left_idx)
7276
end
7377
end
7478

@@ -129,11 +133,6 @@ function fft_dft!(out::AbstractVector{Complex{T}}, in::AbstractVector{T}, N::Int
129133
end
130134
end
131135

132-
function fft!(out::AbstractVector{T}, in::AbstractVector{U}, start_out::Int, start_in::Int, d::Direction, ::DFT, g::CallGraph{T}, idx::Int) where {T,U}
133-
root = g[idx]
134-
fft_dft!(out, in, root.sz, start_out, root.s_out, start_in, root.s_in, _conj(root.w, d))
135-
end
136-
137136
"""
138137
$(TYPEDSIGNATURES)
139138
Power of 2 FFT, in place
@@ -171,13 +170,6 @@ function fft_pow2!(out::AbstractVector{T}, in::AbstractVector{U}, N::Int, start_
171170
end
172171
end
173172

174-
function fft!(out::AbstractVector{T}, in::AbstractVector{U}, start_out::Int, start_in::Int, d::Direction, ::Pow2FFT, g::CallGraph{T}, idx::Int) where {T,U}
175-
root = g[idx]
176-
N = root.sz
177-
s_in = root.s_in
178-
s_out = root.s_out
179-
fft_pow2!(out, in, N, start_out, s_out, start_in, s_in, _conj(root.w, d))
180-
end
181173

182174
"""
183175
$(TYPEDSIGNATURES)
@@ -232,13 +224,6 @@ function fft_pow4!(out::AbstractVector{T}, in::AbstractVector{U}, N::Int, start_
232224
end
233225
end
234226

235-
function fft!(out::AbstractVector{T}, in::AbstractVector{U}, start_out::Int, start_in::Int, d::Direction, ::Pow4FFT, g::CallGraph{T}, idx::Int) where {T,U}
236-
root = g[idx]
237-
N = root.sz
238-
s_in = root.s_in
239-
s_out = root.s_out
240-
fft_pow4!(out, in, N, start_out, s_out, start_in, s_in, _conj(root.w, d))
241-
end
242227

243228
"""
244229
$(TYPEDSIGNATURES)
@@ -288,17 +273,3 @@ function fft_pow3!(out::AbstractVector{T}, in::AbstractVector{U}, N::Int, start_
288273
wk2 *= w2
289274
end
290275
end
291-
292-
function fft!(out::AbstractVector{T}, in::AbstractVector{U}, start_out::Int, start_in::Int, d::Direction, ::Pow3FFT, g::CallGraph{T}, idx::Int) where {T,U}
293-
root = g[idx]
294-
N = root.sz
295-
s_in = root.s_in
296-
s_out = root.s_out
297-
p_120 = convert(T, cispi(2/3))
298-
m_120 = convert(T, cispi(4/3))
299-
if d == FFT_FORWARD
300-
fft_pow3!(out, in, N, start_out, s_out, start_in, s_in, _conj(root.w, d), m_120, p_120)
301-
else
302-
fft_pow3!(out, in, N, start_out, s_out, start_in, s_in, _conj(root.w, d), p_120, m_120)
303-
end
304-
end

src/callgraph.jl

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
@enum Direction FFT_FORWARD=-1 FFT_BACKWARD=1
22
@enum Pow24 POW2=2 POW4=1
3-
4-
abstract type AbstractFFTType end
5-
6-
# Represents a Composite Cooley-Tukey FFT
7-
struct CompositeFFT <: AbstractFFTType end
8-
9-
# Represents a Radix-2 Cooley-Tukey FFT
10-
struct Pow2FFT <: AbstractFFTType end
11-
12-
# Represents a Radix-3 Cooley-Tukey FFT
13-
struct Pow3FFT <: AbstractFFTType end
14-
15-
# Represents a Radix-4 Cooley-Tukey FFT
16-
struct Pow4FFT <: AbstractFFTType end
17-
18-
# Represents an O(N²) DFT
19-
struct DFT <: AbstractFFTType end
20-
21-
223
@enum FFTEnum compositeFFT dft pow2FFT pow3FFT pow4FFT
234

245
"""

test/runtests.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
using Test, Random, FFTA
22

3-
function padnum(m,x)
4-
digs = floor(Int, log10(m))
5-
digs_x = floor(Int, log10(x))
6-
v = fill(' ', digs-digs_x)
7-
for d in digits(x)[end:-1:1] push!(v, '0' + d) end
8-
String(v)
9-
end
10-
113
function naive_1d_fourier_transform(x::Vector, d::FFTA.Direction)
124
n = length(x)
135
y = zeros(Complex{Float64}, n)

0 commit comments

Comments
 (0)