Skip to content

Commit

Permalink
reduce specialization cost (?)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Jan 19, 2021
1 parent 3b2407a commit 6eb51e3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,13 @@ end
__cat(A, shape, catdims, X...) = __cat_offset!(A, shape, catdims, ntuple(zero, length(shape)), X...)

function __cat_offset!(A, shape, catdims, offsets, x, X...)
# splitting the "work" on x from X... may reduce latency (fewer costly specializations)
newoffsets = __cat_offset1!(A, shape, catdims, offsets, x)
return __cat_offset!(A, shape, catdims, newoffsets, X...)
end
__cat_offset!(A, shape, catdims, offsets) = return A

function __cat_offset1!(A, shape, catdims, offsets, x)
inds = ntuple(length(offsets)) do i
(i <= length(catdims) && catdims[i]) ? offsets[i] .+ cat_indices(x, i) : 1:shape[i]
end
Expand All @@ -1654,9 +1661,8 @@ function __cat_offset!(A, shape, catdims, offsets, x, X...)
newoffsets = ntuple(length(offsets)) do i
(i <= length(catdims) && catdims[i]) ? offsets[i] + cat_size(x, i) : offsets[i]
end
return __cat_offset!(A, shape, catdims, newoffsets, X...)
return newoffsets
end
__cat_offset!(A, shape, catdims, offsets) = return A

"""
vcat(A...)
Expand Down

0 comments on commit 6eb51e3

Please sign in to comment.