Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various concatenations involving sparse vectors are dense but should be sparse #17738

Closed
Sacha0 opened this issue Aug 1, 2016 · 0 comments
Closed
Labels
sparse Sparse arrays

Comments

@Sacha0
Copy link
Member

Sacha0 commented Aug 1, 2016

Ref. #16661/#16722. Concatenations of sparse vectors, combinations of sparse vectors and matrices, and combinations of sparse and dense vectors are consistently sparse. All other concatenations involving sparse vectors fall back to the generic concatenation methods; in such concatenations, the result is often dense when the first argument is sparse, and typically dense when the first argument is not sparse. Some examples:

julia> vcat(rand(4, 1), spzeros(4))
8×1 Array{Float64,2}:
 0.320664
 0.250846
 0.463371
 0.7741
 0.0
 0.0
 0.0
 0.0

julia> hcat(spzeros(4), spzeros(4, 4), rand(4, 2))
4×7 Array{Float64,2}:
 0.0  0.0  0.0  0.0  0.0  0.0623076  0.469735
 0.0  0.0  0.0  0.0  0.0  0.303642   0.210563
 0.0  0.0  0.0  0.0  0.0  0.818678   0.984312
 0.0  0.0  0.0  0.0  0.0  0.71566    0.0121382

julia> hvcat((3,), spzeros(4), rand(4, 2), spzeros(4, 4))
4×7 Array{Float64,2}:
 0.0  0.251215  0.365575  0.0  0.0  0.0  0.0
 0.0  0.413717  0.411106  0.0  0.0  0.0  0.0
 0.0  0.481512  0.363571  0.0  0.0  0.0  0.0
 0.0  0.492115  0.538091  0.0  0.0  0.0  0.0

julia> cat((1,2), rand(4, 2), spzeros(4, 4), spzeros(4))
12×7 Array{Float64,2}:
 0.595454  0.425007  0.0  0.0  0.0  0.0  0.0
 0.155889  0.368775  0.0  0.0  0.0  0.0  0.0
 0.568131  0.926523  0.0  0.0  0.0  0.0  0.0
 0.116905  0.803143  0.0  0.0  0.0  0.0  0.0
 0.0       0.0       0.0  0.0  0.0  0.0  0.0
 0.0       0.0       0.0  0.0  0.0  0.0  0.0
 0.0       0.0       0.0  0.0  0.0  0.0  0.0
 0.0       0.0       0.0  0.0  0.0  0.0  0.0
 0.0       0.0       0.0  0.0  0.0  0.0  0.0
 0.0       0.0       0.0  0.0  0.0  0.0  0.0
 0.0       0.0       0.0  0.0  0.0  0.0  0.0
 0.0       0.0       0.0  0.0  0.0  0.0  0.0

Best!

(Edit: Ref. #17660)

@tkelman tkelman added the sparse Sparse arrays label Aug 1, 2016
tkelman added a commit that referenced this issue Aug 7, 2016
Fix #17675 (concatenations involving special matrices) and #17738 (concatenations involving sparse vectors)
@Sacha0 Sacha0 closed this as completed Aug 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sparse Sparse arrays
Projects
None yet
Development

No branches or pull requests

2 participants