Skip to content

Commit 5f6ace6

Browse files
committed
Merge remote-tracking branch 'origin/main' into tutorials
2 parents c307ca7 + 172fd12 commit 5f6ace6

32 files changed

Lines changed: 2019 additions & 882 deletions

Project.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
name = "SparseMatrixColorings"
22
uuid = "0a514795-09f3-496d-8182-132a7b665d35"
33
authors = ["Guillaume Dalle", "Alexis Montoison"]
4-
version = "0.4.13"
4+
version = "0.4.19"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
8-
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
98
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
109
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1110
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1211
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1312

1413
[weakdeps]
14+
CliqueTrees = "60701a23-6482-424a-84db-faee86b9b1f8"
1515
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
1616

1717
[extensions]
18+
SparseMatrixColoringsCliqueTreesExt = "CliqueTrees"
1819
SparseMatrixColoringsColorsExt = "Colors"
1920

2021
[compat]
2122
ADTypes = "1.2.1"
23+
CliqueTrees = "1"
2224
Colors = "0.12.11, 0.13"
23-
DataStructures = "0.18"
2425
DocStringExtensions = "0.8,0.9"
2526
LinearAlgebra = "<0.0.1, 1"
2627
Random = "<0.0.1, 1"

benchmark/benchmarks.jl

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using BenchmarkTools
22
using LinearAlgebra
33
using SparseMatrixColorings
4+
import SparseMatrixColorings as SMC
45
using SparseArrays
56
using StableRNGs
67

@@ -19,21 +20,23 @@ for structure in [:nonsymmetric, :symmetric],
1920
p in [2 / n, 5 / n, 10 / n]
2021

2122
problem = ColoringProblem(; structure, partition)
22-
algo = GreedyColoringAlgorithm(; decompression, postprocessing=true)
23+
algo = GreedyColoringAlgorithm(
24+
RandomOrder(StableRNG(0), 0); decompression, postprocessing=true
25+
)
2326

2427
# use several random matrices to reduce variance
2528
nb_samples = 5
2629
As = [sparse(Symmetric(sprand(StableRNG(i), Bool, n, n, p))) for i in 1:nb_samples]
27-
results = [coloring(A, problem, algo) for A in As]
28-
Bs = [compress(A, result) for (A, result) in zip(As, results)]
30+
results = [coloring(A, problem, algo; decompression_eltype=Float64) for A in As]
31+
Bs = [compress(Float64.(A), result) for (A, result) in zip(As, results)]
2932

30-
SUITE[:coloring][structure][partition][decompression]["n=$n"]["p=$p"] = @benchmarkable begin
33+
bench_col = @benchmarkable begin
3134
for A in $As
3235
coloring(A, $problem, $algo)
3336
end
3437
end
3538

36-
SUITE[:decompress][structure][partition][decompression]["n=$n"]["p=$p"] = @benchmarkable begin
39+
bench_dec = @benchmarkable begin
3740
for (B, result) in zip($Bs, $results)
3841
if B isa AbstractMatrix
3942
decompress(B, result)
@@ -42,4 +45,34 @@ for structure in [:nonsymmetric, :symmetric],
4245
end
4346
end
4447
end
48+
49+
SUITE[:coloring][structure][partition][decompression]["n=$n"]["p=$p"] = bench_col
50+
SUITE[:decompress][structure][partition][decompression]["n=$n"]["p=$p"] = bench_dec
51+
end
52+
53+
for structure in [:nonsymmetric, :symmetric],
54+
partition in (structure == :nonsymmetric ? [:column, :row] : [:column]),
55+
order in [LargestFirst(), SmallestLast(), IncidenceDegree(), DynamicLargestFirst()],
56+
n in [10^3, 10^5],
57+
p in [2 / n, 5 / n, 10 / n]
58+
59+
nb_samples = 5
60+
As = [sparse(Symmetric(sprand(StableRNG(i), Bool, n, n, p))) for i in 1:nb_samples]
61+
if structure == :symmetric
62+
gs = [SMC.AdjacencyGraph(A) for A in As]
63+
bench_ord = @benchmarkable begin
64+
for g in $gs
65+
SMC.vertices(g, $order)
66+
end
67+
end
68+
else
69+
gs = [SMC.BipartiteGraph(A) for A in As]
70+
valside = partition == :row ? Val(1) : Val(2)
71+
bench_ord = @benchmarkable begin
72+
for g in $gs
73+
SMC.vertices(g, $valside, $order)
74+
end
75+
end
76+
end
77+
SUITE[:order][structure][partition][string(order)]["n=$n"]["p=$p"] = bench_ord
4578
end

