diff --git a/src/Arrays/matrix_operations.jl b/src/Arrays/matrix_operations.jl index 9a90a9bf5d..af09b9b588 100644 --- a/src/Arrays/matrix_operations.jl +++ b/src/Arrays/matrix_operations.jl @@ -17,6 +17,9 @@ const DEFAULT_COND_TOL = 1e6 # rank of sparse matrix (see JuliaLang #30415) LinearAlgebra.rank(M::SparseMatrixCSC) = rank(qr(M)) +# rank of sparse submatrix (see #1497) +LinearAlgebra.rank(M::SubArray{N, 2, <:SparseMatrixCSC}) where {N} = + rank(sparse(M)) """ issquare(M::AbstractMatrix)::Bool diff --git a/test/unit_util.jl b/test/unit_util.jl index 7c639c13a4..2be0a77669 100644 --- a/test/unit_util.jl +++ b/test/unit_util.jl @@ -33,7 +33,10 @@ for _dummy_ in 1:1 # avoid global variable warnings # diagonal matrix @test LazySets.isinvertible(Diagonal([2 0; 0 2])) @test !LazySets.isinvertible(Diagonal([2 0; 0 0])) - # diagonal matrices are always square + + # matrix rank + A = sprandn(2, 10, 0.4) + @test rank(Matrix(A)) == rank(A) == rank(view(A, :, :)) for N in [Float64, Rational{Int}, Float32] # substitution