# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1361572641 -3600
# Node ID 1460b5f0f6ecafd0199dfa1d443054fd01a8ceac
# Parent d7b6a30e6acc9f2443b027d8836bb37ee5646919
Speedup in GenericGraph.relabel() and two new options -- new doctests
diff --git a/sage/graphs/generic_graph.py b/sage/graphs/generic_graph.py
a
|
b
|
|
15711 | 15711 | [1 0 1] |
15712 | 15712 | [0 1 0] |
15713 | 15713 | |
15714 | | Relabeling using a dictionary:: |
| 15714 | Relabeling using a dictionary. Note that the dictionary does not define |
| 15715 | the new label of vertex `0`:: |
15715 | 15716 | |
15716 | 15717 | sage: G.relabel({1:2,2:1}, inplace=False).am() |
15717 | 15718 | [0 0 1] |
15718 | 15719 | [0 0 1] |
15719 | 15720 | [1 1 0] |
15720 | 15721 | |
| 15722 | This is because the method automatically "extends" the relabeling to the |
| 15723 | missing vertices (whose label will not change). Checking that all |
| 15724 | vertices have an image can require some time, and this feature can be |
| 15725 | disabled (at your own risk):: |
| 15726 | |
| 15727 | sage: G.relabel({1:2,2:1}, inplace=False, complete_partial_function = False).am() |
| 15728 | Traceback (most recent call last): |
| 15729 | ... |
| 15730 | KeyError: 0 |
| 15731 | |
15721 | 15732 | Relabeling using a list:: |
15722 | 15733 | |
15723 | 15734 | sage: G.relabel([0,2,1], inplace=False).am() |
… |
… |
|
15752 | 15763 | sage: H.edges() |
15753 | 15764 | [(10, 11, None), (11, 12, None)] |
15754 | 15765 | |
15755 | | Relabeling using a non injective function is not yet supported:: |
| 15766 | Relabeling using a non injective function has no meaning:: |
15756 | 15767 | |
15757 | 15768 | sage: G.edges() |
15758 | 15769 | [(0, 1, None), (1, 2, None)] |
… |
… |
|
15761 | 15772 | ... |
15762 | 15773 | NotImplementedError: Non injective relabeling |
15763 | 15774 | |
| 15775 | But this test can be disabled, which leads to ... problems:: |
| 15776 | |
| 15777 | sage: G.edges() |
| 15778 | [(0, 1, None), (1, 2, None)] |
| 15779 | sage: G.relabel(lambda i: 0, check_input = False) |
| 15780 | sage: G.edges() |
| 15781 | [(0, 0, None)] |
| 15782 | |
15764 | 15783 | Relabeling to simpler labels:: |
15765 | 15784 | |
15766 | 15785 | sage: G = graphs.CubeGraph(3) |