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
# Create a list of spokes for each star, preallocating their sizes based on nb_spokes
152
-
spokes = [Vector{Int}(undef, ns) for ns in nb_spokes]
153
-
154
-
# Reuse nb_spokes as counters to track the current index while filling the spokes
155
-
fill!(nb_spokes, 0)
156
-
157
-
for ((i, j), s) inpairs(star)
158
-
h =abs(hub[s])
159
-
nb_spokes[s] +=1
160
-
index = nb_spokes[s]
161
-
162
-
# Assign the non-hub vertex (spoke) to the correct position in spokes
163
-
if i == h
164
-
spokes[s][index] = j
165
-
elseif j == h
166
-
spokes[s][index] = i
167
-
end
168
-
end
169
-
returnStarSet(star, hub, spokes)
152
+
return color, star_set, edge_to_index
170
153
end
171
154
172
-
_sort(u, v) = (min(u, v), max(u, v))
173
-
174
155
function_treat!(
175
156
# modified
176
157
treated::AbstractVector{<:Integer},
@@ -191,86 +172,112 @@ end
191
172
192
173
function_update_stars!(
193
174
# modified
194
-
star::Dict{<:Tuple,<:Integer},
175
+
star::AbstractVector{<:Integer},
195
176
hub::AbstractVector{<:Integer},
196
177
nb_spokes::AbstractVector{<:Integer},
197
178
# not modified
198
179
g::AdjacencyGraph,
199
180
v::Integer,
200
181
color::AbstractVector{<:Integer},
201
182
first_neighbor::AbstractVector{<:Tuple},
183
+
edge_to_index::AbstractVector{<:Integer},
202
184
)
203
-
for w inneighbors(g, v)
204
-
iszero(color[w]) &&continue
205
-
vw =_sort(v, w)
185
+
S =pattern(g)
186
+
for (iw, w) inenumerate(neighbors2(g, v))
187
+
(v == w ||iszero(color[w])) &&continue
188
+
index_vw = edge_to_index[S.colptr[v] + iw -1]
206
189
x_exists =false
207
-
for x inneighbors(g, w)
190
+
for (ix, x) inenumerate(neighbors2(g, w))
191
+
(x == w) &&continue
208
192
if x != v && color[x] == color[v] # vw, wx ∈ E
209
-
wx=_sort(w, x)
210
-
star_wx = star[wx]
193
+
index_wx=edge_to_index[S.colptr[w] + ix -1]
194
+
star_wx = star[index_wx]
211
195
hub[star_wx] = w # this may already be true
212
196
nb_spokes[star_wx] +=1
213
-
star[vw] = star_wx
197
+
star[index_vw] = star_wx
214
198
x_exists =true
215
199
break
216
200
end
217
201
end
218
202
if!x_exists
219
-
(p, q) = first_neighbor[color[w]]
203
+
(p, q, index_pq) = first_neighbor[color[w]]
220
204
if p == v && q != w # vw, vq ∈ E and color[w] = color[q]
221
-
vq =_sort(v, q)
222
-
star_vq = star[vq]
205
+
star_vq = star[index_pq]
223
206
hub[star_vq] = v # this may already be true
224
207
nb_spokes[star_vq] +=1
225
-
star[vw] = star_vq
208
+
star[index_vw] = star_vq
226
209
else# vw forms a new star
227
210
push!(hub, -max(v, w)) # star is trivial (composed only of two vertices) so we set the hub to a negative value, but it allows us to choose one of the two vertices
228
211
push!(nb_spokes, 1)
229
-
star[vw] =length(hub)
212
+
star[index_vw] =length(hub)
230
213
end
231
214
end
232
215
end
233
216
returnnothing
234
217
end
235
218
236
219
"""
237
-
symmetric_coefficient(
238
-
i::Integer, j::Integer,
239
-
color::AbstractVector{<:Integer},
240
-
star_set::StarSet
241
-
)
242
-
243
-
Return the indices `(k, c)` such that `A[i, j] = B[k, c]`, where `A` is the uncompressed symmetric matrix and `B` is the column-compressed matrix.
220
+
StarSet
244
221
245
-
This function corresponds to algorithm `DirectRecover2` in the paper.
222
+
Encode a set of 2-colored stars resulting from the [`star_coloring`](@ref) algorithm.
246
223
247
-
# References
224
+
# Fields
248
225
249
-
> [_Efficient Computation of Sparse Hessians Using Coloring and Automatic Differentiation_](https://pubsonline.informs.org/doi/abs/10.1287/ijoc.1080.0286), Gebremedhin et al. (2009), Figure 3
0 commit comments