Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added immutable keyword argument to canonical_form function #39196

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/sage/graphs/bliss.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ cdef canonical_form_from_edge_list(int Vnr, list Vout, list Vin, int Lnr=1, list
return new_edges


cpdef canonical_form(G, partition=None, return_graph=False, use_edge_labels=True, certificate=False) noexcept:
cpdef canonical_form(G, partition=None, return_graph=False, use_edge_labels=True, certificate=False, immutable=False) noexcept:
r"""
Return a canonical label for the given (di)graph.

Expand All @@ -404,6 +404,9 @@ cpdef canonical_form(G, partition=None, return_graph=False, use_edge_labels=True
- ``certificate`` -- boolean (default: ``False``); when set to ``True``,
returns the labeling of G into a canonical graph

- ``immutable`` -- boolean (default: ``False``); when set to ``True``,
returns an immutable canonical label of the graph

TESTS::

sage: from sage.graphs.bliss import canonical_form # optional - bliss
Expand Down Expand Up @@ -503,6 +506,13 @@ cpdef canonical_form(G, partition=None, return_graph=False, use_edge_labels=True
Traceback (most recent call last):
...
ValueError: some vertices of the graph are not in the partition

Check that parameter ``immutable`` can be used::

sage: g = Graph({1: [2]})
sage: g_ = canonical_form(g, return_graph=True, immutable=True) # optional - bliss
sage: g_.is_immutable() # optional - bliss
True
"""
# We need this to convert the numbers from <unsigned int> to <long>.
# This assertion should be true simply for memory reasons.
Expand Down Expand Up @@ -589,6 +599,9 @@ cpdef canonical_form(G, partition=None, return_graph=False, use_edge_labels=True
H.add_vertices(range(G.order()))
return (H, relabel) if certificate else H

if immutable:
H = H.copy(immutable=True)

# Warning: this may break badly in Python 3 if the graph is not simple
return (sorted(new_edges), relabel) if certificate else sorted(new_edges)

Expand Down
Loading