Skip to content

Commit

Permalink
remove annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
CarloLucibello committed Mar 1, 2021
1 parent b95851d commit 28b7b83
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions src/gather.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 28b7b83

Please sign in to comment.