Skip to content

Commit 6fba67e

Browse files
gdalleamontoison
authored andcommitted
Generalize the API to enable bicoloring
1 parent e541dbf commit 6fba67e

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

src/decompression.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
"""
22
compress(A, result::AbstractColoringResult)
33
4-
Compress `A` into a new matrix `B`, given a coloring `result` of the sparsity pattern of `A`.
4+
Compress `A` given a coloring `result` of the sparsity pattern of `A`.
5+
6+
- If `result` comes from a `:column` (resp. `:row`) partition, the output is a single matrix `B` compressed by column (resp. by row).
7+
- If `result` comes from a `:bidirectional` partition, the output is a tuple of matrices `(Br, Bc)`, where `Br` is compressed by row and `Bc` by column.
58
69
Compression means summing either the columns or the rows of `A` which share the same color.
710
It is undone by calling [`decompress`](@ref).
811
12+
!!! warning
13+
At the moment, `:bidirectional` partitions are not implemented.
14+
915
# Example
1016
1117
```jldoctest
@@ -36,6 +42,7 @@ julia> B = compress(A, result)
3642
3743
# See also
3844
45+
- [`ColoringProblem`](@ref)
3946
- [`AbstractColoringResult`](@ref)
4047
"""
4148
function compress end
@@ -104,6 +111,7 @@ true
104111
105112
# See also
106113
114+
- [`ColoringProblem`](@ref)
107115
- [`AbstractColoringResult`](@ref)
108116
"""
109117
function decompress(B::AbstractMatrix{R}, result::AbstractColoringResult) where {R<:Real}
@@ -165,6 +173,7 @@ true
165173
166174
# See also
167175
176+
- [`ColoringProblem`](@ref)
168177
- [`AbstractColoringResult`](@ref)
169178
"""
170179
function decompress!(

src/interface.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
Selector type for the coloring problem to solve, enabling multiple dispatch.
55
6-
It is used inside the main function [`coloring`](@ref).
6+
It is passed as an argument to the main function [`coloring`](@ref).
77
88
# Constructor
99
@@ -23,11 +23,15 @@ It is used inside the main function [`coloring`](@ref).
2323
2424
Matrix coloring is often used in automatic differentiation, and here is the translation guide:
2525
26-
| matrix | mode | `structure` | `partition` |
27-
| -------- | -------------------- | --------------- | ----------- |
28-
| Jacobian | forward | `:nonsymmetric` | `:column` |
29-
| Jacobian | reverse | `:nonsymmetric` | `:row` |
30-
| Hessian | forward-over-reverse | `:symmetric` | `:column` |
26+
| matrix | mode | `structure` | `partition` |
27+
| -------- | -------------------- | --------------- | -----------------|
28+
| Jacobian | forward | `:nonsymmetric` | `:column` |
29+
| Jacobian | reverse | `:nonsymmetric` | `:row` |
30+
| Jacobian | forward + reverse | `:nonsymmetric` | `:bidirectional` |
31+
| Hessian | any | `:symmetric` | `:column` |
32+
33+
!!! warning
34+
At the moment, `:bidirectional` partitions are not implemented.
3135
"""
3236
struct ColoringProblem{structure,partition,decompression} end
3337

@@ -47,7 +51,7 @@ end
4751
4852
Greedy coloring algorithm for sparse matrices which colors columns or rows one after the other, following a configurable order.
4953
50-
It is used inside the main function [`coloring`](@ref).
54+
It is passed as an argument to the main function [`coloring`](@ref).
5155
5256
# Constructor
5357

src/result.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
## Abstract type
22

33
"""
4-
AbstractColoringResult
4+
AbstractColoringResult{structure,partition,decompression}
55
66
Abstract type for the result of a coloring algorithm.
77
88
It is the supertype of the object returned by the main function [`coloring`](@ref).
99
10+
# Type parameters
11+
12+
Same as those of the [`ColoringProblem`](@ref) that was solved to obtain the result:
13+
14+
- `structure::Symbol`: either `:nonsymmetric` or `:symmetric`
15+
- `partition::Symbol`: either `:column`, `:row` or `:bidirectional`
16+
- `decompression::Symbol`: either `:direct` or `:substitution`
17+
1018
# Applicable methods
1119
1220
- [`column_colors`](@ref) and [`column_groups`](@ref) (for a `:column` or `:bidirectional` partition)

0 commit comments

Comments
 (0)