I'm trying to fix
https://github.com/JuliaLang/julia/issues/16661 but I have a dispatch problem.
Basically, I am trying to add functionality such that sparse vector and sparse matrix concatenation returns a sparse matrix, and I thought I would make sparse matrix and vector + sparse vector and vector return sparse as well while I was at it.
The sparse / dense, sparse / sparse combinations all work, but! For some reason concatenation on an Array of SparseVector s return a SparseMatrixCSC not a SparseVector. I don't really understand why. It is the following test that doesn't work
let m = 80, n = 100
A = Array{SparseVector{Float64,Int}}(n)
tnnz = 0
for i = 1:length(A)
A[i] = sprand(m, 0.3)
tnnz += nnz(A[i])
end
H = hcat(A...)
@test isa(H, SparseMatrixCSC{Float64,Int})
@test size(H) == (m, n)
@test nnz(H) == tnnz
Hr = zeros(m, n)
for j = 1:n
Hr[:,j] = full(A[j])
end
@test full(H) == Hr
V = vcat(A...)
@test isa(V, SparseVector{Float64,Int})
@test length(V) == m * n
Vr = vec(Hr)
@test full(V) == Vr
end
I am happy to explain anything that is not clear. Thanks