From 263519b0f68fb7eba6defb814ab6dc85a6468c65 Mon Sep 17 00:00:00 2001 From: schillic Date: Thu, 4 Jul 2019 17:38:40 +0200 Subject: [PATCH 1/2] define rank for sparse submatrix --- src/Arrays/matrix_operations.jl | 3 +++ 1 file changed, 3 insertions(+) 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 From 34639c20f3972627b6f0c2712bac3d691467bf17 Mon Sep 17 00:00:00 2001 From: schillic Date: Thu, 4 Jul 2019 17:42:22 +0200 Subject: [PATCH 2/2] unit test for rank --- test/unit_util.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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