Skip to content

Commit 85289ad

Browse files
mbaumanandreasnoack
authored andcommitted
Propagate inbounds for the lazy array types
As a further optimization, (at)inbounds could be added throughout the algorithm once it has received more widespread testing.
1 parent ef1eb7b commit 85289ad

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/DistributedArrays.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,14 +711,18 @@ if VERSION > v"0.5.0-dev+5230"
711711
sz::NTuple{N,Int}
712712
end
713713
Base.size(P::ProductIndices) = P.sz
714-
Base.getindex{_,N}(P::ProductIndices{_,N}, I::Vararg{Int, N}) = Bool((&)(map(getindex, P.indices, I)...))
714+
# This gets passed to map to avoid breaking propagation of inbounds
715+
Base.@propagate_inbounds propagate_getindex(A, I...) = A[I...]
716+
Base.@propagate_inbounds Base.getindex{_,N}(P::ProductIndices{_,N}, I::Vararg{Int, N}) =
717+
Bool((&)(map(propagate_getindex, P.indices, I)...))
715718

716719
immutable MergedIndices{I,N} <: AbstractArray{CartesianIndex{N}, N}
717720
indices::I
718721
sz::NTuple{N,Int}
719722
end
720723
Base.size(M::MergedIndices) = M.sz
721-
Base.getindex{_,N}(M::MergedIndices{_,N}, I::Vararg{Int, N}) = CartesianIndex(map(getindex, M.indices, I))
724+
Base.@propagate_inbounds Base.getindex{_,N}(M::MergedIndices{_,N}, I::Vararg{Int, N}) =
725+
CartesianIndex(map(propagate_getindex, M.indices, I))
722726
# Additionally, we optimize bounds checking when using MergedIndices as an
723727
# array index since checking, e.g., A[1:500, 1:500] is *way* faster than
724728
# checking an array of 500^2 elements of CartesianIndex{2}. This optimization

0 commit comments

Comments
 (0)