[sage-devel] Re: Messing up hash and cmp with UniqueRepresentation

2013-02-03 Thread Simon King
Hi, On 2013-01-30, Simon King wrote: > Another patch, that cythons UniqueRepresentation and seems to > drastically improve the performance of using UniqueRepresentation > instances as dictionary keys, will soon be ready. The patch is now posted at #14054. About performance: For example, the tim

[sage-devel] Re: Messing up hash and cmp with UniqueRepresentation

2013-01-31 Thread Nils Bruin
On Jan 31, 6:49 am, "Nicolas M. Thiery" wrote: > Shall we ask the Cython devs to implement the __classcall__ protocol? > Then we could merge the factory function and the class in Cython > classes as is done by UniqueRepresentation. I guess that could be quite doable for "python" style classes th

Re: [sage-devel] Re: Messing up hash and cmp with UniqueRepresentation

2013-01-31 Thread Nicolas M. Thiery
On Thu, Jan 24, 2013 at 12:08:15PM -0800, Nils Bruin wrote: > Ouch, yes that is a fundamental problem. What one should have is a > custom `__new__` on UniqueRepresentation, with the python semantics, > not the cython __cinit__ (formerly called and still accepted __new__). > And there you can see th

[sage-devel] Re: Messing up hash and cmp with UniqueRepresentation

2013-01-30 Thread Simon King
Hi! As a preparatory step, I improved the parsing of function definitions in sage_getargspec. This is needed for putting UniqueRepresentation into a .pyx file, because currently function definitions in a .pyx file containing varargs and keywords are not correctly parsed. By consequence, the @[weak

[sage-devel] Re: Messing up hash and cmp with UniqueRepresentation

2013-01-24 Thread Simon King
Hi Nils, On 2013-01-24, Nils Bruin wrote: >> > And that's a >> > problem when cythoning UniqueRepresentation, because currently it is a >> > Python class with __eq__, __ne__ and __hash__ implemented, but not with >> > __richcmp__. > > That is NOT a problem! If you don't want to implement __le__,

[sage-devel] Re: Messing up hash and cmp with UniqueRepresentation

2013-01-24 Thread Nils Bruin
On Jan 24, 11:29 am, Travis Scrimshaw wrote: > > And now the catch: In a Cython class, you can not directly implement > > __eq__, but you *must* implement __richcmp__ instead. > > That seems strange to me... That's just how Cpython chose to implement those routines. Instead of putting a whole bun

[sage-devel] Re: Messing up hash and cmp with UniqueRepresentation

2013-01-24 Thread Travis Scrimshaw
Hey Simon, >> Isn't that a total mess? Is there a reason why UniqueRepresentation > >> provides __eq__ and __hash__, but not __cmp__? > >> > > > > I thought __cmp__() is only called if __eq__() is not implemented? > > I did not check the documentation before writing the following, but I > th

[sage-devel] Re: Messing up hash and cmp with UniqueRepresentation

2013-01-24 Thread Simon King
Hi Travis, On 2013-01-24, Travis Scrimshaw wrote: >> Isn't that a total mess? Is there a reason why UniqueRepresentation >> provides __eq__ and __hash__, but not __cmp__? >> > > I thought __cmp__() is only called if __eq__() is not implemented? I did not check the documentation before writing

[sage-devel] Re: Messing up hash and cmp with UniqueRepresentation

2013-01-23 Thread Simon King
Hi Andrew, On 2013-01-23, Andrew Mathas wrote: >> At #13991, we try to fix a speed regression that comes from the fact >> that Partitions(n) is not a unique parent > > I'm currently reviewing a patch #13605 by Travis Scrimshaw which, among > other things, makes Partitions into unique parents.

[sage-devel] Re: Messing up hash and cmp with UniqueRepresentation

2013-01-23 Thread Travis Scrimshaw
Hey Simon and Nils, On Wednesday, January 23, 2013 2:28:44 PM UTC-8, Simon King wrote: > > Hi! > > At #13991, we try to fix a speed regression that comes from the fact > that Partitions(n) is not a unique parent, combined with #12313 making > the caching of homsets depend on identity (not equal

[sage-devel] Re: Messing up hash and cmp with UniqueRepresentation

2013-01-23 Thread Nils Bruin
On Jan 23, 2:43 pm, Simon King wrote: > Since MyClass inherits from UniqueRepresentation, comparison should be > by identity. But I thought that == would rely on __eq__ (which *is* > provided by UniqueRepresentation). Are the 2 microseconds really the > to-be-expected overhead of calling UniqueRep

[sage-devel] Re: Messing up hash and cmp with UniqueRepresentation

2013-01-23 Thread Andrew Mathas
> At #13991, we try to fix a speed regression that comes from the fact > that Partitions(n) is not a unique parent > Hi Simon, I'm currently reviewing a patch #13605 by Travis Scrimshaw which, among other things, makes Partitions into unique parents. Andrew -- You received this message bec

[sage-devel] Re: Messing up hash and cmp with UniqueRepresentation

2013-01-23 Thread Simon King
PS: sage: class MyClass(UniqueRepresentation, CombinatorialClass): : def __init__(self, n): : self.n = n : CombinatorialClass.__init__(self) : def __repr__(self): : return "Level %s"%self.n : sage: A = MyClass(1) sage: