Commit 6440292
authored
Fast bounds-check for CartesianIndex ranges (#55596)
`StepRangeLen{<:CartesianIndex}` indices have been supported since
v1.11, but bounds-checking for such indices currently falls back to
iterating over the entire range. This PR adds a quick `checkindex` for
such ranges.
The performance improvement as a consequence:
```julia
julia> D = Diagonal(1:10_000);
julia> @Btime checkbounds($D, diagind($D, IndexCartesian()));
6.697 μs (0 allocations: 0 bytes) # nightly, O(n)
4.044 ns (0 allocations: 0 bytes) # This PR, O(1)
```1 parent d882d62 commit 6440292
File tree
2 files changed
+7
-0
lines changed- base
- stdlib/LinearAlgebra/test
2 files changed
+7
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
730 | 730 | | |
731 | 731 | | |
732 | 732 | | |
| 733 | + | |
| 734 | + | |
733 | 735 | | |
734 | 736 | | |
735 | 737 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1354 | 1354 | | |
1355 | 1355 | | |
1356 | 1356 | | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
1357 | 1362 | | |
0 commit comments