From 2ae97a7c06b0c7b43a5ee7d1298d882473a575aa Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 6 Feb 2024 22:32:55 +0530 Subject: [PATCH] pass init to prod in normalization (#81) * pass init to prod in normalization * Bounds check for region Co-authored-by: Alex Arslan * 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 --- src/definitions.jl | 5 +++-- test/runtests.jl | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/definitions.jl b/src/definitions.jl index 948c582..f4f1c19 100644 --- a/src/definitions.jl +++ b/src/definitions.jl @@ -274,8 +274,9 @@ summary(p::ScaledPlan) = string(p.scale, " * ", summary(p.p)) *(I::UniformScaling, p::Plan) = ScaledPlan(p, I.λ) *(p::Plan, I::UniformScaling) = ScaledPlan(p, I.λ) -# Normalization for ifft, given unscaled bfft, is 1/prod(dimensions) -normalization(::Type{T}, sz, region) where T = one(T) / Int(prod(sz[r] for r in region))::Int +@inline function normalization(::Type{T}, sz, region) where T + one(T) / mapreduce(r -> Int(sz[r])::Int, *, region; init=1)::Int +end normalization(X, region) = normalization(real(eltype(X)), size(X), region) plan_ifft(x::AbstractArray, region; kws...) = diff --git a/test/runtests.jl b/test/runtests.jl index 2c86b08..e97333b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -123,6 +123,9 @@ end # p::TestPlan) f9(p::AbstractFFTs.Plan{T}, sz) where {T} = AbstractFFTs.normalization(real(T), sz, fftdims(p)) @test @inferred(f9(plan_fft(zeros(10), 1), 10)) == 1/10 + + @test_throws BoundsError AbstractFFTs.normalization(Float64, (2,), 1:3) + @test_throws BoundsError AbstractFFTs.normalization(Float64, (2,), (1,3,)) end # Test that dims defaults to 1:ndims for fft-like functions