Skip to content

Commit df53bde

Browse files
committed
Merge branch 'main' into gd/structured
2 parents ef19b99 + 1cb3884 commit df53bde

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
@@ -63,6 +63,7 @@ export ConstantColoringAlgorithm
6363
export coloring
6464
export column_colors, row_colors
6565
export column_groups, row_groups
66+
export sparsity_pattern
6667
export compress, decompress, decompress!, decompress_single_color!
6768

6869
if !isdefined(Base, :get_extension)

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
@@ -4,7 +4,13 @@ using BlockBandedMatrices: BlockBandedMatrix
44
using LinearAlgebra
55
using SparseMatrixColorings
66
using SparseMatrixColorings:
7-
AdjacencyGraph, LinearSystemColoringResult, matrix_versions, respectful_similar
7+
AdjacencyGraph,
8+
LinearSystemColoringResult,
9+
directly_recoverable_columns,
10+
matrix_versions,
11+
respectful_similar,
12+
structurally_orthogonal_columns,
13+
symmetrically_orthogonal_columns
814
using Test
915

1016
function test_coloring_decompression(
@@ -35,10 +41,29 @@ function test_coloring_decompression(
3541
B = compress(A, result)
3642

3743
@testset "Reference" begin
44+
@test sparsity_pattern(result) === A # identity of objects
3845
!isnothing(color0) && @test color == color0
3946
!isnothing(B0) && @test B == B0
4047
end
4148

49+
@testset "Recoverability" begin
50+
# TODO: find tests for recoverability for substitution decompression
51+
if decompression == :direct
52+
if structure == :nonsymmetric
53+
if partition == :column
54+
@test structurally_orthogonal_columns(A0, color)
55+
@test directly_recoverable_columns(A0, color)
56+
else
57+
@test structurally_orthogonal_columns(transpose(A0), color)
58+
@test directly_recoverable_columns(transpose(A0), color)
59+
end
60+
else
61+
@test symmetrically_orthogonal_columns(A0, color)
62+
@test directly_recoverable_columns(A0, color)
63+
end
64+
end
65+
end
66+
4267
@testset "Full decompression" begin
4368
@test decompress(B, result) A0
4469
@test decompress(B, result) A0 # check result wasn't modified
@@ -105,6 +130,7 @@ function test_coloring_decompression(
105130
if structure == :symmetric && count(!iszero, A) > 0 # sparse factorization cannot handle empty matrices
106131
ag = AdjacencyGraph(A)
107132
linresult = LinearSystemColoringResult(A, ag, color, Float64)
133+
@test sparsity_pattern(result) === A # identity of objects
108134
@test decompress(float.(B), linresult) A0
109135
@test decompress!(respectful_similar(float.(A)), float.(B), linresult) A0
110136
end

0 commit comments

Comments
 (0)