Do networkx graphs have a comparison method? We could imitate that, if need be.
- kcrisman On Mar 18, 9:23 am, Niles <nil...@gmail.com> wrote: > Well, I'm stumped (not too surprising), but here's what I think after > a little reading: > > * It seems that there is no comparison implemented for graphs, > anywhere in sage: Graph inherits from GenericGraph, which inherits > from GenericGraph_pyx, which inherits from SageObject. Functions like > __cmp__ or _cmp_ or _rich_cmp_ or whatever don't appear anywhere in > any of this code -- that's not too surprising because something like > g1._<tab> doesn't show any kind of comparison function either. > > * So the only other possibility I can imagine is that comparison of > graphs is falling back to whatever Python does by default to compare > things. Or maybe it's falling back on some other default not in > SageObject; in any case, a ticket should probably be filed to > implement comparison for graphs. > > * Here's a detail about the default Python implementation of > comparison, which might explain why you get erratic behavior [1]: > > > CPython implementation detail: Objects of different types except numbers > > are ordered by their type names; objects of the same types that don’t > > support proper comparison are ordered by their address. > > best, > Niles > > [1] :http://docs.python.org/library/stdtypes.html > > On Mar 17, 11:34 pm, Ryan Hinton <iob...@email.com> wrote: > > > > > Where are the comparison operators for graphs implemented? I can find > > ``__eq__`` in graphs/generic_graph.py, but I can't find any others. > > > I haven't opened a ticket yet for the following behavior because I am > > not sure where the problem is. > > > The current status is some new math! At the moment, I see the > > following. (The following sometimes works, sometimes needs fiddling > > with order of creation or which graphs get a vertex.) > > > sage: g1 = Graph() > > sage: g1.add_vertex(0) > > sage: g2 = Graph() > > sage: g3 = Graph() > > sage: g3.add_vertex(0) > > sage: g1 == g3 > > True > > sage: g1 == g2 > > False > > sage: g1 < g2 > > False > > sage: g3 < g2 > > True > > > So we have two equal graphs that compare on either side of a third > > graph! > > > Thanks! > > > - Ryan -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org