Skip to content

Commit f1d6d1c

Browse files
authored
Merge pull request #55 from JuliaMath/an/forwardrealdft
Fix and test the real DFT
2 parents f1955c5 + 501ddb7 commit f1d6d1c

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/algos.jl

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,16 @@ end
8989

9090
function fft_dft!(out::AbstractVector{Complex{T}}, in::AbstractVector{T}, N::Int, start_out::Int, stride_out::Int, start_in::Int, stride_in::Int, d::Direction) where {T<:Real}
9191
halfN = N÷2
92-
wk = wkn = w = convert(Complex{T}, cispi(direction_sign(d)*2/N))
9392

94-
tmpBegin = tmpHalf = in[start_in]
93+
tmp = Complex{T}(in[start_in])
9594
@inbounds for j in 1:N-1
96-
tmpBegin += in[start_in + stride_in*j]
97-
iseven(j) ? tmpHalf += in[start_in + stride_in*j] : tmpHalf -= in[start_in + stride_in*j]
95+
tmp += in[start_in + j*stride_in]
9896
end
99-
out[start_out] = convert(Complex{T}, tmpBegin)
100-
iseven(N) && (out[start_out + stride_out*halfN] = convert(Complex{T}, tmpHalf))
97+
out[start_out] = tmp
10198

99+
wk = wkn = w = convert(Complex{T}, cispi(direction_sign(d)*2/N))
102100
@inbounds for d in 1:halfN
103-
tmp = in[start_in]
101+
tmp = Complex{T}(in[start_in])
104102
@inbounds for k in 1:N-1
105103
tmp += wkn*in[start_in + k*stride_in]
106104
wkn *= wk
@@ -109,9 +107,6 @@ function fft_dft!(out::AbstractVector{Complex{T}}, in::AbstractVector{T}, N::Int
109107
wk *= w
110108
wkn = wk
111109
end
112-
@inbounds for k in halfN+1:N-1
113-
out[start_out + stride_out*k] = conj(out[start_out + stride_out*(N-k)])
114-
end
115110
end
116111

117112
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}

test/onedim/real_forward.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ end
1212

1313
@testset verbose = true "against naive implementation. Size: $n" for n in 1:64
1414
x = randn(n)
15-
@test naive_1d_fourier_transform(x, FFTA.FFT_FORWARD)[1:(n ÷ 2 + 1)] rfft(x)
15+
y = rfft(x)
16+
@test naive_1d_fourier_transform(x, FFTA.FFT_FORWARD)[1:(n ÷ 2 + 1)] y
17+
18+
@testset "temporarily test real dft separately until used by rfft" begin
19+
y_dft = similar(y)
20+
FFTA.fft_dft!(y_dft, x, n, 1, 1, 1, 1, FFTA.FFT_FORWARD)
21+
@test y y_dft
22+
end
1623
end
1724

1825
@testset "error messages" begin

0 commit comments

Comments
 (0)