Skip to content

Commit b511c9c

Browse files
committed
Add test
1 parent 22d37ca commit b511c9c

3 files changed

Lines changed: 27 additions & 11 deletions

File tree

src/graph.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ SparseArrays.nnz(S::SparsityPatternCSC) = length(S.rowval)
3232
SparseArrays.rowvals(S::SparsityPatternCSC) = S.rowval
3333
SparseArrays.nzrange(S::SparsityPatternCSC, j::Integer) = S.colptr[j]:(S.colptr[j + 1] - 1)
3434

35+
# Needed if using `coloring(::SparsityPatternCSC, ...)`
36+
function Base.similar(A::SparsityPatternCSC, ::Type{T}) where {T}
37+
return SparseArrays.SparseMatrixCSC(
38+
A.m,
39+
A.n,
40+
A.colptr,
41+
A.rowval,
42+
similar(A.rowval, T),
43+
)
44+
end
45+
3546
"""
3647
transpose(S::SparsityPatternCSC)
3748

src/matrices.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,6 @@ respectful_similar(A::AbstractMatrix) = respectful_similar(A, eltype(A))
4949

5050
respectful_similar(A::AbstractMatrix, ::Type{T}) where {T} = similar(A, T)
5151

52-
# Needed if using `coloring(::SparsityPatternCSC, ...)`
53-
function respectful_similar(A::SparsityPatternCSC, ::Type{T}) where {T}
54-
return SparseArrays.SparseMatrixCSC(
55-
A.m,
56-
A.n,
57-
A.colptr,
58-
A.rowval,
59-
similar(A.rowval, T),
60-
)
61-
end
62-
6352
function respectful_similar(A::Transpose, ::Type{T}) where {T}
6453
return transpose(respectful_similar(parent(A), T))
6554
end

test/structured.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,19 @@ end;
5656
test_structured_coloring_decompression(A)
5757
end
5858
end;
59+
60+
# See https://github.com/gdalle/SparseMatrixColorings.jl/pull/299
61+
@testset "SparsityPatternCSC" begin
62+
S = sparse([
63+
0 0 1 1 0 1
64+
1 0 0 0 1 0
65+
0 1 0 0 1 0
66+
0 1 1 0 0 0
67+
])
68+
P = SparseMatrixColorings.SparsityPatternCSC(S)
69+
problem = ColoringProblem()
70+
algo = GreedyColoringAlgorithm()
71+
result = coloring(P, problem, algo)
72+
B = compress(S, result)
73+
@test decompress(B, result) isa SparseMatrixCSC{Int,Int}
74+
end;

0 commit comments

Comments
 (0)