Skip to content

Commit 4b57f54

Browse files
authored
Support plan_inv for ScaledPlan's (#77)
* Add plan_inv for ScaledPlan's * Add tests of plan_inv behaviour * Get type T more correct for real FFT test plans
1 parent 03ef58b commit 4b57f54

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

src/definitions.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ plan_ifft(x::AbstractArray, region; kws...) =
279279
plan_ifft!(x::AbstractArray, region; kws...) =
280280
ScaledPlan(plan_bfft!(x, region; kws...), normalization(x, region))
281281

282+
plan_inv(p::ScaledPlan) = ScaledPlan(plan_inv(p.p), inv(p.scale))
283+
# Don't cache inverse of scaled plan (only inverse of inner plan)
282284
inv(p::ScaledPlan) = ScaledPlan(inv(p.p), inv(p.scale))
283285

284286
LinearAlgebra.mul!(y::AbstractArray, p::ScaledPlan, x::AbstractArray) =

test/runtests.jl

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ end
5656
dims = ndims(x)
5757
y = AbstractFFTs.fft(x, dims)
5858
@test y fftw_fft
59-
P = plan_fft(x, dims)
60-
@test eltype(P) === ComplexF64
61-
@test P * x fftw_fft
62-
@test P \ (P * x) x
63-
@test fftdims(P) == dims
59+
# test plan_fft and also inv and plan_inv of plan_ifft, which should all give
60+
# functionally identical plans
61+
for P in [plan_fft(x, dims), inv(plan_ifft(x, dims)),
62+
AbstractFFTs.plan_inv(plan_ifft(x, dims))]
63+
@test eltype(P) === ComplexF64
64+
@test P * x fftw_fft
65+
@test P \ (P * x) x
66+
@test fftdims(P) == dims
67+
end
6468

6569
fftw_bfft = complex.(size(x, dims) .* x)
6670
@test AbstractFFTs.bfft(y, dims) fftw_bfft
@@ -71,10 +75,14 @@ end
7175

7276
fftw_ifft = complex.(x)
7377
@test AbstractFFTs.ifft(y, dims) fftw_ifft
74-
P = plan_ifft(x, dims)
75-
@test P * y fftw_ifft
76-
@test P \ (P * y) y
77-
@test fftdims(P) == dims
78+
# test plan_ifft and also inv and plan_inv of plan_fft, which should all give
79+
# functionally identical plans
80+
for P in [plan_ifft(x, dims), inv(plan_fft(x, dims)),
81+
AbstractFFTs.plan_inv(plan_fft(x, dims))]
82+
@test P * y fftw_ifft
83+
@test P \ (P * y) y
84+
@test fftdims(P) == dims
85+
end
7886

7987
# real FFT
8088
fftw_rfft = fftw_fft[
@@ -83,11 +91,15 @@ end
8391
]
8492
ry = AbstractFFTs.rfft(x, dims)
8593
@test ry fftw_rfft
86-
P = plan_rfft(x, dims)
87-
@test eltype(P) === Int
88-
@test P * x fftw_rfft
89-
@test P \ (P * x) x
90-
@test fftdims(P) == dims
94+
# test plan_rfft and also inv and plan_inv of plan_irfft, which should all give
95+
# functionally identical plans
96+
for P in [plan_rfft(x, dims), inv(plan_irfft(ry, size(x, dims), dims)),
97+
AbstractFFTs.plan_inv(plan_irfft(ry, size(x, dims), dims))]
98+
@test eltype(P) <: Real
99+
@test P * x fftw_rfft
100+
@test P \ (P * x) x
101+
@test fftdims(P) == dims
102+
end
91103

92104
fftw_brfft = complex.(size(x, dims) .* x)
93105
@test AbstractFFTs.brfft(ry, size(x, dims), dims) fftw_brfft
@@ -98,10 +110,14 @@ end
98110

99111
fftw_irfft = complex.(x)
100112
@test AbstractFFTs.irfft(ry, size(x, dims), dims) fftw_irfft
101-
P = plan_irfft(ry, size(x, dims), dims)
102-
@test P * ry fftw_irfft
103-
@test P \ (P * ry) ry
104-
@test fftdims(P) == dims
113+
# test plan_rfft and also inv and plan_inv of plan_irfft, which should all give
114+
# functionally identical plans
115+
for P in [plan_irfft(ry, size(x, dims), dims), inv(plan_rfft(x, dims)),
116+
AbstractFFTs.plan_inv(plan_rfft(x, dims))]
117+
@test P * ry fftw_irfft
118+
@test P \ (P * ry) ry
119+
@test fftdims(P) == dims
120+
end
105121
end
106122
end
107123

test/testplans.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ Base.:*(p::InverseTestPlan, x::AbstractArray) = mul!(similar(x, complex(float(el
9292
mutable struct TestRPlan{T,N} <: Plan{T}
9393
region
9494
sz::NTuple{N,Int}
95-
pinv::Plan{T}
95+
pinv::Plan{Complex{T}}
9696
TestRPlan{T}(region, sz::NTuple{N,Int}) where {T,N} = new{T,N}(region, sz)
9797
end
9898

99-
mutable struct InverseTestRPlan{T,N} <: Plan{T}
99+
mutable struct InverseTestRPlan{T,N} <: Plan{Complex{T}}
100100
d::Int
101101
region
102102
sz::NTuple{N,Int}
@@ -107,10 +107,10 @@ mutable struct InverseTestRPlan{T,N} <: Plan{T}
107107
end
108108
end
109109

110-
function AbstractFFTs.plan_rfft(x::AbstractArray{T}, region; kwargs...) where {T}
110+
function AbstractFFTs.plan_rfft(x::AbstractArray{T}, region; kwargs...) where {T<:Real}
111111
return TestRPlan{T}(region, size(x))
112112
end
113-
function AbstractFFTs.plan_brfft(x::AbstractArray{T}, d, region; kwargs...) where {T}
113+
function AbstractFFTs.plan_brfft(x::AbstractArray{Complex{T}}, d, region; kwargs...) where {T}
114114
return InverseTestRPlan{T}(d, region, size(x))
115115
end
116116
function AbstractFFTs.plan_inv(p::TestRPlan{T,N}) where {T,N}

0 commit comments

Comments
 (0)