Skip to content

Increment state conditionally in CartesianIndices iteration #58742

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

Merged
merged 1 commit into from
Jun 17, 2025

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Jun 16, 2025

Fixes #53430

julia> a = rand(100,100); b = similar(a); av = view(a, axes(a)...); bv = view(b, axes(b)...); bv2 = view(b, UnitRange.(axes(b))...);

julia> @btime copyto!($bv2, $av); # slow, indices are UnitRanges
  12.352 μs (0 allocations: 0 bytes) # master, v"1.13.0-DEV.745"
  1.662 μs (0 allocations: 0 bytes) # this PR
  
julia> @btime copyto!($bv, $av); # reference
  1.733 μs (0 allocations: 0 bytes)

The performances become comparable after this PR.

I've also renamed the second I to Itail, as the two variables represent different quantities.

@jishnub jishnub added performance Must go faster arrays [a, r, r, a, y, s] backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 backport 1.12 Change should be backported to release-1.12 labels Jun 16, 2025
@jishnub jishnub merged commit 36a4616 into master Jun 17, 2025
13 checks passed
@jishnub jishnub deleted the jishnub/cartinds_iter branch June 17, 2025 09:37
KristofferC pushed a commit that referenced this pull request Jun 25, 2025
Fixes #53430

```julia
julia> a = rand(100,100); b = similar(a); av = view(a, axes(a)...); bv = view(b, axes(b)...); bv2 = view(b, UnitRange.(axes(b))...);

julia> @Btime copyto!($bv2, $av); # slow, indices are UnitRanges
  12.352 μs (0 allocations: 0 bytes) # master, v"1.13.0-DEV.745"
  1.662 μs (0 allocations: 0 bytes) # this PR

julia> @Btime copyto!($bv, $av); # reference
  1.733 μs (0 allocations: 0 bytes)
```
The performances become comparable after this PR.

I've also renamed the second `I` to `Itail`, as the two variables
represent different quantities.

(cherry picked from commit 36a4616)
@KristofferC KristofferC mentioned this pull request Jun 25, 2025
55 tasks
KristofferC pushed a commit that referenced this pull request Jun 25, 2025
Fixes #53430

```julia
julia> a = rand(100,100); b = similar(a); av = view(a, axes(a)...); bv = view(b, axes(b)...); bv2 = view(b, UnitRange.(axes(b))...);

julia> @Btime copyto!($bv2, $av); # slow, indices are UnitRanges
  12.352 μs (0 allocations: 0 bytes) # master, v"1.13.0-DEV.745"
  1.662 μs (0 allocations: 0 bytes) # this PR

julia> @Btime copyto!($bv, $av); # reference
  1.733 μs (0 allocations: 0 bytes)
```
The performances become comparable after this PR.

I've also renamed the second `I` to `Itail`, as the two variables
represent different quantities.

(cherry picked from commit 36a4616)
@KristofferC KristofferC mentioned this pull request Jun 25, 2025
71 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 backport 1.12 Change should be backported to release-1.12 performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

copyto! does not vectorize for views with UnitRange indices
2 participants