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

Unexpected behaviours of spdiagm #37174

Closed
phipsgabler opened this issue Aug 24, 2020 · 0 comments · Fixed by #37684
Closed

Unexpected behaviours of spdiagm #37174

phipsgabler opened this issue Aug 24, 2020 · 0 comments · Fixed by #37684
Labels
sparse Sparse arrays

Comments

@phipsgabler
Copy link
Contributor

phipsgabler commented Aug 24, 2020

Say we have

julia> y = sprand(10, 0.2)
10-element SparseVector{Float64,Int64} with 2 stored entries:
  [2 ]  =  0.804026
  [3 ]  =  0.0159904

Then, firstly, there is no method that works implicitly on the main diagonal, like diagm(y) does -- you have to explicitely say spdiagm(0 => y). Secondly, and more importantly, this method does not preserve sparsity of the input:

julia> spdiagm(0 => y)
10×10 SparseMatrixCSC{Float64,Int64} with 10 stored entries:
  [1 ,  1]  =  0.0
  [2 ,  2]  =  0.804026
  [3 ,  3]  =  0.0159904
  [4 ,  4]  =  0.0
  [5 ,  5]  =  0.0
  [6 ,  6]  =  0.0
  [7 ,  7]  =  0.0
  [8 ,  8]  =  0.0
  [9 ,  9]  =  0.0
  [10, 10]  =  0.0

Where I really had expected the result to be

julia> spdiagm(0 => y)
10×10 SparseMatrixCSC{Float64,Int64} with 2 stored entries:
  [2 ,  2]  =  0.804026
  [3 ,  3]  =  0.0159904

(That's on 1.3.1, sorry for not having updated yet :))

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
2 participants