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

Specialize common reductions for ranges with init specified #56896

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented Dec 23, 2024

The idea is that since ranges have O(1) reductions such as minimum, maximum and sum defined, we may reuse the implementations in the corresponding reductions with init specified, instead of hitting slow fallback implementations.

for example, after this,

julia> @btime maximum($(Ref(1:10000))[], init=typemin(Int))
  2.344 ns (0 allocations: 0 bytes)
10000

whereas, on master, this is O(N) as it loops over each element.

The specific use case is to avoid hitting slow fallbacks in a change like https://github.com/JuliaLinearAlgebra/BlockBandedMatrices.jl/pull/218/files.

@nsajko nsajko added performance Must go faster fold sum, maximum, reduce, foldl, etc. labels Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fold sum, maximum, reduce, foldl, etc. performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants