Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass init to prod in normalization #81

Merged
merged 10 commits into from
Feb 6, 2024

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented Nov 4, 2022

Normalization is defined as 1/prod(dimensions), which should be well-defined for an empty dimensions (in which case the prod evaluates to 1). This PR gets around the following error:

julia> AbstractFFTs.normalization(zeros(), 1:0)
ERROR: MethodError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer

and the following runtime dispatch that arises from the error:

julia> using JET

julia> @report_opt AbstractFFTs.normalization(rand(4), 1:1)
═════ 1 possible error found ═════
┌ @ /home/jishnu/Dropbox/JuliaPackages/AbstractFFTs.jl/src/definitions.jl:275 AbstractFFTs.normalization(AbstractFFTs.real(AbstractFFTs.eltype(X)), AbstractFFTs.size(X), region)
│┌ @ /home/jishnu/Dropbox/JuliaPackages/AbstractFFTs.jl/src/definitions.jl:274 AbstractFFTs.prod(Base.Generator(#91, region))
││┌ @ reduce.jl:613 Base.:(var"#prod#270")(pairs(NamedTuple()), #self#, a)
│││┌ @ reduce.jl:613 mapreduce(identity, Base.mul_prod, a)
││││┌ @ reduce.jl:302 Base.:(var"#mapreduce#263")(pairs(NamedTuple()), #self#, f, op, itr)
│││││┌ @ reduce.jl:302 mapfoldl(f, op, itr)
││││││┌ @ reduce.jl:170 Base.:(var"#mapfoldl#259")(Base._InitialValue(), #self#, f, op, itr)
│││││││┌ @ reduce.jl:170 Base.mapfoldl_impl(f, op, init, itr)
││││││││┌ @ reduce.jl:44 Base.foldl_impl(op′, nt, itr′)
│││││││││┌ @ reduce.jl:49 Base.reduce_empty_iter(op, itr)
││││││││││┌ @ reduce.jl:378 Base.reduce_empty_iter(op, itr, Base.IteratorEltype(itr))
│││││││││││┌ @ reduce.jl:379 Base.reduce_empty(op, eltype(itr))
││││││││││││┌ @ reduce.jl:356 Base.mapreduce_empty(%1, [quote], T)
│││││││││││││ runtime dispatch detected: Base.mapreduce_empty(%1::AbstractFFTs.var"#91#92"{Tuple{Int64}}, [quote]::Base.BottomRF{typeof(Base.mul_prod)}, T::Type{Int64})::Union{}
││││││││││││└─────────────────

After this PR,

julia> AbstractFFTs.normalization(zeros(), 1:0)
1.0

julia> @report_opt AbstractFFTs.normalization(rand(4), 1:1)
No errors detected

@codecov
Copy link

codecov bot commented Nov 4, 2022

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (0918c3c) 84.13% compared to head (42d157b) 94.84%.
Report is 32 commits behind head on master.

Files Patch % Lines
src/definitions.jl 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master      #81       +/-   ##
===========================================
+ Coverage   84.13%   94.84%   +10.70%     
===========================================
  Files           2        5        +3     
  Lines         208      446      +238     
===========================================
+ Hits          175      423      +248     
+ Misses         33       23       -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/definitions.jl Outdated Show resolved Hide resolved
src/definitions.jl Outdated Show resolved Hide resolved
src/definitions.jl Outdated Show resolved Hide resolved
@jishnub
Copy link
Contributor Author

jishnub commented Mar 29, 2023

Gentle bump, is there anything else that needs to be done here?

@jishnub
Copy link
Contributor Author

jishnub commented May 5, 2023

Gentle bump

@ararslan ararslan requested a review from stevengj May 5, 2023 23:18
src/definitions.jl Outdated Show resolved Hide resolved
src/definitions.jl Outdated Show resolved Hide resolved
@stevengj stevengj merged commit 2ae97a7 into JuliaMath:master Feb 6, 2024
14 of 15 checks passed
@jishnub jishnub deleted the normalizationinit branch February 6, 2024 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants