Skip to content

Commit 1cb3884

Browse files
authored
Add sparsity_pattern getter for results (#135)
1 parent ae7fa30 commit 1cb3884

7 files changed

Lines changed: 41 additions & 19 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SparseMatrixColorings"
22
uuid = "0a514795-09f3-496d-8182-132a7b665d35"
33
authors = ["Guillaume Dalle", "Alexis Montoison"]
4-
version = "0.4.3"
4+
version = "0.4.4"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

docs/src/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ column_colors
2828
row_colors
2929
column_groups
3030
row_groups
31+
sparsity_pattern
3132
```
3233

3334
## Decompression

src/SparseMatrixColorings.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export ConstantColoringAlgorithm
6060
export coloring
6161
export column_colors, row_colors
6262
export column_groups, row_groups
63+
export sparsity_pattern
6364
export compress, decompress, decompress!, decompress_single_color!
6465

6566
end

src/result.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Combination between the type parameters of [`ColoringProblem`](@ref) and [`Greed
1919
2020
- [`column_colors`](@ref) and [`column_groups`](@ref) (for a `:column` or `:bidirectional` partition)
2121
- [`row_colors`](@ref) and [`row_groups`](@ref) (for a `:row` or `:bidirectional` partition)
22+
- [`sparsity_pattern`](@ref)
2223
- [`compress`](@ref), [`decompress`](@ref), [`decompress!`](@ref), [`decompress_single_color!`](@ref)
2324
2425
!!! warning
@@ -84,6 +85,16 @@ column_groups(result::AbstractColoringResult{s,:column}) where {s} = result.grou
8485
row_colors(result::AbstractColoringResult{s,:row}) where {s} = result.color
8586
row_groups(result::AbstractColoringResult{s,:row}) where {s} = result.group
8687

88+
"""
89+
sparsity_pattern(result::AbstractColoringResult)
90+
91+
Return the matrix that was initially passed to [`coloring`](@ref), without any modifications.
92+
93+
!!! note
94+
This matrix is not necessarily a `SparseMatrixCSC`, nor does it necessarily have `Bool` entries.
95+
"""
96+
sparsity_pattern(result::AbstractColoringResult) = result.A
97+
8798
## Concrete subtypes
8899

89100
"""

test/random.jl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ using ADTypes: column_coloring, row_coloring, symmetric_coloring
22
using LinearAlgebra
33
using SparseArrays
44
using SparseMatrixColorings
5-
using SparseMatrixColorings:
6-
structurally_orthogonal_columns,
7-
symmetrically_orthogonal_columns,
8-
directly_recoverable_columns
95
using StableRNGs
106
using Test
117

@@ -29,15 +25,11 @@ symmetric_params = vcat(
2925
@testset "$((; m, n, p))" for (m, n, p) in asymmetric_params
3026
A0 = sprand(rng, m, n, p)
3127
color0 = column_coloring(A0, algo)
32-
@test structurally_orthogonal_columns(A0, color0)
33-
@test directly_recoverable_columns(A0, color0)
3428
test_coloring_decompression(A0, problem, algo; color0)
3529
end
3630
@testset "$((; n, p))" for (n, p) in symmetric_params
3731
A0 = sparse(Symmetric(sprand(rng, n, n, p)))
3832
color0 = column_coloring(A0, algo)
39-
@test structurally_orthogonal_columns(A0, color0)
40-
@test directly_recoverable_columns(A0, color0)
4133
test_coloring_decompression(A0, problem, algo; color0)
4234
end
4335
end;
@@ -48,15 +40,11 @@ end;
4840
@testset "$((; m, n, p))" for (m, n, p) in asymmetric_params
4941
A0 = sprand(rng, m, n, p)
5042
color0 = row_coloring(A0, algo)
51-
@test structurally_orthogonal_columns(transpose(A0), color0)
52-
@test directly_recoverable_columns(transpose(A0), color0)
5343
test_coloring_decompression(A0, problem, algo; color0)
5444
end
5545
@testset "$((; n, p))" for (n, p) in symmetric_params
5646
A0 = sparse(Symmetric(sprand(rng, n, n, p)))
5747
color0 = row_coloring(A0, algo)
58-
@test structurally_orthogonal_columns(transpose(A0), color0)
59-
@test directly_recoverable_columns(transpose(A0), color0)
6048
test_coloring_decompression(A0, problem, algo; color0)
6149
end
6250
end;
@@ -67,8 +55,6 @@ end;
6755
@testset "$((; n, p))" for (n, p) in symmetric_params
6856
A0 = sparse(Symmetric(sprand(rng, n, n, p)))
6957
color0 = symmetric_coloring(A0, algo)
70-
@test symmetrically_orthogonal_columns(A0, color0)
71-
@test directly_recoverable_columns(A0, color0)
7258
test_coloring_decompression(A0, problem, algo; color0)
7359
end
7460
end;

test/suitesparse.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ colpack_table_6_7 = CSV.read(
3131

3232
@testset "Distance-2 coloring (ColPack paper)" begin
3333
@testset "$(row[:name])" for row in eachrow(colpack_table_6_7)
34-
@info "Testing distance-2 coloring for $(row[:name]) against ColPack paper"
3534
original_mat = matrixdepot("$(row[:group])/$(row[:name])")
3635
mat = dropzeros(original_mat)
3736
bg = BipartiteGraph(mat)
@@ -59,7 +58,6 @@ what_table_31_32 = CSV.read(
5958
@testset "Distance-2 coloring (survey paper)" begin
6059
@testset "$(row[:name])" for row in eachrow(what_table_31_32)
6160
ismissing(row[:group]) && continue
62-
@info "Testing distance-2 coloring for $(row[:name]) against survey paper"
6361
original_mat = matrixdepot("$(row[:group])/$(row[:name])")
6462
mat = original_mat # no dropzeros
6563
bg = BipartiteGraph(mat)
@@ -89,7 +87,6 @@ what_table_41_42 = CSV.read(
8987
@testset "Star coloring (survey paper)" begin
9088
@testset "$(row[:name])" for row in eachrow(what_table_41_42)
9189
ismissing(row[:group]) && continue
92-
@info "Testing star coloring for $(row[:name]) against survey paper"
9390
original_mat = matrixdepot("$(row[:group])/$(row[:name])")
9491
mat = dropzeros(sparse(original_mat))
9592
ag = AdjacencyGraph(mat)

test/utils.jl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
using LinearAlgebra
22
using SparseMatrixColorings
33
using SparseMatrixColorings:
4-
AdjacencyGraph, LinearSystemColoringResult, matrix_versions, respectful_similar
4+
AdjacencyGraph,
5+
LinearSystemColoringResult,
6+
directly_recoverable_columns,
7+
matrix_versions,
8+
respectful_similar,
9+
structurally_orthogonal_columns,
10+
symmetrically_orthogonal_columns
511
using Test
612

713
function test_coloring_decompression(
@@ -32,10 +38,29 @@ function test_coloring_decompression(
3238
B = compress(A, result)
3339

3440
@testset "Reference" begin
41+
@test sparsity_pattern(result) === A # identity of objects
3542
!isnothing(color0) && @test color == color0
3643
!isnothing(B0) && @test B == B0
3744
end
3845

46+
@testset "Recoverability" begin
47+
# TODO: find tests for recoverability for substitution decompression
48+
if decompression == :direct
49+
if structure == :nonsymmetric
50+
if partition == :column
51+
@test structurally_orthogonal_columns(A0, color)
52+
@test directly_recoverable_columns(A0, color)
53+
else
54+
@test structurally_orthogonal_columns(transpose(A0), color)
55+
@test directly_recoverable_columns(transpose(A0), color)
56+
end
57+
else
58+
@test symmetrically_orthogonal_columns(A0, color)
59+
@test directly_recoverable_columns(A0, color)
60+
end
61+
end
62+
end
63+
3964
@testset "Full decompression" begin
4065
@test decompress(B, result) A0
4166
@test decompress(B, result) A0 # check result wasn't modified
@@ -102,6 +127,7 @@ function test_coloring_decompression(
102127
if structure == :symmetric && count(!iszero, A) > 0 # sparse factorization cannot handle empty matrices
103128
ag = AdjacencyGraph(A)
104129
linresult = LinearSystemColoringResult(A, ag, color, Float64)
130+
@test sparsity_pattern(result) === A # identity of objects
105131
@test decompress(float.(B), linresult) A0
106132
@test decompress!(respectful_similar(float.(A)), float.(B), linresult) A0
107133
end

0 commit comments

Comments
 (0)