Skip to content

Commit 2a84a1f

Browse files
committed
faster cat performance (#432)
The generic `cat` does more shape analysis, that typed_cat does not always do (before either may then dispatch to _cat_t), so we can make this faster by calling it instead. Secondly, we can make `issparse` non-recursive once it hits a base case where all trailing elements are the same. This makes it much better at handling large splat, since we do not need to check each recursively smaller type down to the base case using generic code, and just generate one const method specialized on the full length instead. Fix JuliaLang/julia#51011 (cherry picked from commit 4e6776a)
1 parent 4a6d98c commit 2a84a1f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/sparsevector.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,7 @@ _makesparse(x::AbstractMatrix) = convert(SparseMatrixCSC, issparse(x) ? x : spar
11971197
anysparse() = false
11981198
anysparse(X) = X isa AbstractArray && issparse(X)
11991199
anysparse(X, Xs...) = anysparse(X) || anysparse(Xs...)
1200+
anysparse(X::T, Xs::T...) where {T} = anysparse(X)
12001201

12011202
const _SparseVecConcatGroup = Union{Vector, AbstractSparseVector}
12021203
function hcat(X::_SparseVecConcatGroup...)
@@ -1229,13 +1230,13 @@ function hcat(X1::_SparseConcatGroup, X::_SparseConcatGroup...)
12291230
if anysparse(X1) || anysparse(X...)
12301231
X1, X = _sparse(X1), map(_makesparse, X)
12311232
end
1232-
return cat(X1, X..., dims=Val(2))
1233+
return Base.typed_hcat(Base.promote_eltype(X1, X...), X1, X...)
12331234
end
12341235
function vcat(X1::_SparseConcatGroup, X::_SparseConcatGroup...)
12351236
if anysparse(X1) || anysparse(X...)
12361237
X1, X = _sparse(X1), map(_makesparse, X)
12371238
end
1238-
return cat(X1, X..., dims=Val(1))
1239+
return Base.typed_vcat(Base.promote_eltype(X1, X...), X1, X...)
12391240
end
12401241
function hvcat(rows::Tuple{Vararg{Int}}, X1::_SparseConcatGroup, X::_SparseConcatGroup...)
12411242
if anysparse(X1) || anysparse(X...)

0 commit comments

Comments
 (0)