Skip to content

Commit d35236c

Browse files
authored
Improve inferrability (#48)
This is technically a breaking change because it returns the sizes as tuples rather than vectors. Hence I've taken the liberty of bumping the version number. The consensus is we can go to 1.0.0.
1 parent ad5e39f commit d35236c

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "AbstractFFTs"
22
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
3-
version = "0.5.0"
3+
version = "1.0.0"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/definitions.jl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ summary(p::ScaledPlan) = string(p.scale, " * ", summary(p.p))
256256
*(p::Plan, I::UniformScaling) = ScaledPlan(p, I.λ)
257257

258258
# Normalization for ifft, given unscaled bfft, is 1/prod(dimensions)
259-
normalization(T, sz, region) = one(T) / Int(prod([sz...][[region...]]))::Int
259+
normalization(::Type{T}, sz, region) where T = one(T) / Int(prod([sz...][[region...]]))::Int
260260
normalization(X, region) = normalization(real(eltype(X)), size(X), region)
261261

262262
plan_ifft(x::AbstractArray, region; kws...) =
@@ -316,19 +316,17 @@ transformed dimensions (of the real output array) in order to obtain the inverse
316316
"""
317317
brfft
318318

319-
function rfft_output_size(x::AbstractArray, region)
319+
rfft_output_size(x::AbstractArray, region) = rfft_output_size(size(x), region)
320+
function rfft_output_size(sz::Dims{N}, region) where {N}
320321
d1 = first(region)
321-
osize = [size(x)...]
322-
osize[d1] = osize[d1]>>1 + 1
323-
return osize
322+
return ntuple(d -> d == d1 ? sz[d]>>1 + 1 : sz[d], Val(N))
324323
end
325324

326-
function brfft_output_size(x::AbstractArray, d::Integer, region)
325+
brfft_output_size(x::AbstractArray, d::Integer, region) = brfft_output_size(size(x), d, region)
326+
function brfft_output_size(sz::Dims{N}, d::Integer, region) where {N}
327327
d1 = first(region)
328-
osize = [size(x)...]
329-
@assert osize[d1] == d>>1 + 1
330-
osize[d1] = d
331-
return osize
328+
@assert sz[d1] == d>>1 + 1
329+
return ntuple(i -> i == d1 ? d : sz[i], Val(N))
332330
end
333331

334332
plan_irfft(x::AbstractArray{Complex{T}}, d::Integer, region; kws...) where {T} =
@@ -432,7 +430,7 @@ Return the discrete Fourier transform (DFT) sample frequencies for a DFT of leng
432430
bin centers at every sample point. `fs` is the sampling rate of the
433431
input signal, which is the reciprocal of the sample spacing.
434432
435-
Given a window of length `n` and a sampling rate `fs`, the frequencies returned are
433+
Given a window of length `n` and a sampling rate `fs`, the frequencies returned are
436434
437435
```julia
438436
[0:n÷2-1; -n÷2:-1] * fs/n # if n is even
@@ -467,7 +465,7 @@ The returned `Frequencies` object is an `AbstractVector`
467465
containing the frequency bin centers at every sample point. `fs`
468466
is the sampling rate of the input signal, which is the reciprocal of the sample spacing.
469467
470-
Given a window of length `n` and a sampling rate `fs`, the frequencies returned are
468+
Given a window of length `n` and a sampling rate `fs`, the frequencies returned are
471469
472470
```julia
473471
[0:n÷2;] * fs/n # if n is even

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ using AbstractFFTs: Plan
55
using LinearAlgebra
66
using Test
77

8+
@testset "rfft sizes" begin
9+
A = rand(11, 10)
10+
@test @inferred(AbstractFFTs.rfft_output_size(A, 1)) == (6, 10)
11+
@test @inferred(AbstractFFTs.rfft_output_size(A, 2)) == (11, 6)
12+
A1 = rand(6, 10); A2 = rand(11, 6)
13+
@test @inferred(AbstractFFTs.brfft_output_size(A1, 11, 1)) == (11, 10)
14+
@test @inferred(AbstractFFTs.brfft_output_size(A2, 10, 2)) == (11, 10)
15+
@test_throws AssertionError AbstractFFTs.brfft_output_size(A1, 10, 2)
16+
end
17+
818
mutable struct TestPlan{T} <: Plan{T}
919
region
1020
pinv::Plan{T}

0 commit comments

Comments
 (0)