Hi!

At #15247, I am introducing a class SingletonClass: If you write a class
and add SingletonClass to the list of bases, then your class will have a
unique instance plus fast comparison and hash. We have a similar thing
already, namely sage.categories.category_singleton.Category_singleton.

It would be natural to apply this to RationalField: There is a unique
instance, namely QQ. In fact, using #15247, I get a considerable speed-up
of common operations such as "RationalField()" (this used to be
particularly slow, since it used to call RationalField.__init__ *again* on the
unique instance QQ, which is of course bad!), "hash(QQ)" and "QQ==ZZ".

Problem: It breaks the pickle jar, and I don't understand why this is
happening. Namely, in vanilla sage-5.12, QQ.__reduce__() returns
(RationalField,()), which is all that is needed to correctly unpickle
QQ. In fact I tested that a pickle of QQ or 1/2 created with  vanilla
sage-5.12 can be correctly unpickled after applying the branch from #15247.

However, sage.structure.sage_object.unpickle_all() fails. It seems that
some old pickles do not store QQ via (RationalField,()), but somehow
result in calling RationalField.__new__(RationalField).
This used to work, since RationalField had a custom __new__ method that
was responsible for the unique instance behaviour in the past.

So, can you please explain to me what I can do here? Is there a way to
use unpickle_override to replace the call to
RationalField.__new__(RationalField) by
RationalField.__classcall__(RationalField)? Do you have a different idea
to solve the problem?

Best regards,
Simon


-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to