Skip to content

Commit

Permalink
Merge pull request #9 from martinholters/fix_normalization_inference
Browse files Browse the repository at this point in the history
Add a typeassert in `normalization`
  • Loading branch information
stevengj authored Jan 17, 2018
2 parents 486ce50 + cc853d9 commit c1eb41d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,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...]]))
normalization(T, sz, region) = 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
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ end
@test AbstractFFTs.ifftshift([1 2 3; 4 5 6], (1,2)) == [5 6 4; 2 3 1]
@test AbstractFFTs.ifftshift([1 2 3; 4 5 6], 1:2) == [5 6 4; 2 3 1]
end

@testset "normalization" begin
# normalization should be inferable even if region is only inferred as ::Any,
# need to wrap in another function to test this (note that p.region::Any for
# p::TestPlan)
f9(p::Plan{T}, sz) where {T} = AbstractFFTs.normalization(real(T), sz, p.region)
@test @inferred(f9(plan_fft(zeros(10), 1), 10)) == 1/10
end

0 comments on commit c1eb41d

Please sign in to comment.