Skip to content

Commit 4cf9005

Browse files
committed
Integral support for AbstractFFTs
1 parent 23a4b1a commit 4cf9005

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/plan.jl

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@ import LinearAlgebra: mul!
33

44
struct FFTAInvPlan{T} <: Plan{T} end
55

6-
@computed struct FFTAPlan{T<:Union{Real, Complex},N} <: Plan{T}
7-
callgraph::NTuple{N, CallGraph{(T<:Real) ? Complex{T} : T}}
8-
region
6+
struct FFTAPlan{T,N} <: Plan{T}
7+
callgraph::NTuple{N, CallGraph{T}}
8+
region::Union{Int,AbstractVector{<:Int}}
99
dir::Direction
1010
pinv::FFTAInvPlan{T}
1111
end
1212

13-
function AbstractFFTs.plan_fft(x::AbstractArray{T}, region; kwargs...)::FFTAPlan{T} where T
13+
function AbstractFFTs.plan_fft(x::AbstractArray{T}, region; kwargs...)::FFTAPlan{T} where {T <: Complex}
1414
N = length(region)
1515
@assert N <= 2 "Only supports vectors and matrices"
1616
if N == 1
1717
g = CallGraph{T}(size(x,region[]))
1818
pinv = FFTAInvPlan{T}()
1919
return FFTAPlan{T,N}((g,), region, FFT_FORWARD, pinv)
2020
else
21+
sort!(region)
2122
g1 = CallGraph{T}(size(x,region[1]))
2223
g2 = CallGraph{T}(size(x,region[2]))
2324
pinv = FFTAInvPlan{T}()
@@ -43,8 +44,35 @@ function LinearAlgebra.mul!(y::AbstractArray{T,N}, p::FFTAPlan{T,1}, x::Abstract
4344
end
4445
end
4546

47+
function LinearAlgebra.mul!(y::AbstractArray{T,N}, p::FFTAPlan{T,2}, x::AbstractArray{T,N}) where {T,N}
48+
R1 = CartesianIndices(size(x)[1:p.region[1]-1])
49+
R2 = CartesianIndices(size(x)[p.region[1]+1:p.region[2]-1])
50+
R3 = CartesianIndices(size(x)[p.region[2]+1:end])
51+
y_tmp = similar(y, axes(y)[p.region])
52+
for I1 in R1
53+
for I2 in R2
54+
for I3 in R3
55+
rows,cols = size(x)[p.region]
56+
for k in 1:cols
57+
@views fft!(y_tmp[:,k], x[I1,:,I2,k,I3], 1, 1, p.dir, p.callgraph[2][1].type, p.callgraph[2], 1)
58+
end
59+
60+
for k in 1:rows
61+
@views fft!(y[I1,k,I2,:,I3], y_tmp[k,:], 1, 1, p.dir, p.callgraph[1][1].type, p.callgraph[1], 1)
62+
end
63+
end
64+
end
65+
end
66+
end
67+
4668
function *(p::FFTAPlan{T,1}, x::AbstractVector{T}) where {T<:Union{Real, Complex}}
4769
y = similar(x)
4870
LinearAlgebra.mul!(y, p, x)
4971
y
72+
end
73+
74+
function *(p::FFTAPlan{T,N1}, x::AbstractArray{T,N2}) where {T<:Union{Real, Complex}, N1, N2}
75+
y = similar(x)
76+
LinearAlgebra.mul!(y, p, x)
77+
y
5078
end

0 commit comments

Comments
 (0)