Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit d93fc4a

Browse files
committed
28531: further cleaning in bliss.pyx
1 parent 6e239eb commit d93fc4a

File tree

1 file changed

+37
-44
lines changed

1 file changed

+37
-44
lines changed

src/sage/graphs/bliss.pyx

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ cdef Graph *bliss_graph_from_labelled_edges(int Vnr, int Lnr, Vout, Vin, labels,
171171
- ``partition`` -- an ordered partition of the vertex set
172172
"""
173173
cdef Graph * g
174-
cdef int i, j, x, y, lab, Pnr, Enr
175-
cdef int logLnr = 1
174+
cdef int i, j, x, y, lab, Pnr, Enr, logLnr = 1
176175

177176
if Lnr <= 1:
178177
g = new Graph(Vnr)
@@ -186,9 +185,7 @@ cdef Graph *bliss_graph_from_labelled_edges(int Vnr, int Lnr, Vout, Vin, labels,
186185

187186
if Lnr <= 1:
188187
for i in range(Enr):
189-
x = Vout[i]
190-
y = Vin[i]
191-
g.add_edge(x, y)
188+
g.add_edge(Vout[i], Vin[i])
192189

193190
else:
194191
# arrows going up in layers
@@ -200,7 +197,6 @@ cdef Graph *bliss_graph_from_labelled_edges(int Vnr, int Lnr, Vout, Vin, labels,
200197
x = Vout[i]
201198
y = Vin[i]
202199
lab = labels[i] + 1
203-
204200
j = 0
205201
while lab:
206202
if lab & 1:
@@ -211,12 +207,11 @@ cdef Graph *bliss_graph_from_labelled_edges(int Vnr, int Lnr, Vout, Vin, labels,
211207
# vertex partition gives colors
212208
if partition:
213209
Pnr = len(partition)
214-
for i in range(len(partition)):
210+
for i in range(Pnr):
215211
for v in partition[i]:
216212
for j in range(logLnr):
217213
g.change_color(j * Vnr + v, j * Pnr + i)
218214
else:
219-
Pnr = 1
220215
for j in range(logLnr):
221216
for v in range(Vnr):
222217
g.change_color(j * Vnr + v, j)
@@ -252,53 +247,51 @@ cdef Digraph *bliss_digraph_from_labelled_edges(int Vnr, int Lnr, Vout, Vin, lab
252247
253248
- ``partition`` -- a partition of the vertex set
254249
"""
255-
cdef Py_ssize_t i, j
256-
cdef int logLnr = 0
257-
258250
cdef Digraph *g
259-
cdef int x, y, lab
251+
cdef int i, j, x, y, lab, Pnr, Enr, logLnr = 1
260252

261-
if Lnr == 1:
253+
if Lnr <= 1:
262254
g = new Digraph(Vnr)
263-
if not g:
264-
raise MemoryError("allocation failed")
265255
else:
266256
logLnr = encoding_numbits(Lnr)
267257
g = new Digraph(Vnr * logLnr)
268-
if not g:
269-
raise MemoryError("allocation failed")
270-
for j in range(1, logLnr):
271-
for i in range((j - 1) * Vnr, j * Vnr):
272-
g.add_edge(i, i + Vnr)
258+
if not g:
259+
raise MemoryError("allocation failed")
273260

274-
cdef int Enr = len(Vout)
261+
Enr = len(Vout)
275262

276-
for i in range(Enr):
277-
x = Vout[i]
278-
y = Vin[i]
279-
if Lnr == 1:
280-
lab = 0
281-
else:
282-
lab = labels[i]
263+
if Lnr <= 1:
264+
for i in range(Enr):
265+
g.add_edge(Vout[i], Vin[i])
266+
else:
267+
# arrows going up in layers
268+
for i in range(Vnr * (logLnr - 1)):
269+
g.add_edge(i, i + Vnr)
283270

284-
if lab:
285-
lab += 1
286-
for j in range(logLnr - 1, -1, -1):
287-
if lab & (1 << j):
271+
# arrows inside layers shadowing the original graph
272+
for i in range(Enr):
273+
x = Vout[i]
274+
y = Vin[i]
275+
lab = labels[i] + 1
276+
j = 0
277+
while lab:
278+
if lab & 1:
288279
g.add_edge(j * Vnr + x, j * Vnr + y)
289-
else:
290-
g.add_edge(x, y)
291-
292-
if not bool(partition):
293-
partition = [list(range(Vnr))]
294-
cdef Pnr = len(partition)
295-
for i in range(Pnr):
296-
for v in partition[i]:
297-
if Lnr == 1:
298-
g.change_color(v, i)
299-
else:
280+
j += 1
281+
lab >>= 1
282+
283+
# vertex partition gives color
284+
if partition:
285+
Pnr = len(partition)
286+
for i in range(Pnr):
287+
for v in partition[i]:
300288
for j in range(logLnr):
301289
g.change_color(j * Vnr + v, j * Pnr + i)
290+
else:
291+
for j in range(logLnr):
292+
for v in range(Vnr):
293+
g.change_color(j * Vnr + v, j)
294+
302295
return g
303296

304297
#####################################################
@@ -542,7 +535,7 @@ cpdef canonical_form(G, partition=None, return_graph=False, use_edge_labels=True
542535
Lnr = len(lab_to_index)
543536

544537
else:
545-
for x,y,lab in G.edge_iterator(labels=True):
538+
for x,y in G.edge_iterator(labels=False):
546539
Vout.append(vert2int[x])
547540
Vin.append(vert2int[y])
548541

0 commit comments

Comments
 (0)