Skip to content

Commit 438dd7a

Browse files
committed
Working RFFT and BRFFT
1 parent bd5f7be commit 438dd7a

File tree

1 file changed

+22
-36
lines changed

1 file changed

+22
-36
lines changed

src/plan.jl

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,33 @@ function AbstractFFTs.plan_bfft(x::AbstractArray{T}, region; kwargs...)::FFTAPla
5252
end
5353
end
5454

55-
function AbstractFFTs.plan_rfft(x::AbstractArray{T}, region; kwargs...)::FFTAPlan_re{T} where {T <: Real}
55+
function AbstractFFTs.plan_rfft(x::AbstractArray{T}, region; kwargs...)::FFTAPlan_re{Complex{T}} where {T <: Real}
5656
N = length(region)
5757
@assert N <= 2 "Only supports vectors and matrices"
5858
if N == 1
5959
g = CallGraph{Complex{T}}(size(x,region[]))
60-
pinv = FFTAInvPlan{T,N}()
61-
return FFTAPlan_re{T,N}((g,), region, FFT_FORWARD, pinv, size(x,region[]))
60+
pinv = FFTAInvPlan{Complex{T},N}()
61+
return FFTAPlan_re{Complex{T},N}(tuple(g), region, FFT_FORWARD, pinv, size(x,region[]))
6262
else
6363
sort!(region)
6464
g1 = CallGraph{Complex{T}}(size(x,region[1]))
6565
g2 = CallGraph{Complex{T}}(size(x,region[2]))
66-
pinv = FFTAInvPlan{T,N}()
67-
return FFTAPlan_re{T,N}((g1,g2), region, FFT_FORWARD, pinv, size(x,region[1]))
66+
pinv = FFTAInvPlan{Complex{T},N}()
67+
return FFTAPlan_re{Complex{T},N}(tuple(g1,g2), region, FFT_FORWARD, pinv, size(x,region[1]))
6868
end
6969
end
7070

7171
function AbstractFFTs.plan_brfft(x::AbstractArray{T}, len, region; kwargs...)::FFTAPlan_re{T} where {T}
7272
N = length(region)
73-
@info "" x
7473
@assert N <= 2 "Only supports vectors and matrices"
7574
if N == 1
76-
g = CallGraph{Complex{T}}(len)
75+
g = CallGraph{T}(len)
7776
pinv = FFTAInvPlan{T,N}()
7877
return FFTAPlan_re{T,N}((g,), region, FFT_BACKWARD, pinv, len)
7978
else
8079
sort!(region)
81-
g1 = CallGraph{Complex{T}}(len)
82-
g2 = CallGraph{Complex{T}}(size(x,region[2]))
80+
g1 = CallGraph{T}(len)
81+
g2 = CallGraph{T}(size(x,region[2]))
8382
pinv = FFTAInvPlan{T,N}()
8483
return FFTAPlan_re{T,N}((g1,g2), region, FFT_BACKWARD, pinv, len)
8584
end
@@ -107,37 +106,15 @@ function LinearAlgebra.mul!(y::AbstractArray{U,N}, p::FFTAPlan{T,1}, x::Abstract
107106
end
108107
end
109108

110-
function LinearAlgebra.mul!(y::AbstractArray{U,N}, p::FFTAPlan_cx{T,2}, x::AbstractArray{T,N}) where {T,U,N}
111-
R1 = CartesianIndices(size(x)[1:p.region[1]-1])
112-
R2 = CartesianIndices(size(x)[p.region[1]+1:p.region[2]-1])
113-
R3 = CartesianIndices(size(x)[p.region[2]+1:end])
114-
y_tmp = similar(y, axes(y)[p.region])
115-
for I1 in R1
116-
for I2 in R2
117-
for I3 in R3
118-
rows,cols = size(x)[p.region]
119-
for k in 1:cols
120-
@views fft!(y_tmp[:,k], x[I1,:,I2,k,I3], 1, 1, p.dir, p.callgraph[2][1].type, p.callgraph[2], 1)
121-
end
122-
123-
for k in 1:rows
124-
@views fft!(y[I1,k,I2,:,I3], y_tmp[k,:], 1, 1, p.dir, p.callgraph[1][1].type, p.callgraph[1], 1)
125-
end
126-
end
127-
end
128-
end
129-
end
130-
131-
132-
function LinearAlgebra.mul!(y::AbstractArray{U,N}, p::FFTAPlan_re{T,2}, x::AbstractArray{T,N}) where {T,U,N}
109+
function LinearAlgebra.mul!(y::AbstractArray{U,N}, p::FFTAPlan{T,2}, x::AbstractArray{T,N}) where {T,U,N}
133110
R1 = CartesianIndices(size(x)[1:p.region[1]-1])
134111
R2 = CartesianIndices(size(x)[p.region[1]+1:p.region[2]-1])
135112
R3 = CartesianIndices(size(x)[p.region[2]+1:end])
136113
y_tmp = similar(y, axes(y)[p.region])
114+
rows,cols = size(x)[p.region]
137115
for I1 in R1
138116
for I2 in R2
139117
for I3 in R3
140-
rows,cols = size(x)[p.region]
141118
for k in 1:cols
142119
@views fft!(y_tmp[:,k], x[I1,:,I2,k,I3], 1, 1, p.dir, p.callgraph[2][1].type, p.callgraph[2], 1)
143120
end
@@ -163,9 +140,18 @@ function *(p::FFTAPlan{T,N1}, x::AbstractArray{T,N2}) where {T<:Union{Real, Comp
163140
end
164141

165142
function *(p::FFTAPlan_re{T,1}, x::AbstractVector{T}) where {T<:Union{Real, Complex}}
166-
y = similar(x, T <: Real ? Complex{T} : T)
167-
LinearAlgebra.mul!(y, p, x)
168-
y[1:end÷2 + 1]
143+
if p.dir == FFT_FORWARD
144+
y = similar(x, T <: Real ? Complex{T} : T)
145+
LinearAlgebra.mul!(y, p, x)
146+
return y[1:end÷2 + 1]
147+
else
148+
x_tmp = similar(x, p.flen)
149+
x_tmp[1:end÷2 + 1] .= x
150+
x_tmp[end÷2 + 2:end] .= iseven(p.flen) ? conj.(x[end-1:-1:2]) : conj.(x[end:-1:2])
151+
y = similar(x_tmp)
152+
LinearAlgebra.mul!(y, p, x_tmp)
153+
return y
154+
end
169155
end
170156

171157
function *(p::FFTAPlan_re{T,N}, x::AbstractArray{T,2}) where {T<:Union{Real, Complex}, N}

0 commit comments

Comments
 (0)