[BGL] vertices creates new objects
I've just started playing with the python bindings of BGL and I'm puzzled from the following:
from boost.graph import Graph g = Graph() v = g.add_vertex() g.vertices.next() == v True g.vertices.next() is v False
It seems that the vertices iterator creates new vertex objects every time instead of iterating over the existing ones. This essentially prevents, among other things, storing vertices as keys in a dictionary since the hashes of the stored and the new vertex differ although they compare equal. Is this really what's happening, and if so, why ? Thanks, George
On Jan 29, 2007, at 12:52 AM, George Sakkis wrote:
I've just started playing with the python bindings of BGL and I'm puzzled from the following:
from boost.graph import Graph g = Graph() v = g.add_vertex() g.vertices.next() == v True g.vertices.next() is v False
It seems that the vertices iterator creates new vertex objects every time instead of iterating over the existing ones. This essentially prevents, among other things, storing vertices as keys in a dictionary since the hashes of the stored and the new vertex differ although they compare equal. Is this really what's happening, and if so, why ?
The latest version of the BGL-Python bindings, available in the Subversion repository, re-uses vertex and edge descriptors, so the last check would return "True". This is what we should have been doing all along. Cheers, Doug
Doug,
thanks for the prompt reply. Do you happen to have Windows binaries in
SVN too ?
By the way, I was trying to get my head around "property maps" and the
whole time I was thinking how redundant would all this boilerplate be
in pure Python. Perhaps I'm still missing the point, but why not allow
subclassing Vertices and Edges and store all (internal) properties as
attributes in the same object instead of dealing with property maps ?
I understand that this might be the way to go in a statically typed
B&D language but is there an advantage of using property maps in a
language like Python ? If not, I might end up writing a more pythonic
wrapper around the BGL binding; do you have any insights on how this
may work out?
Thanks,
George
On 1/29/07, Doug Gregor
On Jan 29, 2007, at 12:52 AM, George Sakkis wrote:
I've just started playing with the python bindings of BGL and I'm puzzled from the following:
from boost.graph import Graph g = Graph() v = g.add_vertex() g.vertices.next() == v True g.vertices.next() is v False
It seems that the vertices iterator creates new vertex objects every time instead of iterating over the existing ones. This essentially prevents, among other things, storing vertices as keys in a dictionary since the hashes of the stored and the new vertex differ although they compare equal. Is this really what's happening, and if so, why ?
The latest version of the BGL-Python bindings, available in the Subversion repository, re-uses vertex and edge descriptors, so the last check would return "True". This is what we should have been doing all along.
Cheers, Doug _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Jan 29, 2007, at 8:33 PM, George Sakkis wrote:
thanks for the prompt reply. Do you happen to have Windows binaries in SVN too ?
No, not yet. I'm trying to get all of the pieces together to put out another release, with binaries.
By the way, I was trying to get my head around "property maps" and the whole time I was thinking how redundant would all this boilerplate be in pure Python. Perhaps I'm still missing the point, but why not allow subclassing Vertices and Edges and store all (internal) properties as attributes in the same object instead of dealing with property maps ? I understand that this might be the way to go in a statically typed B&D language but is there an advantage of using property maps in a language like Python ? If not, I might end up writing a more pythonic wrapper around the BGL binding; do you have any insights on how this may work out?
I've also tried to address this problem in the development version. One can create or access new properties by naming the attribute in a vertex object. For example: from boost.graph import Graph g = Graph() v = g.add_vertex() v.color = 'Blue' # creates a new vertex property map called "color". v's color is the string 'Blue' These are still property maps under the hood, and one can get at the actual property map as, e.g., vertex_properties['color'] to be passed to various BGL algorithms. Cheers, Doug
participants (2)
-
Doug Gregor
-
George Sakkis