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

Add a sparse ev_view for SymTridiagonal backed by sparse arrays #225

Closed
wants to merge 2 commits into from

Conversation

mcognetta
Copy link
Contributor

@mcognetta mcognetta commented Aug 16, 2022

This is a fix for JuliaLang/LinearAlgebra.jl#942, where SymTridiagonal matrices backed by sparse arrays couldn't be summed/subtracted/etc. The root cause is that adding @views of SparseArrays produces a dense array.

https://github.com/JuliaLang/julia/blob/ec98087cbf19bac26f6be05df9282746b0cffe78/stdlib/LinearAlgebra/src/tridiag.jl#L207

https://github.com/JuliaLang/julia/blob/ec98087cbf19bac26f6be05df9282746b0cffe78/stdlib/LinearAlgebra/src/LinearAlgebra.jl#L449-L453

julia> z = @view sparse([1, 2, 3])[1:3]
3-element view(::SparseVector{Int64, Int64}, 1:3) with eltype Int64:
 1
 2
 3

julia> z + z
3-element Vector{Int64}:
 2
 4
 6

This view usage was added in JuliaLang/julia#42472 to deal with an implementation detail of SymTridiagonals where the off-diagonal has an additional element that should usually be ignored. A view was used to access only the actual elements of the off-diagonal without copying. This PR makes it so that sparse arrays just use a regular (copying) slice, until a better fix is found (I am not sure if there has been any discussion about the sparse @view sum thing).

@SobhanMP
Copy link
Member

wouldn't it be just better to fix SparseVectorView + SparseVectorView addition? @ViralBShah yet another argument for AbstractCompressedSparseVector?

@mcognetta
Copy link
Contributor Author

Yes, it would be better, if that is something that should actually be done. I don't know if there are any weird considerations that need to be addressed when summing two views though, so I am fixing it this way for now.

@ViralBShah
Copy link
Member

Yeah we should just fix the views.

@SobhanMP
Copy link
Member

@ViralBShah so do i extract the AbstractCompressedVector from JuliaLang/julia#201 and merge it? We can make the default for all operations on AbstractCompressedVectors return SparseVectors

@ViralBShah
Copy link
Member

@Wimmerer Any thoughts on your part?

@rayegun
Copy link
Member

rayegun commented Aug 21, 2022

@ViralBShah so do i extract the AbstractCompressedVector from JuliaLang/julia#201 and merge it? We can make the default for all operations on AbstractCompressedVectors return SparseVectors

@SobhanMP Yes.

@codecov-commenter
Copy link

codecov-commenter commented Aug 21, 2022

Codecov Report

Merging #225 (984209f) into main (f51b64c) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     JuliaLang/julia#225      +/-   ##
==========================================
+ Coverage   92.11%   92.12%   +0.01%     
==========================================
  Files          11       11              
  Lines        7203     7204       +1     
==========================================
+ Hits         6635     6637       +2     
+ Misses        568      567       -1     
Impacted Files Coverage Δ
src/SparseArrays.jl 100.00% <100.00%> (ø)
src/linalg.jl 84.58% <0.00%> (+0.08%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants