G.relabel problem

80 views
Skip to first unread message

Pedro Cruz

unread,
Apr 25, 2014, 2:04:16 PM4/25/14
to sage-s...@googlegroups.com
To the graph package maintainers,

Using 
   G.relabel( [ i+1 for i in range(G.order()) ], inplace=True )
and repeat the same command once more causes the error below.

But using 
   G.relabel(lambda i: i+1, inplace=True)
twice does not produce the error.

(at least this it's not intuitive for me)

Thanks,

Pedro
┌────────────────────────────────────────────────────────────────────┐
│ Sage Version 6.1.1, Release Date: 2014-02-04 │
└────────────────────────────────────────────────────────────────────┘

sage: G = graphs.PetersenGraph()
sage: G.relabel( [ i+1 for i in range(G.order()) ], inplace=True )
sage: G.vertices()
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
sage: G.relabel( [ i+1 for i in range(G.order()) ], inplace=True )
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-4-bf2b8e5b2a10> in <module>()
----> 1 G.relabel( [ i+Integer(1) for i in range(G.order()) ], inplace=True )


/home/jpedro/sage-6.1.1/local/lib/python2.7/site-packages/sage/graphs/generic_graph.pyc in relabel(self, perm, inplace, return_map, check_input, complete_partial_function)
16716 if check_input:
16717 if len(set(perm.values())) < len(perm):
> 16718 raise NotImplementedError("Non injective relabeling")
16719
16720 for v in perm.iterkeys():

NotImplementedError: Non injective relabeling

Nathann Cohen

unread,
Apr 28, 2014, 4:47:14 AM4/28/14
to sage-s...@googlegroups.com
Hello !!

Using 
   G.relabel( [ i+1 for i in range(G.order()) ], inplace=True )
and repeat the same command once more causes the error below.

That is because of that (rom the doc of Graph.relabel) :

        If ``perm`` is a dictionary ``d``, then each vertex ``v``
        (which should be a key of ``d``) is relabeled to ``d[v]``.
        Similarly, if ``perm`` is a list or tuple ``l`` of length
        ``n``, then each vertex (which should be in `\{0,1,...,n-1\}`)
        is relabeled to ``l[v]`

I agree that the error message is not clear, though.

The reason is the following : If your vertices are named "a","r","whatever","hello" and you want to relabel them with "1,2,3,4" then there is no way to know which vertex is theone that should be renamed to 1, which to 2, etc ... If your vertex set is 0,1,2,3 ... to begin with,  then we "can assume" that you want vertex 0 to be renamed to the first vertex of your list, vertex 1 to the second, etc ...

When you use the second syntax :
 
But using 
   G.relabel(lambda i: i+1, inplace=True)
twice does not produce the error.

there is no such doubt, and we know which vertex should be renamed to which output by applying the lambda function.

I think we should change the code above, so that when you feed .relabel() with a list then the "first vertex of g.vertices()" is labeled with the "first vertex of your list", etc, etc ... I hope that it will not create any confusion that I do not see at the moment.

Nathann

Nathann Cohen

unread,
Apr 28, 2014, 5:01:33 AM4/28/14
to sage-s...@googlegroups.com
The problem is now fixed by this ticket :


If you can review it, it will be merged faster, possibly into the next release :-)

Thanks for the report,

Nathann
Reply all
Reply to author
Forward
0 new messages