|
4 | 4 | module IteratorsMD
|
5 | 5 | import .Base: eltype, length, size, first, last, in, getindex,
|
6 | 6 | setindex!, IndexStyle, min, max, zero, oneunit, isless, eachindex,
|
7 |
| - ndims, IteratorSize, convert, show, iterate, promote_rule |
| 7 | + ndims, IteratorSize, convert, show, iterate, promote_rule, to_indices |
8 | 8 |
|
9 | 9 | import .Base: +, -, *, (:)
|
10 | 10 | import .Base: simd_outer_range, simd_inner_length, simd_index
|
@@ -381,6 +381,10 @@ module IteratorsMD
|
381 | 381 | first(iter::CartesianIndices) = CartesianIndex(map(first, iter.indices))
|
382 | 382 | last(iter::CartesianIndices) = CartesianIndex(map(last, iter.indices))
|
383 | 383 |
|
| 384 | + # When used as indices themselves, CartesianIndices can simply become its tuple of ranges |
| 385 | + @inline to_indices(A, inds, I::Tuple{CartesianIndices, Vararg{Any}}) = |
| 386 | + to_indices(A, inds, (I[1].indices..., tail(I)...)) |
| 387 | + |
384 | 388 | @inline function in(i::CartesianIndex{N}, r::CartesianIndices{N}) where {N}
|
385 | 389 | _in(true, i.I, first(r).I, last(r).I)
|
386 | 390 | end
|
@@ -573,6 +577,7 @@ function checkindex(::Type{Bool}, inds::Tuple, I::AbstractArray{<:CartesianIndex
|
573 | 577 | end
|
574 | 578 | b
|
575 | 579 | end
|
| 580 | +checkindex(::Type{Bool}, inds::Tuple, I::CartesianIndices) = all(checkindex.(Bool, inds, I.indices)) |
576 | 581 |
|
577 | 582 | # combined count of all indices, including CartesianIndex and
|
578 | 583 | # AbstractArray{CartesianIndex}
|
|
0 commit comments