Skip to content

Commit

Permalink
Improve inferrability (#48)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
timholy authored Dec 24, 2020
1 parent ad5e39f commit d35236c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "AbstractFFTs"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
version = "0.5.0"
version = "1.0.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
22 changes: 10 additions & 12 deletions src/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ summary(p::ScaledPlan) = string(p.scale, " * ", summary(p.p))
*(p::Plan, I::UniformScaling) = ScaledPlan(p, I.λ)

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

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

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

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

plan_irfft(x::AbstractArray{Complex{T}}, d::Integer, region; kws...) where {T} =
Expand Down Expand Up @@ -432,7 +430,7 @@ Return the discrete Fourier transform (DFT) sample frequencies for a DFT of leng
bin centers at every sample point. `fs` is the sampling rate of the
input signal, which is the reciprocal of the sample spacing.
Given a window of length `n` and a sampling rate `fs`, the frequencies returned are
Given a window of length `n` and a sampling rate `fs`, the frequencies returned are
```julia
[0:n÷2-1; -n÷2:-1] * fs/n # if n is even
Expand Down Expand Up @@ -467,7 +465,7 @@ The returned `Frequencies` object is an `AbstractVector`
containing the frequency bin centers at every sample point. `fs`
is the sampling rate of the input signal, which is the reciprocal of the sample spacing.
Given a window of length `n` and a sampling rate `fs`, the frequencies returned are
Given a window of length `n` and a sampling rate `fs`, the frequencies returned are
```julia
[0:n÷2;] * fs/n # if n is even
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ using AbstractFFTs: Plan
using LinearAlgebra
using Test

@testset "rfft sizes" begin
A = rand(11, 10)
@test @inferred(AbstractFFTs.rfft_output_size(A, 1)) == (6, 10)
@test @inferred(AbstractFFTs.rfft_output_size(A, 2)) == (11, 6)
A1 = rand(6, 10); A2 = rand(11, 6)
@test @inferred(AbstractFFTs.brfft_output_size(A1, 11, 1)) == (11, 10)
@test @inferred(AbstractFFTs.brfft_output_size(A2, 10, 2)) == (11, 10)
@test_throws AssertionError AbstractFFTs.brfft_output_size(A1, 10, 2)
end

mutable struct TestPlan{T} <: Plan{T}
region
pinv::Plan{T}
Expand Down

0 comments on commit d35236c

Please sign in to comment.