Ticket #14225: trac_14225-partition_classcall_private.patch

File trac_14225-partition_classcall_private.patch, 9.6 KB (added by SimonKing, 10 years ago)
  • sage/combinat/partition.py

    # HG changeset patch
    # User Simon King <simon.king@uni-jena.de>
    # Date 1362492914 -3600
    # Node ID f9e2712e64f38b11f4683848b72b26ef934c2092
    # Parent  c1bffa4c1536d5c32c83a12237c2a3ec5c86069d
    #14225: Remove redundant __classcall_private__ from partitions
    
    diff --git a/sage/combinat/partition.py b/sage/combinat/partition.py
    a b  
    302302from sage.combinat.integer_vector import IntegerVectors
    303303from sage.combinat.cartesian_product import CartesianProduct
    304304from sage.combinat.integer_list import IntegerListsLex
     305from sage.combinat.root_system.weyl_group import WeylGroup
    305306
    306307from sage.groups.perm_gps.permgroup import PermutationGroup
    307308
     
    412413    """
    413414    from sage.misc.superseded import deprecation
    414415    deprecation(13605, 'from_frobenius_coordinates is deprecated. Use Partitions().from_frobenius_coordinates instead.')
    415     return Partitions().from_frobenius_coordinates(coords)
     416    return _Partitions.from_frobenius_coordinates(coords)
    416417
    417418def from_beta_numbers(beta):
    418419    """
     
    428429    """
    429430    from sage.misc.superseded import deprecation
    430431    deprecation(13605, 'from_beta_numbers is deprecated. Use Partitions().from_beta_numbers instead.')
    431     return Partitions().from_beta_numbers(beta)
     432    return _Partitions.from_beta_numbers(beta)
    432433
    433434def from_exp(exp):
    434435    """
     
    444445    """
    445446    from sage.misc.superseded import deprecation
    446447    deprecation(13605, 'from_exp is deprecated. Use Partitions().from_exp instead.')
    447     return Partitions().from_exp(exp)
     448    return _Partitions.from_exp(exp)
    448449
    449450def from_core_and_quotient(core, quotient):
    450451    """
     
    460461    """
    461462    from sage.misc.superseded import deprecation
    462463    deprecation(13605, 'from_core_and_quotient is deprecated. Use Partitions().from_core_and_quotient instead.')
    463     return Partitions().from_core_and_quotient(core, quotient)
     464    return _Partitions.from_core_and_quotient(core, quotient)
    464465
    465466class Partition(CombinatorialObject, Element):
    466467    r"""
     
    609610            sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]])
    610611            [11, 5, 5, 3, 2, 2, 2]
    611612        """
    612         if mu is not None and len(keyword) == 0:
    613             if isinstance(mu, Partition):
    614                 return mu
    615 
    616             return Partitions()(list(mu))
    617         elif 'beta_numbers' in keyword and len(keyword) == 1:
    618             return Partitions().from_beta_numbers(keyword['beta_numbers'])
    619         elif 'core' in keyword and 'quotient' in keyword and len(keyword) == 2:
    620             return Partitions().from_core_and_quotient(keyword['core'], keyword['quotient'])
    621         elif 'exp' in keyword and len(keyword) == 1:
    622             return Partitions().from_exp(keyword['exp'])
    623         elif 'frobenius_coordinates' in keyword and len(keyword) == 1:
    624             return Partitions().from_frobenius_coordinates(keyword['frobenius_coordinates'])
    625         elif 'zero_one' in keyword and len(keyword) == 1:
    626             return Partitions().from_zero_one(keyword['zero_one'])
    627         else:
    628             raise ValueError('incorrect syntax for Partition()')
     613        l = len(keyword)
     614        if l == 0:
     615            if mu is not None:
     616                if isinstance(mu, Partition):
     617                    return mu
     618                return _Partitions(list(mu))
     619        if l == 1:
     620            if 'beta_numbers' in keyword:
     621                return _Partitions.from_beta_numbers(keyword['beta_numbers'])
     622            elif 'exp' in keyword:
     623                return _Partitions.from_exp(keyword['exp'])
     624            elif 'frobenius_coordinates' in keyword:
     625                return _Partitions.from_frobenius_coordinates(keyword['frobenius_coordinates'])
     626            elif 'zero_one' in keyword:
     627                return _Partitions.from_zero_one(keyword['zero_one'])
     628
     629        if l == 2 and 'core' in keyword and 'quotient' in keyword:
     630            return _Partitions.from_core_and_quotient(keyword['core'], keyword['quotient'])
     631        raise ValueError('incorrect syntax for Partition()')
    629632
    630633    def __setstate__(self, state):
    631634        """
     
    641644            [3, 2, 1]
    642645        """
    643646        if isinstance(state, dict):   # for old pickles from Partition_class
    644             self._set_parent(Partitions())
     647            self._set_parent(_Partitions)
    645648            self.__dict__ = state
    646649        else:
    647650            self._set_parent(state[0])
     
    874877        """
    875878        return [ self ]
    876879
    877 
    878880    def young_subgroup(self):
    879881        """
    880882        Return the corresponding Young, or parabolic, subgroup of the symmetric
     
    31483150            [0 1 0]
    31493151            [0 0 1]
    31503152        """
    3151         from sage.combinat.root_system.weyl_group import WeylGroup
    3152         W=WeylGroup(['A',k,1])
    3153         return W.from_reduced_word(self.from_kbounded_to_reduced_word(k))
     3153        return WeylGroup(['A',k,1]).from_reduced_word(self.from_kbounded_to_reduced_word(k))
    31543154
    31553155    def to_list(self):
    31563156        r"""
     
    42874287        sage: TestSuite( sage.combinat.partition.Partitions_all() ).run()
    42884288    """
    42894289
    4290     @staticmethod
    4291     def __classcall_private__(cls):
    4292         """
    4293         Normalize the input to ensure a unique representation.
    4294 
    4295         TESTS::
    4296 
    4297             sage: P = Partitions()
    4298             sage: P2 = Partitions()
    4299             sage: P is P2
    4300             True
    4301         """
    4302         return super(Partitions_all, cls).__classcall__(cls)
    4303 
    43044290    def __init__(self):
    43054291        """
    43064292        Initialize ``self``.
     
    44524438
    44534439
    44544440class Partitions_all_bounded(Partitions):
    4455     @staticmethod
    4456     def __classcall_private__(cls, k):
    4457         """
    4458         Normalize the input to ensure a unique representation.
    4459 
    4460         TESTS::
    4461 
    4462             sage: P = Partitions(max_part=3)
    4463             sage: P2 = Partitions(max_part=3)
    4464             sage: P is P2
    4465             True
    4466         """
    4467         return super(Partitions_all_bounded, cls).__classcall__(cls, Integer(k))
    44684441
    44694442    def __init__(self, k):
    44704443        """
     
    44994472            False
    45004473        """
    45014474        try:
    4502             return Partitions()(x).get_part(0) <= self.k
     4475            return _Partitions(x).get_part(0) <= self.k
    45034476        except (ValueError, TypeError):
    45044477            return False
    45054478
     
    45414514        sage: TestSuite( sage.combinat.partition.Partitions_n(0) ).run()
    45424515    """
    45434516
    4544     @staticmethod
    4545     def __classcall_private__(cls, n):
    4546         """
    4547         Normalize the input to ensure a unique representation.
    4548 
    4549          TESTS::
    4550 
    4551             sage: P = Partitions(4)
    4552             sage: P2 = Partitions(4)
    4553             sage: P is P2
    4554             True
    4555         """
    4556         return super(Partitions_n, cls).__classcall__(cls, Integer(n))
    4557 
    45584517    def __init__(self, n):
    45594518        """
    45604519        Initialze ``self``.
     
    45804539            sage: [3,2] in p
    45814540            True
    45824541        """
    4583         return x in Partitions() and sum(x) == self.n
     4542        return x in _Partitions and sum(x) == self.n
    45844543
    45854544    def _repr_(self):
    45864545        """
     
    49694928            sage: [4,1] in p
    49704929            False
    49714930        """
    4972         return (x in Partitions() and sum(x) == self.n and
     4931        return (x in _Partitions and sum(x) == self.n and
    49734932                all(p in self.parts for p in x))
    49744933
    49754934    def _repr_(self):
     
    54065365        sage: PartitionsInBox(2,2).list()
    54075366        [[], [1], [1, 1], [2], [2, 1], [2, 2]]
    54085367    """
    5409 
    5410     @staticmethod
    5411     def __classcall_private__(cls, h, w):
    5412         """
    5413         Normalize the input to ensure a unique representation.
    5414    
    5415         TESTS::
    5416 
    5417             sage: P = PartitionsInBox(2,2)
    5418             sage: P2 = PartitionsInBox(2,2)
    5419             sage: P is P2
    5420             True
    5421         """
    5422         return super(PartitionsInBox, cls).__classcall__(cls, Integer(h), Integer(w))
    54235368   
    54245369    def __init__(self, h, w):
    54255370        """
     
    54605405            sage: [2,1,1] in PartitionsInBox(2,2)
    54615406            False
    54625407        """
    5463         return x in Partitions() and len(x) <= self.h \
     5408        return x in _Partitions and len(x) <= self.h \
    54645409               and (len(x) == 0 or x[0] <= self.w)
    54655410
    54665411    def list(self):
     
    57135658        Partitions...
    57145659    """
    57155660
    5716     @staticmethod
    5717     def __classcall_private__(cls, n, k):
    5718         """
    5719         Normalize the input to ensure a unique representation.
    5720    
    5721         TESTS::
    5722 
    5723             sage: P = PartitionsGreatestLE(4,2)
    5724             sage: P2 = PartitionsGreatestLE(4,2)
    5725             sage: P is P2
    5726             True
    5727         """
    5728         return super(PartitionsGreatestLE, cls).__classcall__(cls, Integer(n), Integer(k))
    5729 
    57305661    def __init__(self, n, k):
    57315662        """
    57325663        Initialize ``self``.
     
    58025733        Partitions...
    58035734    """
    58045735
    5805     @staticmethod
    5806     def __classcall_private__(cls, n, k):
    5807         """
    5808         Normalize the input to ensure a unique representation.
    5809 
    5810         TESTS::
    5811 
    5812             sage: P = PartitionsGreatestEQ(4,2)
    5813             sage: P2 = PartitionsGreatestEQ(4,2)
    5814             sage: P is P2
    5815             True
    5816         """
    5817         return super(PartitionsGreatestEQ, cls).__classcall__(cls, Integer(n), Integer(k))
    5818 
    58195736    def __init__(self, n, k):
    58205737        """
    58215738        Initialize ``self``.
     
    62776194
    62786195    raise ValueError("unknown algorithm '%s'"%algorithm)
    62796196
     6197##########
     6198# trac 14225: Partitions() is frequently used, but only weakly cached. Hence,
     6199# establish a strong reference to it.
     6200
     6201_Partitions = Partitions()
     6202
     6203
    62806204# This function was previously used to cache number_of_partitions with the
    62816205# justification that "Some function e.g.: Partitions(n).random() heavily use
    62826206# number_of_partitions", however, the random() method of Partitions() seems to be