Skip to content

Instantly share code, notes, and snippets.

@pkofod
Created June 2, 2016 13:31
Show Gist options
  • Save pkofod/5536ae52c23db5f34ba35cedbf0b74e9 to your computer and use it in GitHub Desktop.
Save pkofod/5536ae52c23db5f34ba35cedbf0b74e9 to your computer and use it in GitHub Desktop.
using Base.Test
Base.hcat(Xin::Union{SparseVector, SparseMatrixCSC}...) = hcat(map(SparseMatrixCSC, Xin)...)
Base.vcat(Xin::Union{SparseVector, SparseMatrixCSC}...) = vcat(map(SparseMatrixCSC, Xin)...)
Base.hcat(Xin::Union{Vector, AbstractSparseVector}...) = hcat(map(sparse, Xin)...)
Base.vcat(Xin::Union{Vector, AbstractSparseVector}...) = vcat(map(sparse, Xin)...)
function Base.hcat(Xin::Union{Matrix, Vector, SparseMatrixCSC}...)
X = SparseMatrixCSC[issparse(x) ? x : sparse(x) for x in Xin]
hcat(X...)
end
function Base.vcat(Xin::Union{Matrix, Vector, SparseMatrixCSC}...)
X = SparseMatrixCSC[issparse(x) ? x : sparse(x) for x in Xin]
vcat(X...)
end
Base.hcat(A::Union{Matrix, Vector}...) = Base.typed_hcat(Base.promote_eltype(A...), A...)
Base.vcat{T}(A::Union{Matrix{T}, Vector{T}}...) = typed_vcat(T, A...)
Base.vcat(A::Union{Matrix, Vector}...) = Base.typed_vcat(Base.promote_eltype(A...), A...)
Base.hcat{T}(A::Union{Matrix{T}, Vector{T}}...) = typed_hcat(T, A...)
# Matrix vector cat not supported for sparse #13130 and #16661
@test issparse([sprand(10,10,.1) sprand(10,.1)])
@test issparse([sprand(10,1,.1); sprand(10,.1)])
@test issparse([sprand(10,10,.1) rand(10)])
@test issparse([sprand(10,1,.1) rand(10)])
@test issparse([sprand(10,2,.1) sprand(10,1,.1) rand(10)])
@test issparse([sprand(10,1,.1); rand(10)])
@test issparse([sprand(10,.1) rand(10)])
@test issparse([sprand(10,.1); rand(10)])
@pkofod
Copy link
Author

pkofod commented Jun 2, 2016

Hmm, it's the SparseVector, right? It's more specific, so it won't fall back to the abstractsparsevector method...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment