Skip to content

Commit

Permalink
Fix #20409: rank for sparse matrices.
Browse files Browse the repository at this point in the history
  • Loading branch information
ViralBShah committed Dec 17, 2018
1 parent 01fe7c2 commit f229e1f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions stdlib/SuiteSparse/src/spqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ _ret_size(F::QRSparse, b::AbstractVector) = (size(F, 2),)
_ret_size(F::QRSparse, B::AbstractMatrix) = (size(F, 2), size(B, 2))

LinearAlgebra.rank(F::QRSparse) = reduce(max, view(F.R.rowval, 1:nnz(F.R)), init = eltype(F.R.rowval)(0))
LinearAlgebra.rank(S::SparseMatrixCSC) = rank(qr(S))

function (\)(F::QRSparse{T}, B::VecOrMat{Complex{T}}) where T<:LinearAlgebra.BlasReal
# |z1|z3| reinterpret |x1|x2|x3|x4| transpose |x1|y1| reshape |x1|y1|x3|y3|
Expand Down
5 changes: 4 additions & 1 deletion stdlib/SuiteSparse/test/spqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ end
end

@testset "rank" begin
@test rank(qr(sprandn(10, 5, 1.0)*sprandn(5, 10, 1.0))) == 5
S = sprandn(10, 5, 1.0)*sprandn(5, 10, 1.0)
@test rank(qr(S)) == 5
@test rank(S) == 5
@test all(iszero, (rank(qr(spzeros(10, i))) for i in 1:10))
@test all(iszero, (rank(spzeros(10, i)) for i in 1:10))
end

end

0 comments on commit f229e1f

Please sign in to comment.