Skip to content

Commit 1e3df24

Browse files
authored
Ensure all fft-like functions fallback to version with region when region not provided (#84)
* Ensure all fft-like functions fallback to version with region when region not provided * Add testset for default dims * Add tests for complex float promotion * Test complex float promotion for fft,ifft,bfft too
1 parent b2dd69c commit 1e3df24

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/definitions.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ _to1(::Tuple, x) = copy1(eltype(x), x)
5959
for f in (:fft, :bfft, :ifft, :fft!, :bfft!, :ifft!, :rfft)
6060
pf = Symbol("plan_", f)
6161
@eval begin
62-
$f(x::AbstractArray) = (y = to1(x); $pf(y) * y)
62+
$f(x::AbstractArray) = $f(x, 1:ndims(x))
6363
$f(x::AbstractArray, region) = (y = to1(x); $pf(y, region) * y)
6464
$pf(x::AbstractArray; kws...) = (y = to1(x); $pf(y, 1:ndims(y); kws...))
6565
end
@@ -207,9 +207,9 @@ bfft!
207207
for f in (:fft, :bfft, :ifft)
208208
pf = Symbol("plan_", f)
209209
@eval begin
210-
$f(x::AbstractArray{<:Real}, region=1:ndims(x)) = $f(complexfloat(x), region)
210+
$f(x::AbstractArray{<:Real}, region) = $f(complexfloat(x), region)
211211
$pf(x::AbstractArray{<:Real}, region; kws...) = $pf(complexfloat(x), region; kws...)
212-
$f(x::AbstractArray{<:Complex{<:Union{Integer,Rational}}}, region=1:ndims(x)) = $f(complexfloat(x), region)
212+
$f(x::AbstractArray{<:Complex{<:Union{Integer,Rational}}}, region) = $f(complexfloat(x), region)
213213
$pf(x::AbstractArray{<:Complex{<:Union{Integer,Rational}}}, region; kws...) = $pf(complexfloat(x), region; kws...)
214214
end
215215
end
@@ -297,16 +297,16 @@ LinearAlgebra.mul!(y::AbstractArray, p::ScaledPlan, x::AbstractArray) =
297297
for f in (:brfft, :irfft)
298298
pf = Symbol("plan_", f)
299299
@eval begin
300-
$f(x::AbstractArray, d::Integer) = $pf(x, d) * x
300+
$f(x::AbstractArray, d::Integer) = $f(x, d, 1:ndims(x))
301301
$f(x::AbstractArray, d::Integer, region) = $pf(x, d, region) * x
302302
$pf(x::AbstractArray, d::Integer;kws...) = $pf(x, d, 1:ndims(x);kws...)
303303
end
304304
end
305305

306306
for f in (:brfft, :irfft)
307307
@eval begin
308-
$f(x::AbstractArray{<:Real}, d::Integer, region=1:ndims(x)) = $f(complexfloat(x), d, region)
309-
$f(x::AbstractArray{<:Complex{<:Union{Integer,Rational}}}, d::Integer, region=1:ndims(x)) = $f(complexfloat(x), d, region)
308+
$f(x::AbstractArray{<:Real}, d::Integer, region) = $f(complexfloat(x), d, region)
309+
$f(x::AbstractArray{<:Complex{<:Union{Integer,Rational}}}, d::Integer, region) = $f(complexfloat(x), d, region)
310310
end
311311
end
312312

test/runtests.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,33 @@ end
213213
@test @inferred(f9(plan_fft(zeros(10), 1), 10)) == 1/10
214214
end
215215

216+
# Test that dims defaults to 1:ndims for fft-like functions
217+
@testset "Default dims" begin
218+
for x in (randn(3), randn(3, 4), randn(3, 4, 5))
219+
N = ndims(x)
220+
complex_x = complex.(x)
221+
@test fft(x) fft(x, 1:N)
222+
@test ifft(x) ifft(x, 1:N)
223+
@test bfft(x) bfft(x, 1:N)
224+
@test rfft(x) rfft(x, 1:N)
225+
d = 2 * size(x, 1) - 1
226+
@test irfft(x, d) irfft(x, d, 1:N)
227+
@test brfft(x, d) brfft(x, d, 1:N)
228+
end
229+
end
230+
231+
@testset "Complex float promotion" begin
232+
for x in (rand(-5:5, 3), rand(-5:5, 3, 4), rand(-5:5, 3, 4, 5))
233+
N = ndims(x)
234+
@test fft(x) fft(complex.(x)) fft(complex.(float.(x)))
235+
@test ifft(x) ifft(complex.(x)) ifft(complex.(float.(x)))
236+
@test bfft(x) bfft(complex.(x)) bfft(complex.(float.(x)))
237+
d = 2 * size(x, 1) - 1
238+
@test irfft(x, d) irfft(complex.(x), d) irfft(complex.(float.(x)), d)
239+
@test brfft(x, d) brfft(complex.(x), d) brfft(complex.(float.(x)), d)
240+
end
241+
end
242+
216243
@testset "ChainRules" begin
217244
@testset "shift functions" begin
218245
for x in (randn(3), randn(3, 4), randn(3, 4, 5))

0 commit comments

Comments
 (0)