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

fix (\) SparseVector in SuiteSparse.CHOLMOD #28526

Closed
wants to merge 2 commits into from

Conversation

pochoi
Copy link
Contributor

@pochoi pochoi commented Aug 8, 2018

(\) for Factor and SparseVecOrMat has the following method error:

julia> using SparseArrays, LinearAlgebra
julia> sparseI = sparse(1.0I, 100, 100);
julia> sparseb = sprandn(100, 0.5); #SparseVector
julia> chI = cholesky(sparseI); #Factor
julia> chI \ sparseb  sparseb #(\)(Factor, SparseVecOrMat)
ERROR: MethodError: no method matching SuiteSparse.CHOLMOD.Sparse(::SparseVector{Float64,Int64}, ::Int64)
Closest candidates are:
  SuiteSparse.CHOLMOD.Sparse(::Integer, ::Integer, ::Array{Int64,1}, ::Array{Int64,1}, ::Array{#s608,1} where #s608<:Union{Complex{Float64}, Float64}) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v0.7/SuiteSparse/src/cholmod.jl:882
  SuiteSparse.CHOLMOD.Sparse(::Integer, ::Integer, ::Array{Int64,1}, ::Array{Int64,1}, ::Array{Tv<:Union{Complex{Float64}, Float64},1}, ::Any) where Tv<:Union{Complex{Float64}, Float64} at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v0.7/SuiteSparse/src/cholmod.jl:848
  SuiteSparse.CHOLMOD.Sparse(::SparseMatrixCSC{Tv<:Union{Complex{Float64}, Float64},Int64}, ::Integer) where Tv<:Union{Complex{Float64}, Float64} at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v0.7/SuiteSparse/src/cholmod.jl:896
  ...
Stacktrace:
 [1] \(::SuiteSparse.CHOLMOD.Factor{Float64}, ::SparseVector{Float64,Int64}) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v0.7/SuiteSparse/src/cholmod.jl:1718
 [2] top-level scope at none:0

The method error is due to the call Sparse(A::SparseMatrixCSC{Tv,SuiteSparse_long}, stype::Integer).
It should call Sparse(A::SparseVector{<:VTypes,SuiteSparse_long}) and Sparse(A::SparseMatrixCSC{<:VTypes,<:ITypes}) instead.

I fixed it and wrote a test:

Test Summary:                        | Pass  Total
Test \ for Factor and SparseVecOrMat |    2      2

@@ -1714,7 +1714,7 @@ end
(\)(L::Factor{T}, B::StridedMatrix) where {T<:VTypes} = Matrix(L\Dense{T}(B))
(\)(L::Factor, B::Sparse) = spsolve(CHOLMOD_A, L, B)
# When right hand side is sparse, we have to ensure that the rhs is not marked as symmetric.
(\)(L::Factor, B::SparseVecOrMat) = sparse(spsolve(CHOLMOD_A, L, Sparse(B, 0)))
(\)(L::Factor, B::SparseVecOrMat) = sparse(spsolve(CHOLMOD_A, L, Sparse(B)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not completely clear but the comment right above is the explanation for the zero so it is wrong to remove it here. Instead, I'd just split the method into one for matrices and one for vectors.

Copy link
Member

@andreasnoack andreasnoack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See inline comment.

test for Factor and Symmetric Sparse Matrix
@pochoi
Copy link
Contributor Author

pochoi commented Aug 8, 2018

Thanks so much for the comment. I also wrote a test for the symmetric matrix case.

@ViralBShah
Copy link
Member

@pochoi Let's get this merged. I've submitted a new PR to rebase this PR on master and see if CI is good with it.

If you are able to rebase this PR to master I will close #34989.

@dkarrasch
Copy link
Member

In case this gets successfully rebased on master, I'd suggest #34989 (review).

ViralBShah added a commit that referenced this pull request Mar 5, 2020
* fix \ SparseVector

* split (\) for sparsevector;
test for Factor and Symmetric Sparse Matrix

Co-authored-by: Chi Po Choi <[email protected]>
@ViralBShah ViralBShah closed this Mar 5, 2020
@ViralBShah
Copy link
Member

I've merged #34989

@pochoi
Copy link
Contributor Author

pochoi commented Mar 5, 2020

Thank you so much!

KristofferC pushed a commit that referenced this pull request Mar 23, 2020
* fix \ SparseVector

* split (\) for sparsevector;
test for Factor and Symmetric Sparse Matrix

Co-authored-by: Chi Po Choi <[email protected]>
(cherry picked from commit d2f9677)
@KristofferC KristofferC mentioned this pull request Mar 23, 2020
27 tasks
ravibitsgoa pushed a commit to ravibitsgoa/julia that referenced this pull request Apr 9, 2020
* fix \ SparseVector

* split (\) for sparsevector;
test for Factor and Symmetric Sparse Matrix

Co-authored-by: Chi Po Choi <[email protected]>
KristofferC pushed a commit that referenced this pull request Apr 11, 2020
* fix \ SparseVector

* split (\) for sparsevector;
test for Factor and Symmetric Sparse Matrix

Co-authored-by: Chi Po Choi <[email protected]>
Moelf added a commit to Moelf/julia that referenced this pull request Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra sparse Sparse arrays
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants