Skip to content

Commit 287f56d

Browse files
mbaumanandreasnoack
authored andcommitted
Fixup checkbounds_indices to the new APIs
Also clarify the comment since I was confused upon coming back to this method a few weeks later
1 parent c5c5352 commit 287f56d

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/DistributedArrays.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -707,24 +707,24 @@ if VERSION > v"0.5.0-dev+5230"
707707
end
708708
Base.size(M::MergedIndices) = M.sz
709709
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.
714718
typealias ReshapedMergedIndices{T,N,M<:MergedIndices} Base.ReshapedArray{T,N,M}
715719
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}
724721
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)...))
728728

729729
# The tricky thing here is that we want to optimize the accesses into the
730730
# distributed array, but in doing so, we lose track of which indices in I we

0 commit comments

Comments
 (0)