@@ -707,24 +707,24 @@ if VERSION > v"0.5.0-dev+5230"
707
707
end
708
708
Base. size (M:: MergedIndices ) = M. sz
709
709
Base. getindex {_,N} (M:: MergedIndices{_,N} , I:: Vararg{Int, N} ) = CartesianIndex (map (getindex, M. indices, I))
710
- # Boundschecking for using MergedIndices as an array index. This is overly
711
- # strict -- even for SubArrays of ReshapedIndices, we require that the entire
712
- # parent array's indices are valid. In this usage, it is just fine... and is a
713
- # huge optimization over exact bounds checking.
710
+ # Additionally, we optimize bounds checking when using MergedIndices as an
711
+ # array index since checking, e.g., A[1:500, 1:500] is *way* faster than
712
+ # checking an array of 500^2 elements of CartesianIndex{2}. This optimization
713
+ # also applies to reshapes of MergedIndices since the outer shape of the
714
+ # container doesn't affect the index elements themselves. We can go even
715
+ # farther and say that even restricted views of MergedIndices must be valid
716
+ # over the entire array. This is overly strict in general, but in this
717
+ # use-case all the merged indices must be valid at some point, so it's ok.
714
718
typealias ReshapedMergedIndices{T,N,M<: MergedIndices } Base. ReshapedArray{T,N,M}
715
719
typealias SubMergedIndices{T,N,M<: Union{MergedIndices, ReshapedMergedIndices} } SubArray{T,N,M}
716
- typealias MergedIndicesOrSub Union{MergedIndices, SubMergedIndices}
717
- import Base: _chkbnds
718
- # Ambiguity with linear indexing:
719
- @inline _chkbnds (A:: AbstractVector , checked:: NTuple{1,Bool} , I:: MergedIndicesOrSub ) = _chkbnds (A, checked, parent (parent (I)). indices... )
720
- @inline _chkbnds (A:: AbstractArray , checked:: NTuple{1,Bool} , I:: MergedIndicesOrSub ) = _chkbnds (A, checked, parent (parent (I)). indices... )
721
- # Generic bounds checking
722
- @inline _chkbnds {T,N} (A:: AbstractArray{T,N} , checked:: NTuple{N,Bool} , I1:: MergedIndicesOrSub , I... ) = _chkbnds (A, checked, parent (parent (I1)). indices... , I... )
723
- @inline _chkbnds {T,N,M} (A:: AbstractArray{T,N} , checked:: NTuple{M,Bool} , I1:: MergedIndicesOrSub , I... ) = _chkbnds (A, checked, parent (parent (I1)). indices... , I... )
720
+ typealias MergedIndicesOrSub Union{MergedIndices, ReshapedMergedIndices, SubMergedIndices}
724
721
import Base: checkbounds_indices
725
- @inline checkbounds_indices (:: Tuple{} , I:: Tuple{MergedIndicesOrSub,Vararg{Any}} ) = checkbounds_indices ((), (parent (parent (I[1 ])). indices... , tail (I)... ))
726
- @inline checkbounds_indices (inds:: Tuple{Any} , I:: Tuple{MergedIndicesOrSub,Vararg{Any}} ) = checkbounds_indices (inds, (parent (parent (I[1 ])). indices... , tail (I)... ))
727
- @inline checkbounds_indices (inds:: Tuple , I:: Tuple{MergedIndicesOrSub,Vararg{Any}} ) = checkbounds_indices (inds, (parent (parent (I[1 ])). indices... , tail (I)... ))
722
+ @inline checkbounds_indices (:: Type{Bool} , inds:: Tuple{} , I:: Tuple{MergedIndicesOrSub,Vararg{Any}} ) =
723
+ checkbounds_indices (Bool, inds, (parent (parent (I[1 ])). indices... , tail (I)... ))
724
+ @inline checkbounds_indices (:: Type{Bool} , inds:: Tuple{Any} , I:: Tuple{MergedIndicesOrSub,Vararg{Any}} ) =
725
+ checkbounds_indices (Bool, inds, (parent (parent (I[1 ])). indices... , tail (I)... ))
726
+ @inline checkbounds_indices (:: Type{Bool} , inds:: Tuple , I:: Tuple{MergedIndicesOrSub,Vararg{Any}} ) =
727
+ checkbounds_indices (Bool, inds, (parent (parent (I[1 ])). indices... , tail (I)... ))
728
728
729
729
# The tricky thing here is that we want to optimize the accesses into the
730
730
# distributed array, but in doing so, we lose track of which indices in I we
0 commit comments