diff --git a/src/gather.jl b/src/gather.jl index 434e7fd55..e72d7905a 100644 --- a/src/gather.jl +++ b/src/gather.jl @@ -30,16 +30,16 @@ can end up being copied into zero, one, or multiple `dst` columns. function gather!(dst::AbstractArray{Tdst,Ndst}, src::AbstractArray{Tsrc,Nsrc}, idx::AbstractArray{NTuple{M,Int}, Nidx}) where {Tdst,Tsrc,Ndst,Nsrc,Nidx,M} + # TODO: use M = typelength(eltype(idx)) to merge the integer method into this? - @boundscheck _gather_checkbounds(src, idx) Ndst - Nidx == Nsrc - M || throw(ArgumentError("")) size(dst)[1:Ndst-Nidx] == size(src)[1:Ndst-Nidx] || throw(ArgumentError("")) size(dst)[Ndst-Nidx+1:end] == size(idx) || throw(ArgumentError("")) coldst = ntuple(i -> Colon(), Ndst - Nidx) colsrc = ntuple(i -> Colon(), Nsrc - M) - @simd for k in CartesianIndices(idx) - @inbounds view(dst, coldst..., Tuple(k)...) .= view(src, colsrc..., idx[k]...) + for k in CartesianIndices(idx) + view(dst, coldst..., Tuple(k)...) .= view(src, colsrc..., idx[k]...) end return dst end @@ -48,32 +48,17 @@ function gather!(dst::AbstractArray{Tdst,Ndst}, src::AbstractArray{Tsrc,Nsrc}, idx::AbstractArray{<:Integer, Nidx}) where {Tdst,Tsrc,Ndst,Nsrc,Nidx} - @boundscheck _gather_checkbounds(src, idx) Ndst - Nidx == Nsrc - 1 || throw(ArgumentError("")) size(dst)[1:Ndst-Nidx] == size(src)[1:Ndst-Nidx] || throw(ArgumentError("")) size(dst)[Ndst-Nidx+1:end] == size(idx) || throw(ArgumentError("")) coldst = ntuple(i -> Colon(), Ndst - Nidx) colsrc = ntuple(i -> Colon(), Nsrc - 1) - @simd for k in CartesianIndices(idx) - @inbounds view(dst, coldst..., k) .= view(src, colsrc..., idx[k]) + for k in CartesianIndices(idx) + view(dst, coldst..., k) .= view(src, colsrc..., idx[k]) end return dst end -function _gather_checkbounds(src, idx::AbstractArray{<:Integer}) - mini, maxi = extrema(idx) - checkbounds(src, axes(src)[1:end-1]..., mini:maxi) -end - -function _gather_checkbounds(src, idx::AbstractArray{<:NTuple{M,Int}}) where M - # TODO: use M = typelength(eltype(idx)) to merge the integer method into this? - minimaxi = ntuple(M) do d - mini = minimum(i -> i[d], idx) - maxi = maximum(i -> i[d], idx) - mini:maxi - end - checkbounds(src, axes(src)[1:end-M]..., minimaxi...) -end """ gather(src, idx)