docs/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
77
MatrixMarket = "4d4711f2-db25-561a-b6b3-d35e7d4047d3"
88
SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35"
99
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
10+
11+
[sources]
12+
SparseMatrixColorings = {path=".."}

docs/src/api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SparseMatrixColorings
1515

1616
```@docs
1717
coloring
18+
fast_coloring
1819
ColoringProblem
1920
GreedyColoringAlgorithm
2021
ConstantColoringAlgorithm
@@ -52,4 +53,5 @@ SmallestLast
5253
IncidenceDegree
5354
DynamicLargestFirst
5455
DynamicDegreeBasedOrder
56+
PerfectEliminationOrder
5557
```

docs/src/dev.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ SparseMatrixColorings.BipartiteGraph
1616
SparseMatrixColorings.vertices
1717
SparseMatrixColorings.neighbors
1818
transpose
19+
SparseMatrixColorings.bidirectional_pattern
1920
```
2021

2122
## Low-level coloring
2223

2324
```@docs
2425
SparseMatrixColorings.partial_distance2_coloring
25-
SparseMatrixColorings.symmetric_coefficient
2626
SparseMatrixColorings.star_coloring
2727
SparseMatrixColorings.acyclic_coloring
2828
SparseMatrixColorings.group_by_color
29+
SparseMatrixColorings.Forest
2930
SparseMatrixColorings.StarSet
3031
SparseMatrixColorings.TreeSet
3132
```

docs/src/vis.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,33 @@ problem_bi = ColoringProblem(; structure=:nonsymmetric, partition=:bidirectional
7474
algo_bi = GreedyColoringAlgorithm(RandomOrder(StableRNG(0)); postprocessing=true, decompression=:direct)
7575
result_bi = coloring(S, problem_bi, algo_bi)
7676
77-
A_img, Br_img, Bc_img = show_colors(
77+
Arc_img, Ar_img, Ac_img, Br_img, Bc_img = show_colors(
7878
result_bi;
7979
colorscheme=ColorSchemes.progress,
80-
background=RGB(1, 1, 1), # white
80+
background_color=RGB(1, 1, 1), # white
8181
scale=10,
82+
border=1,
8283
pad=2
8384
)
8485
```
8586

8687
In the bidirectional case, columns and rows can both get colors:
8788

8889
```@example img
89-
A_img
90+
Ar_img
91+
```
92+
93+
```@example img
94+
Ac_img
95+
```
96+
97+
Together, this yields:
98+
99+
```@example img
100+
Arc_img
90101
```
91102

92-
And there are two compression results, one by row and one by column:
103+
And there are two associated compression results, one by row and one by column:
93104

94105
```@example img
95106
Br_img
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module SparseMatrixColoringsCliqueTreesExt
2+
3+
import CliqueTrees: permutation, EliminationAlgorithm, MCS
4+
import SparseArrays: SparseMatrixCSC, rowvals, nnz
5+
import SparseMatrixColorings:
6+
AdjacencyGraph, BipartiteGraph, PerfectEliminationOrder, pattern, vertices
7+
8+
PerfectEliminationOrder() = PerfectEliminationOrder(MCS())
9+
10+
function vertices(g::AdjacencyGraph{T}, order::PerfectEliminationOrder) where {T}
11+
S = pattern(g)
12+
13+
# construct matrix with sparsity pattern S
14+
M = SparseMatrixCSC{Bool,T}(size(S)..., S.colptr, rowvals(S), ones(Bool, nnz(S)))
15+
16+
# construct a perfect elimination order
17+
# self-loops are ignored
18+
order, _ = permutation(M; alg=order.elimination_algorithm)
19+
20+
return reverse!(order)
21+
end
22+
23+
end # module

0 commit comments

Comments
 (0)