Skip to content

Commit 49e126f

Browse files
committed
some care in genus.pyx
1 parent d592e08 commit 49e126f

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

src/sage/graphs/generic_graph_pyx.pyx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,10 @@ def small_integer_to_graph6(n):
487487
"""
488488
if n < 63:
489489
return chr(n + 63)
490-
else:
491-
# get 18-bit rep of n
492-
n = int_to_binary_string(n)
493-
n = '0'*(18 - len(n)) + n
494-
return chr(126) + binary_string_to_graph6(n)
490+
# get 18-bit rep of n
491+
n = int_to_binary_string(n)
492+
n = '0'*(18 - len(n)) + n
493+
return chr(126) + binary_string_to_graph6(n)
495494

496495

497496
def length_and_string_from_graph6(s):

src/sage/graphs/genus.pyx

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -597,31 +597,31 @@ def simple_connected_graph_genus(G, set_embedding=False, check=True, minimal=Tru
597597

598598
if minimal and G.is_planar(set_embedding=set_embedding):
599599
return 0
600+
601+
if check:
602+
if not G.is_connected():
603+
raise ValueError("Cannot compute the genus of a disconnected graph")
604+
605+
if G.is_directed() or G.has_multiple_edges() or G.has_loops():
606+
G = G.to_simple()
607+
608+
G, vmap = G.relabel(inplace=False, return_map=True)
609+
backmap = {u: v for v, u in vmap.items()}
610+
G = Graph(G, sparse=False)
611+
GG = simple_connected_genus_backtracker(G._backend.c_graph()[0])
612+
613+
if minimal:
614+
style = 1
615+
cutoff = 1
600616
else:
601-
if check:
602-
if not G.is_connected():
603-
raise ValueError("Cannot compute the genus of a disconnected graph")
604-
605-
if G.is_directed() or G.has_multiple_edges() or G.has_loops():
606-
G = G.to_simple()
607-
608-
G, vmap = G.relabel(inplace=False, return_map=True)
609-
backmap = {u: v for v, u in vmap.items()}
610-
G = Graph(G, sparse=False)
611-
GG = simple_connected_genus_backtracker(G._backend.c_graph()[0])
612-
613-
if minimal:
614-
style = 1
615-
cutoff = 1
616-
else:
617-
style = 2
618-
cutoff = 1 + (G.num_edges() - G.num_verts()) / 2 # rounding here is ok
619-
620-
g = GG.genus(style=style, cutoff=cutoff, record_embedding=set_embedding)
621-
if set_embedding:
622-
oE = {}
623-
E = GG.get_embedding()
624-
for v in E:
625-
oE[backmap[v]] = [backmap[x] for x in E[v]]
626-
oG.set_embedding(oE)
627-
return g
617+
style = 2
618+
cutoff = 1 + (G.num_edges() - G.num_verts()) / 2 # rounding here is ok
619+
620+
g = GG.genus(style=style, cutoff=cutoff, record_embedding=set_embedding)
621+
if set_embedding:
622+
oE = {}
623+
E = GG.get_embedding()
624+
for v in E:
625+
oE[backmap[v]] = [backmap[x] for x in E[v]]
626+
oG.set_embedding(oE)
627+
return g

0 commit comments

Comments
 (0)