[sage-combinat-devel] Re: __classcall_private__ in partitions
Hey Simon, Because the ABC Partitions has a __classcall_private__() which returns the correct parent and is acting as a factory. This is applied to all of its subclasses which doesn't make sense there and caused exceptions to be raised (at least, that's what I remember, it's been awhile since I did that). I may be superflous for Partitions_all... Best, Travis On Monday, March 4, 2013 12:34:41 PM UTC-5, Simon King wrote: Hi! In sage.combinat.partition (at least after 13605), there are several __classcall_private__ methods of the following stile: class Partitions_all(Partitions): @staticmethod def __classcall_private__(cls): return super(Partitions_all, cls).__classcall__(cls) Isn't such a __classcall_private__ method totally useless? Namely, a __classcall_private__ method is only called on those classes that have it in their dictionary---in particular, the private classcall will *not* be called on sub-classes. In other words, the fact that Partitions does some preprocessing in a __classcall_private__ method does absolutely not matter for Partitions_all. Or what was the rationale for introducing these and other __classcall_private__ methods that just call __classcall__ (which would be called anyway)? Best regards, Simon -- You received this message because you are subscribed to the Google Groups sage-combinat-devel group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-combinat-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-combinat-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sage-combinat-devel] Re: __classcall_private__ in partitions
Hi Travis, On 2013-03-04, Travis Scrimshaw tsc...@ucdavis.edu wrote: Because the ABC Partitions has a __classcall_private__() which returns the correct parent and is acting as a factory. This is applied to all of its subclasses No, certainly not. From the docs of sage.misc.classcall_metaclass: Another difference is that ``__classcall__`` is inherited by subclasses, which may be desirable, or not. If not, one should instead define the method ``__classcall_private__`` which will not be called for subclasses. Specifically, if a class ``cls`` defines both methods ``__classcall__`` and ``__classcall_private__`` then, for any subclass ``sub`` of ``cls``: - ``cls(args)`` will call ``cls.__classcall_private__(cls, args)`` - ``sub(args)`` will call ``cls.__classcall__(sub, args)`` I did not run the whole doc tests. But it is enough to keep the following __classcall_private__ methods in order to make the tests of sage.combinat.partition pass. These are: - Partition, which really does a lot of work - Partitions, which does even more work - Partitions_parts_in, Partitions_starting, Partitions_ending - OrderedPartitions, which has a default argument. There were 6 other __classcall_private__ methods, some of them sanitising input such as putting Integer(k) around an argument k, but I really don't see why this should be done, rather than using the correct argument type right away. Best regards, Simon -- You received this message because you are subscribed to the Google Groups sage-combinat-devel group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-combinat-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-combinat-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sage-combinat-devel] Re: __classcall_private__ in partitions
Hey Simon, No, certainly not. From the docs of sage.misc.classcall_metaclass: Another difference is that ``__classcall__`` is inherited by subclasses, which may be desirable, or not. If not, one should instead define the method ``__classcall_private__`` which will not be called for subclasses. Specifically, if a class ``cls`` defines both methods ``__classcall__`` and ``__classcall_private__`` then, for any subclass ``sub`` of ``cls``: - ``cls(args)`` will call ``cls.__classcall_private__(cls, args)`` - ``sub(args)`` will call ``cls.__classcall__(sub, args)`` I most likely messed something up when I was doing this the first time through...I had a pickling issue come up with number of arguments with the classcalls vs. __init__, but I think I solved that differently... I did not run the whole doc tests. But it is enough to keep the following __classcall_private__ methods in order to make the tests of sage.combinat.partition pass. These are: - Partition, which really does a lot of work - Partitions, which does even more work - Partitions_parts_in, Partitions_starting, Partitions_ending - OrderedPartitions, which has a default argument. There were 6 other __classcall_private__ methods, some of them sanitising input such as putting Integer(k) around an argument k, but I really don't see why this should be done, rather than using the correct argument type right away. I was worried something like Partitions(3) would not be the same as Partitions(int(3)), but I've done some testing recently and realized that this didn't seem to be a problem. Could you send me the patch with your changes (since trac is currently down, we can't create the followup ticket)? Thanks, Travis -- You received this message because you are subscribed to the Google Groups sage-combinat-devel group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-combinat-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-combinat-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sage-combinat-devel] Re: __classcall_private__ in partitions
Hi Travis, On 2013-03-04, Travis Scrimshaw tsc...@ucdavis.edu wrote: I most likely messed something up when I was doing this the first time through...I had a pickling issue come up with number of arguments with the classcalls vs. __init__, but I think I solved that differently... Number of arguments (in particular: default arguments!) is indeed something that can be taken care of by a __classcall_private__ or a __classcall__ (depending on the situation). Note that one of my current projects is to automatically take care of default arguments, so that class Bla(UniqueRepresentation): def __init__(self, a=3): do some init would automaticalls yield sage: Bla() is Bla(3) is Bla(a=3) (currently, this would require adding a classcall_private) I was worried something like Partitions(3) would not be the same as Partitions(int(3)), No. The (weak) cache used in UniqueRepresentation uses a Python WeakValueDictionary. In particular, the keys are compared by equality. Hence, sage: 3.0==3==int(3)==long(3)==NN(3) True these different versions of 3 would give *identical* output. Could you send me the patch with your changes (since trac is currently down, we can't create the followup ticket)? I am confident the server will soon enough be up. If it isn't by tomorrow, I'll send you the patch. Cheers, Simon -- You received this message because you are subscribed to the Google Groups sage-combinat-devel group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-combinat-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-combinat-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sage-combinat-devel] Re: __classcall_private__ in partitions
Hi! On 2013-03-04, Simon King simon.k...@uni-jena.de wrote: Could you send me the patch with your changes (since trac is currently down, we can't create the followup ticket)? I am confident the server will soon enough be up. If it isn't by tomorrow, I'll send you the patch. See #14225. Cheers, Simon -- You received this message because you are subscribed to the Google Groups sage-combinat-devel group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-combinat-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-combinat-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en. For more options, visit https://groups.google.com/groups/opt_out.