Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1078,10 +1078,11 @@ const _SparseConcatGroup = Union{_DenseConcatGroup, _SparseConcatArrays, _Annota
_makesparse(x::Number) = x
_makesparse(x::AbstractArray) = SparseMatrixCSC(issparse(x) ? x : sparse(x))

function Base._cat(dims, Xin::_SparseConcatGroup...)
# `@constprop :aggressive` allows `dims` to be propagated as constant improving return type inference
Base.@constprop :aggressive function Base._cat(dims, Xin::_SparseConcatGroup...)
X = map(_makesparse, Xin)
T = promote_eltype(Xin...)
Base.cat_t(T, X...; dims=dims)
return Base._cat_t(dims, T, X...)
end
function hcat(Xin::_SparseConcatGroup...)
X = map(_makesparse, Xin)
Expand Down
10 changes: 10 additions & 0 deletions test/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,11 @@ end
@test issparse(hvcat((2,), othervecormat, spvec))
@test issparse(cat(spvec, othervecormat; dims=(1,2)))
@test issparse(cat(othervecormat, spvec; dims=(1,2)))

# inferrability (https://github.com/JuliaSparse/SparseArrays.jl/pull/92)
cat_with_constdims(args...) = cat(args...; dims=(1,2))
@test issparse(@inferred cat_with_constdims(spvec, othervecormat))
@test issparse(@inferred cat_with_constdims(othervecormat, spvec))
end
# The preceding tests should cover multi-way combinations of those types, but for good
# measure test a few multi-way combinations involving those types
Expand All @@ -572,6 +577,11 @@ end
@test issparse(hvcat((5,), spvec, densemat, diagmat, densevec, spmat))
@test issparse(cat(densemat, diagmat, spmat, densevec, spvec; dims=(1,2)))
@test issparse(cat(spvec, diagmat, densevec, spmat, densemat; dims=(1,2)))

# inferrability (https://github.com/JuliaSparse/SparseArrays.jl/pull/92)
cat_with_constdims(args...) = cat(args...; dims=(1,2))
@test issparse(@inferred cat_with_constdims(densemat, diagmat, spmat, densevec, spvec))
@test issparse(@inferred cat_with_constdims(spvec, diagmat, densevec, spmat, densemat))
end
@testset "vertical concatenation of SparseVectors with different el- and ind-type (#22225)" begin
spv6464 = SparseVector(0, Int64[], Int64[])
Expand Down