Skip to content

Specialize iterate for AbstractOneTo #58677

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Jun 9, 2025

Alternate approach to #58635, which produces a similar performance improvement. This is more general, as the improvement would apply to arbitrary iterators that use AbstractOneTo axes, and not just to AbstractArrays. The idea is that iterate(r::OneTo, i::Integer) now returns nothing if i > last(r), instead of returning an out-of-bound value. This ensures that iterating over a OneTo always produces valid indices.

julia> using LinearAlgebra

julia> A = rand(1000,1000); v = view(A, :);

julia> @btime norm(Iterators.map(splat(-), zip($v, $v)));
  2.239 ms (0 allocations: 0 bytes) # master
  500.028 μs (0 allocations: 0 bytes) # this PR

@jishnub jishnub marked this pull request as draft June 9, 2025 14:31
@nsajko nsajko added the ranges Everything AbstractRange label Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ranges Everything AbstractRange
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants