@@ -358,16 +358,14 @@ module IteratorsMD
358
358
CartesianIndex ()
359
359
end
360
360
@inline function Base. getindex (iter:: CartesianIndices{N,R} , I:: Vararg{Int, N} ) where {N,R}
361
- # Eagerly do boundscheck before calculating each item of the CartesianIndex,
362
- # this generates inlined codes for `_get_cartesianindex` and furthermore enables SIMD
361
+ # Eagerly do boundscheck before calculating each item of the CartesianIndex so that
362
+ # we can pass `@inbounds` hint to inside the map and generates more efficient SIMD codes
363
363
@boundscheck checkbounds (iter, I... )
364
- @inbounds CartesianIndex (_get_cartesianindex (iter. indices, I))
365
- end
366
- @propagate_inbounds _get_cartesianindex (indices, I) = _get_cartesianindex (getindex (first (indices), first (I)), tail (indices), tail (I))
367
- @propagate_inbounds function _get_cartesianindex (out, indices, I)
368
- _get_cartesianindex ((out... , getindex (first (indices), first (I))), tail (indices), tail (I))
364
+ index = map (iter. indices, I) do r, i
365
+ @inbounds getindex (r, i)
366
+ end
367
+ CartesianIndex (index)
369
368
end
370
- @inline _get_cartesianindex (out, :: Tuple{} , :: Tuple{} ) = out
371
369
372
370
# CartesianIndices act as a multidimensional range, so cartesian indexing of CartesianIndices
373
371
# with compatible dimensions may be seen as indexing into the component ranges.
0 commit comments