Skip to content

Commit a7cb154

Browse files
blegatamontoison
andauthored
Fix respectful_similar with SparsityPatternCSC (#299)
* Fix respectful_similar with SparsityPatternCSC * Add test * Fix format * Add test --------- Co-authored-by: Alexis Montoison <35051714+amontoison@users.noreply.github.com>
1 parent 921c7a0 commit a7cb154

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/graph.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ 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(A.m, A.n, A.colptr, A.rowval, similar(A.rowval, T))
38+
end
39+
3540
"""
3641
transpose(S::SparsityPatternCSC)
3742

test/structured.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using ArrayInterface: ArrayInterface
22
using BandedMatrices: BandedMatrix, brand
33
using BlockBandedMatrices: BandedBlockBandedMatrix, BlockBandedMatrix
44
using LinearAlgebra
5+
using SparseArrays
56
using SparseMatrixColorings
67
using Test
78

@@ -56,3 +57,19 @@ end;
5657
test_structured_coloring_decompression(A)
5758
end
5859
end;
60+
61+
# See https://github.com/gdalle/SparseMatrixColorings.jl/pull/299
62+
@testset "SparsityPatternCSC $T" for T in [Int, Float32]
63+
S = sparse(T[
64+
0 0 1 1 0 1
65+
1 0 0 0 1 0
66+
0 1 0 0 1 0
67+
0 1 1 0 0 0
68+
])
69+
P = SparseMatrixColorings.SparsityPatternCSC(S)
70+
problem = ColoringProblem()
71+
algo = GreedyColoringAlgorithm()
72+
result = coloring(P, problem, algo)
73+
B = compress(S, result)
74+
@test decompress(B, result) isa SparseMatrixCSC{T,Int}
75+
end;

0 commit comments

Comments
 (0)