You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/coloring.jl
+35-31Lines changed: 35 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -17,18 +17,18 @@ The vertices are colored in a greedy fashion, following the `order` supplied.
17
17
> [_What Color Is Your Jacobian? Graph Coloring for Computing Derivatives_](https://epubs.siam.org/doi/10.1137/S0036144504444711), Gebremedhin et al. (2005), Algorithm 3.2
@@ -76,16 +76,18 @@ If `postprocessing=true`, some colors might be replaced with `0` (the "neutral"
76
76
77
77
> [_New Acyclic and Star Coloring Algorithms with Application to Computing Hessians_](https://epubs.siam.org/doi/abs/10.1137/050639879), Gebremedhin et al. (2007), Algorithm 4.1
first_neighbor =fill((0, 0, 0), nv) # at first no neighbors have been encountered
86
-
treated =zeros(Int, nv)
87
-
star =Vector{Int}(undef, ne)
88
-
hub =Int[] # one hub for each star, including the trivial ones
85
+
color =zeros(T, nv)
86
+
forbidden_colors =zeros(T, nv)
87
+
first_neighbor =fill((zero(T), zero(T), zero(T)), nv) # at first no neighbors have been encountered
88
+
treated =zeros(T, nv)
89
+
star =Vector{T}(undef, ne)
90
+
hub =T[] # one hub for each star, including the trivial ones
89
91
vertices_in_order =vertices(g, order)
90
92
91
93
for v in vertices_in_order
@@ -196,11 +198,11 @@ Encode a set of 2-colored stars resulting from the [`star_coloring`](@ref) algor
196
198
197
199
$TYPEDFIELDS
198
200
"""
199
-
struct StarSet
201
+
struct StarSet{T}
200
202
"a mapping from edges (pair of vertices) to their star index"
201
-
star::Vector{Int}
203
+
star::Vector{T}
202
204
"a mapping from star indices to their hub (undefined hubs for single-edge stars are the negative value of one of the vertices, picked arbitrarily)"
203
-
hub::Vector{Int}
205
+
hub::Vector{T}
204
206
end
205
207
206
208
"""
@@ -226,15 +228,17 @@ If `postprocessing=true`, some colors might be replaced with `0` (the "neutral"
226
228
227
229
> [_New Acyclic and Star Coloring Algorithms with Application to Computing Hessians_](https://epubs.siam.org/doi/abs/10.1137/050639879), Gebremedhin et al. (2007), Algorithm 3.1
Copy file name to clipboardExpand all lines: src/constant.jl
+13-10Lines changed: 13 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ Indeed, for symmetric coloring problems, we need more than just the vector of co
14
14
15
15
- `partition::Symbol`: either `:row` or `:column`.
16
16
- `matrix_template::AbstractMatrix`: matrix for which the vector of colors was precomputed (the algorithm will only accept matrices of the exact same size).
17
-
- `color::Vector{Int}`: vector of integer colors, one for each row or column (depending on `partition`).
17
+
- `color::Vector{<:Integer}`: vector of integer colors, one for each row or column (depending on `partition`).
18
18
19
19
!!! warning
20
20
The second constructor (based on keyword arguments) is type-unstable.
@@ -222,11 +223,13 @@ The adjacency graph of a symmetric matrix `A ∈ ℝ^{n × n}` is `G(A) = (V, E)
222
223
223
224
> [_What Color Is Your Jacobian? SparsityPatternCSC Coloring for Computing Derivatives_](https://epubs.siam.org/doi/10.1137/S0036144504444711), Gebremedhin et al. (2005)
224
225
"""
225
-
struct AdjacencyGraph{T,has_diagonal}
226
+
struct AdjacencyGraph{T<:Integer,has_diagonal}
226
227
S::SparsityPatternCSC{T}
227
228
edge_to_index::Vector{T}
228
229
end
229
230
231
+
Base.eltype(::AdjacencyGraph{T}) where {T} = T
232
+
230
233
functionAdjacencyGraph(
231
234
S::SparsityPatternCSC{T},
232
235
edge_to_index::Vector{T}=build_edge_to_index(S);
@@ -298,7 +301,7 @@ function has_neighbor(g::AdjacencyGraph, v::Integer, u::Integer)
@@ -338,11 +341,13 @@ When `symmetric_pattern` is `true`, this construction is more efficient.
338
341
339
342
> [_What Color Is Your Jacobian? SparsityPatternCSC Coloring for Computing Derivatives_](https://epubs.siam.org/doi/10.1137/S0036144504444711), Gebremedhin et al. (2005)
0 commit comments