Skip to content

Commit

Permalink
Make vcat of SparseVectors with different el- and/or ind-type yield S…
Browse files Browse the repository at this point in the history
…parseVector (#22225). (#22301)
  • Loading branch information
Sacha0 authored and ararslan committed Jun 10, 2017
1 parent 6e72de6 commit b1de9e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,11 @@ end
# of _absspvec_vcat below. The <:Integer qualifications are necessary for correct dispatch.
vcat(X::SparseVector{Tv,Ti}...) where {Tv,Ti<:Integer} = _absspvec_vcat(X...)
vcat(X::AbstractSparseVector{Tv,Ti}...) where {Tv,Ti<:Integer} = _absspvec_vcat(X...)
function vcat(X::SparseVector...)
commeltype = promote_type(map(eltype, X)...)
commindtype = promote_type(map(indtype, X)...)
vcat(map(x -> SparseVector{commeltype,commindtype}(x), X)...)
end
function _absspvec_vcat(X::AbstractSparseVector{Tv,Ti}...) where {Tv,Ti}
# check sizes
n = length(X)
Expand Down
7 changes: 6 additions & 1 deletion test/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,12 @@ let N = 4
@test issparse(cat((1,2), densemat, diagmat, spmat, densevec, spvec))
@test issparse(cat((1,2), spvec, diagmat, densevec, spmat, densemat))
end

@testset "vertical concatenation of SparseVectors with different el- and ind-type (#22225)" begin
spv6464 = SparseVector(0, Int64[], Int64[])
@test isa(vcat(spv6464, SparseVector(0, Int64[], Int32[])), SparseVector{Int64,Int64})
@test isa(vcat(spv6464, SparseVector(0, Int32[], Int64[])), SparseVector{Int64,Int64})
@test isa(vcat(spv6464, SparseVector(0, Int32[], Int32[])), SparseVector{Int64,Int64})
end

## sparsemat: combinations with sparse matrix

Expand Down

0 comments on commit b1de9e5

Please sign in to comment.