|
1 | 1 | using BenchmarkTools |
2 | 2 | using LinearAlgebra |
3 | 3 | using SparseMatrixColorings |
| 4 | +import SparseMatrixColorings as SMC |
4 | 5 | using SparseArrays |
| 6 | +using StableRNGs |
5 | 7 |
|
6 | 8 | SUITE = BenchmarkGroup() |
7 | 9 |
|
8 | 10 | for structure in [:nonsymmetric, :symmetric], |
9 | | - partition in (structure == :nonsymmetric ? [:column, :row] : [:column]), |
10 | | - decompression in (structure == :nonsymmetric ? [:direct] : [:direct, :substitution]), |
| 11 | + partition in (structure == :nonsymmetric ? [:column, :row, :bidirectional] : [:column]), |
| 12 | + decompression in ( |
| 13 | + if (structure == :nonsymmetric && partition in [:column, :row]) |
| 14 | + [:direct] |
| 15 | + else |
| 16 | + [:direct, :substitution] |
| 17 | + end |
| 18 | + ), |
11 | 19 | n in [10^3, 10^5], |
12 | 20 | p in [2 / n, 5 / n, 10 / n] |
13 | 21 |
|
14 | 22 | problem = ColoringProblem(; structure, partition) |
15 | | - algo = GreedyColoringAlgorithm(; decompression) |
16 | | - |
17 | | - SUITE[:coloring][structure][partition][decompression]["n=$n"]["p=$p"] = @benchmarkable coloring( |
18 | | - A, $problem, $algo |
19 | | - ) setup = ( # |
20 | | - A = sparse(Symmetric(sprand($n, $n, $p))) |
| 23 | + algo = GreedyColoringAlgorithm( |
| 24 | + RandomOrder(StableRNG(0), 0); decompression, postprocessing=true |
21 | 25 | ) |
22 | 26 |
|
23 | | - SUITE[:decompress][structure][partition][decompression]["n=$n"]["p=$p"] = @benchmarkable decompress( |
24 | | - B, result |
25 | | - ) setup = ( # |
26 | | - A = sparse(Symmetric(sprand($n, $n, $p))); |
27 | | - result = coloring(A, $problem, $algo); |
28 | | - B = compress(A, result) |
29 | | - ) |
| 27 | + # use several random matrices to reduce variance |
| 28 | + nb_samples = 5 |
| 29 | + As = [sparse(Symmetric(sprand(StableRNG(i), Bool, n, n, p))) for i in 1:nb_samples] |
| 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)] |
| 32 | + |
| 33 | + bench_col = @benchmarkable begin |
| 34 | + for A in $As |
| 35 | + coloring(A, $problem, $algo) |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + bench_dec = @benchmarkable begin |
| 40 | + for (B, result) in zip($Bs, $results) |
| 41 | + if B isa AbstractMatrix |
| 42 | + decompress(B, result) |
| 43 | + elseif B isa Tuple |
| 44 | + decompress(B[1], B[2], result) |
| 45 | + end |
| 46 | + end |
| 47 | + 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 |
30 | 78 | end |
0 commit comments