Skip to content

Commit

Permalink
pass init to prod in normalization (#81)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
jishnub and ararslan authored Feb 6, 2024
1 parent 636dbfa commit 2ae97a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...) =
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2ae97a7

Please sign in to comment.