Skip to content

Handle empty matrix #192

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

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/coloring/matrix2graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Returns a vector of rows where each row contains
a vector of its column indices.
"""
function _cols_by_rows(rows_index,cols_index)
nrows = maximum(rows_index)
nrows = isempty(rows_index) ? 0 : maximum(rows_index)
cols_by_rows = [eltype(rows_index)[] for _ in 1:nrows]
for (i,j) in zip(rows_index,cols_index)
push!(cols_by_rows[i],j)
Expand Down
4 changes: 4 additions & 0 deletions test/test_specialmatrices.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using SparseDiffTools
using SparseArrays
using LinearAlgebra
using BandedMatrices
using BlockBandedMatrices
using Test

n=10
dense=fill(1.,(n,n))
Expand All @@ -13,6 +15,7 @@ bidiagonalU=Bidiagonal(dense,:U)
bidiagonalL=Bidiagonal(dense,:L)
tridiagonal=Tridiagonal(dense)
symtridiagonal=SymTridiagonal(dense)
emptymat=sparse(Int[], Int[], true, 1, 1)

banded=BandedMatrix(dense,(1,2))
blockbanded1=BlockBandedMatrix(dense,[1,2,3,4],[4,3,2,1],(1,0))
Expand Down Expand Up @@ -60,3 +63,4 @@ _testvalidity(blockbanded1)
_testvalidity(blockbanded2)
_testvalidity(bandedblockbanded1)
_testvalidity(bandedblockbanded2)
_testvalidity(emptymat)