Skip to content

Commit

Permalink
Fix vcat of sparse vectors with numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch committed Sep 8, 2022
1 parent d88be9f commit 9b3700e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,8 @@ const _SparseConcatGroup = Union{_DenseConcatGroup, _SparseConcatArrays, _Annota

# Concatenations involving un/annotated sparse/special matrices/vectors should yield sparse arrays
_makesparse(x::Number) = x
_makesparse(x::AbstractArray) = SparseMatrixCSC(issparse(x) ? x : sparse(x))
_makesparse(x::AbstractVector) = convert(SparseVector, issparse(x) ? x : sparse(x))::SparseVector
_makesparse(x::AbstractMatrix) = convert(SparseMatrixCSC, issparse(x) ? x : sparse(x))::SparseMatrixCSC

# `@constprop :aggressive` allows `dims` to be propagated as constant improving return type inference
Base.@constprop :aggressive function Base._cat(dims, Xin::_SparseConcatGroup...)
Expand Down
4 changes: 4 additions & 0 deletions test/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ end
@test length(V) == m * n
Vr = vec(Hr)
@test Array(V) == Vr
Vnum = vcat(zero(eltype(A)), A...)
@test Vnum isa SparseVector{Float64,Int}
@test length(Vnum) == m*n + 1
@test Array(Vnum) == [0; Vr]
end

@testset "concatenation of sparse vectors with other types" begin
Expand Down

0 comments on commit 9b3700e

Please sign in to comment.