Skip to content

Commit 8806a4c

Browse files
authored
Merge pull request #192 from JuliaDiff/myb/empty
Handle empty matrix
2 parents f70fd6d + d69aaaa commit 8806a4c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/coloring/matrix2graph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Returns a vector of rows where each row contains
55
a vector of its column indices.
66
"""
77
function _cols_by_rows(rows_index,cols_index)
8-
nrows = maximum(rows_index)
8+
nrows = isempty(rows_index) ? 0 : maximum(rows_index)
99
cols_by_rows = [eltype(rows_index)[] for _ in 1:nrows]
1010
for (i,j) in zip(rows_index,cols_index)
1111
push!(cols_by_rows[i],j)

test/test_specialmatrices.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using SparseDiffTools
2+
using SparseArrays
23
using LinearAlgebra
34
using BandedMatrices
45
using BlockBandedMatrices
6+
using Test
57

68
n=10
79
dense=fill(1.,(n,n))
@@ -13,6 +15,7 @@ bidiagonalU=Bidiagonal(dense,:U)
1315
bidiagonalL=Bidiagonal(dense,:L)
1416
tridiagonal=Tridiagonal(dense)
1517
symtridiagonal=SymTridiagonal(dense)
18+
emptymat=sparse(Int[], Int[], true, 1, 1)
1619

1720
banded=BandedMatrix(dense,(1,2))
1821
blockbanded1=BlockBandedMatrix(dense,[1,2,3,4],[4,3,2,1],(1,0))
@@ -60,3 +63,4 @@ _testvalidity(blockbanded1)
6063
_testvalidity(blockbanded2)
6164
_testvalidity(bandedblockbanded1)
6265
_testvalidity(bandedblockbanded2)
66+
_testvalidity(emptymat)

0 commit comments

Comments
 (0)