For some reason, google won't let me grab your patch. Anyway, converting to string is not a good idea. Better to hash a tuple of real, imag I think. (Maybe you did this already?)
I don't seem able to send in a key function sorted; I'll try sort(cmp=) in a moment. I wonder if I hit a Pyrex bug? Thanks for the reply. Nick On Mar 19, 8:06 am, "William Stein" <[EMAIL PROTECTED]> wrote: > On 3/19/07, Mike Hansen <[EMAIL PROTECTED]> wrote: > > > > <type 'exceptions.TypeError'>: unhashable type: > > > 'sage.rings.complex_number.ComplexNumber' > > > You should be able to just add the following to the ComplexNumber class: > > > def __hash__(self): > > return str(self).__hash__() > > > That should work so long as the complex number is completely > > determined by its __str__. I'm not sure if ComplexNumbers are mutable > > or immutable, but if they are mutable, you need to make sure not to > > change them while they are dictionary keys; otherwise, bad things will > > happen. > > Complex numbers are immutable. All numeric types in SAGE > are immutable, including polynomials. The only elements > that are not immutable are matrices (which can be set immutable), and > vectors (which will soon have an immutability flag too). > > I've attached a patch for some numerical hashing to this email. > > > I'm not sure about the sort under sagex which reminds me that I should > > get a better understanding of pyrex. > > Sorting under sagex is exactly the same as under Python, > unless you want to something new at the C level. E.g., > you can use L.sort(cmp=...) if L is a list. > > 3490.patch > 1KDownload --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---