From 326c57718ac93ec2fb3d88d03e345e30a927cc8b Mon Sep 17 00:00:00 2001 From: dcoudert Date: Wed, 23 Oct 2024 16:39:20 +0200 Subject: [PATCH 1/3] fix issue #38832 --- src/sage/graphs/bipartite_graph.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/sage/graphs/bipartite_graph.py b/src/sage/graphs/bipartite_graph.py index 45e4c67747d..1be201822c5 100644 --- a/src/sage/graphs/bipartite_graph.py +++ b/src/sage/graphs/bipartite_graph.py @@ -2633,11 +2633,29 @@ class by some canonization function `c`. If `G` and `H` are graphs, sage: C.right {4, 5, 6} + TESTS: + + Check that :issue:`38832` is fixed:: + + sage: B = BipartiteGraph(matrix([[1, 1], [1, 1]])) + sage: C = B.canonical_label() + sage: C.left, C.right + ({0, 1}, {2, 3}) + sage: B.canonical_label(certificate=True) + (Bipartite graph on 4 vertices, {0: 0, 1: 1, 2: 2, 3: 3}) + sage: C = B.canonical_label(edge_labels=True) + sage: C.left, C.right + ({0, 1}, {2, 3}) + sage: B.allow_multiple_edges(True) + sage: B.add_edges(G.edges()) + sage: C = B.canonical_label() + sage: C.left, C.right + ({0, 1}, {2, 3}) + .. SEEALSO:: :meth:`~sage.graphs.generic_graph.GenericGraph.canonical_label()` """ - if certificate: C, cert = GenericGraph.canonical_label(self, partition=partition, certificate=certificate, @@ -2669,6 +2687,8 @@ class by some canonization function `c`. If `G` and `H` are graphs, cert = {v: c[G_to[relabeling[v]]] for v in self} else: + if partition is None: + partition = self.bipartition() G_vertices = list(chain(*partition)) G_to = {u: i for i, u in enumerate(G_vertices)} H = Graph(len(G_vertices)) From 864bcdb57320edd29cb26f7a32d5bfa8b92746cc Mon Sep 17 00:00:00 2001 From: dcoudert Date: Wed, 23 Oct 2024 17:39:38 +0200 Subject: [PATCH 2/3] #38842: fix doctests --- src/sage/graphs/bipartite_graph.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sage/graphs/bipartite_graph.py b/src/sage/graphs/bipartite_graph.py index 1be201822c5..240b62c7c96 100644 --- a/src/sage/graphs/bipartite_graph.py +++ b/src/sage/graphs/bipartite_graph.py @@ -2641,13 +2641,14 @@ class by some canonization function `c`. If `G` and `H` are graphs, sage: C = B.canonical_label() sage: C.left, C.right ({0, 1}, {2, 3}) - sage: B.canonical_label(certificate=True) - (Bipartite graph on 4 vertices, {0: 0, 1: 1, 2: 2, 3: 3}) + sage: C, certificate = B.canonical_label(certificate=True) + sage: C.left, C.right + ({0, 1}, {2, 3}) sage: C = B.canonical_label(edge_labels=True) sage: C.left, C.right ({0, 1}, {2, 3}) sage: B.allow_multiple_edges(True) - sage: B.add_edges(G.edges()) + sage: B.add_edges(B.edges()) sage: C = B.canonical_label() sage: C.left, C.right ({0, 1}, {2, 3}) From ddad107c93659448b0f0715c9382c699ebd21fdf Mon Sep 17 00:00:00 2001 From: dcoudert Date: Wed, 23 Oct 2024 18:04:07 +0200 Subject: [PATCH 3/3] #38842: make doctests more robusts --- src/sage/graphs/bipartite_graph.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/sage/graphs/bipartite_graph.py b/src/sage/graphs/bipartite_graph.py index 240b62c7c96..e21ec47e9cf 100644 --- a/src/sage/graphs/bipartite_graph.py +++ b/src/sage/graphs/bipartite_graph.py @@ -2638,20 +2638,16 @@ class by some canonization function `c`. If `G` and `H` are graphs, Check that :issue:`38832` is fixed:: sage: B = BipartiteGraph(matrix([[1, 1], [1, 1]])) - sage: C = B.canonical_label() - sage: C.left, C.right - ({0, 1}, {2, 3}) - sage: C, certificate = B.canonical_label(certificate=True) - sage: C.left, C.right - ({0, 1}, {2, 3}) - sage: C = B.canonical_label(edge_labels=True) - sage: C.left, C.right - ({0, 1}, {2, 3}) + sage: B.canonical_label() + Bipartite graph on 4 vertices + sage: B.canonical_label(certificate=True)[0] + Bipartite graph on 4 vertices + sage: B.canonical_label(edge_labels=True) + Bipartite graph on 4 vertices sage: B.allow_multiple_edges(True) sage: B.add_edges(B.edges()) - sage: C = B.canonical_label() - sage: C.left, C.right - ({0, 1}, {2, 3}) + sage: B.canonical_label() + Bipartite multi-graph on 4 vertices .. SEEALSO::