Skip to content

Add fast method for count/sum of view of BitArray #58930

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

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

Conversation

jakobnissen
Copy link
Member

The dispatch to this method is not ideal, because it does not handle multi- dimensional views, nor discontiguous views.
Ideally, we would have an internal API that, given a view, would iterate all contiguous sub-views. Then this new method could be called for all the conti- guous chunks.

Benchmarks

julia> using BenchmarkTools

julia> x = BitArray(rand(Bool, 1000, 1000));

julia> @btime sum(view(x, 43:849212)); # before
  251.198 μs (4 allocations: 128 bytes)

julia> @btime sum(view(x, 43:849212)); # after
  747.024 ns (4 allocations: 128 bytes)

The dispatch to this method is not ideal, because it does not handle multi-
dimensional views, nor discontiguous views.
Ideally, we would have an internal API that, given a view, would iterate all
contiguous sub-views. Then this new method could be called for all the conti-
guous chunks.
@jakobnissen jakobnissen added performance Must go faster arrays [a, r, r, a, y, s] labels Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants