Skip to content

Commit 2ae97a7

Browse files
jishnubararslan
andauthored
pass init to prod in normalization (#81)
* pass init to prod in normalization * Bounds check for region Co-authored-by: Alex Arslan <[email protected]> * remove test for empty region * add type assertion * Add fallback checkindex method * fixes to boundscheck * Use init=1 in normalization * Remove explicit bounds checking * Use prod instead of mapreduce * revert to using mapreduce --------- Co-authored-by: Alex Arslan <[email protected]>
1 parent 636dbfa commit 2ae97a7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/definitions.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,9 @@ summary(p::ScaledPlan) = string(p.scale, " * ", summary(p.p))
274274
*(I::UniformScaling, p::Plan) = ScaledPlan(p, I.λ)
275275
*(p::Plan, I::UniformScaling) = ScaledPlan(p, I.λ)
276276

277-
# Normalization for ifft, given unscaled bfft, is 1/prod(dimensions)
278-
normalization(::Type{T}, sz, region) where T = one(T) / Int(prod(sz[r] for r in region))::Int
277+
@inline function normalization(::Type{T}, sz, region) where T
278+
one(T) / mapreduce(r -> Int(sz[r])::Int, *, region; init=1)::Int
279+
end
279280
normalization(X, region) = normalization(real(eltype(X)), size(X), region)
280281

281282
plan_ifft(x::AbstractArray, region; kws...) =

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ end
123123
# p::TestPlan)
124124
f9(p::AbstractFFTs.Plan{T}, sz) where {T} = AbstractFFTs.normalization(real(T), sz, fftdims(p))
125125
@test @inferred(f9(plan_fft(zeros(10), 1), 10)) == 1/10
126+
127+
@test_throws BoundsError AbstractFFTs.normalization(Float64, (2,), 1:3)
128+
@test_throws BoundsError AbstractFFTs.normalization(Float64, (2,), (1,3,))
126129
end
127130

128131
# Test that dims defaults to 1:ndims for fft-like functions

0 commit comments

Comments
 (0)