Ticket #14225: trac_14225-partition_classcall_private.patch
File trac_14225-partition_classcall_private.patch, 9.6 KB (added by , 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 302 302 from sage.combinat.integer_vector import IntegerVectors 303 303 from sage.combinat.cartesian_product import CartesianProduct 304 304 from sage.combinat.integer_list import IntegerListsLex 305 from sage.combinat.root_system.weyl_group import WeylGroup 305 306 306 307 from sage.groups.perm_gps.permgroup import PermutationGroup 307 308 … … 412 413 """ 413 414 from sage.misc.superseded import deprecation 414 415 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) 416 417 417 418 def from_beta_numbers(beta): 418 419 """ … … 428 429 """ 429 430 from sage.misc.superseded import deprecation 430 431 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) 432 433 433 434 def from_exp(exp): 434 435 """ … … 444 445 """ 445 446 from sage.misc.superseded import deprecation 446 447 deprecation(13605, 'from_exp is deprecated. Use Partitions().from_exp instead.') 447 return Partitions().from_exp(exp)448 return _Partitions.from_exp(exp) 448 449 449 450 def from_core_and_quotient(core, quotient): 450 451 """ … … 460 461 """ 461 462 from sage.misc.superseded import deprecation 462 463 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) 464 465 465 466 class Partition(CombinatorialObject, Element): 466 467 r""" … … 609 610 sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]]) 610 611 [11, 5, 5, 3, 2, 2, 2] 611 612 """ 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()') 629 632 630 633 def __setstate__(self, state): 631 634 """ … … 641 644 [3, 2, 1] 642 645 """ 643 646 if isinstance(state, dict): # for old pickles from Partition_class 644 self._set_parent( Partitions())647 self._set_parent(_Partitions) 645 648 self.__dict__ = state 646 649 else: 647 650 self._set_parent(state[0]) … … 874 877 """ 875 878 return [ self ] 876 879 877 878 880 def young_subgroup(self): 879 881 """ 880 882 Return the corresponding Young, or parabolic, subgroup of the symmetric … … 3148 3150 [0 1 0] 3149 3151 [0 0 1] 3150 3152 """ 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)) 3154 3154 3155 3155 def to_list(self): 3156 3156 r""" … … 4287 4287 sage: TestSuite( sage.combinat.partition.Partitions_all() ).run() 4288 4288 """ 4289 4289 4290 @staticmethod4291 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 P24300 True4301 """4302 return super(Partitions_all, cls).__classcall__(cls)4303 4304 4290 def __init__(self): 4305 4291 """ 4306 4292 Initialize ``self``. … … 4452 4438 4453 4439 4454 4440 class Partitions_all_bounded(Partitions): 4455 @staticmethod4456 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 P24465 True4466 """4467 return super(Partitions_all_bounded, cls).__classcall__(cls, Integer(k))4468 4441 4469 4442 def __init__(self, k): 4470 4443 """ … … 4499 4472 False 4500 4473 """ 4501 4474 try: 4502 return Partitions()(x).get_part(0) <= self.k4475 return _Partitions(x).get_part(0) <= self.k 4503 4476 except (ValueError, TypeError): 4504 4477 return False 4505 4478 … … 4541 4514 sage: TestSuite( sage.combinat.partition.Partitions_n(0) ).run() 4542 4515 """ 4543 4516 4544 @staticmethod4545 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 P24554 True4555 """4556 return super(Partitions_n, cls).__classcall__(cls, Integer(n))4557 4558 4517 def __init__(self, n): 4559 4518 """ 4560 4519 Initialze ``self``. … … 4580 4539 sage: [3,2] in p 4581 4540 True 4582 4541 """ 4583 return x in Partitions()and sum(x) == self.n4542 return x in _Partitions and sum(x) == self.n 4584 4543 4585 4544 def _repr_(self): 4586 4545 """ … … 4969 4928 sage: [4,1] in p 4970 4929 False 4971 4930 """ 4972 return (x in Partitions()and sum(x) == self.n and4931 return (x in _Partitions and sum(x) == self.n and 4973 4932 all(p in self.parts for p in x)) 4974 4933 4975 4934 def _repr_(self): … … 5406 5365 sage: PartitionsInBox(2,2).list() 5407 5366 [[], [1], [1, 1], [2], [2, 1], [2, 2]] 5408 5367 """ 5409 5410 @staticmethod5411 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 P25420 True5421 """5422 return super(PartitionsInBox, cls).__classcall__(cls, Integer(h), Integer(w))5423 5368 5424 5369 def __init__(self, h, w): 5425 5370 """ … … 5460 5405 sage: [2,1,1] in PartitionsInBox(2,2) 5461 5406 False 5462 5407 """ 5463 return x in Partitions()and len(x) <= self.h \5408 return x in _Partitions and len(x) <= self.h \ 5464 5409 and (len(x) == 0 or x[0] <= self.w) 5465 5410 5466 5411 def list(self): … … 5713 5658 Partitions... 5714 5659 """ 5715 5660 5716 @staticmethod5717 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 P25726 True5727 """5728 return super(PartitionsGreatestLE, cls).__classcall__(cls, Integer(n), Integer(k))5729 5730 5661 def __init__(self, n, k): 5731 5662 """ 5732 5663 Initialize ``self``. … … 5802 5733 Partitions... 5803 5734 """ 5804 5735 5805 @staticmethod5806 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 P25815 True5816 """5817 return super(PartitionsGreatestEQ, cls).__classcall__(cls, Integer(n), Integer(k))5818 5819 5736 def __init__(self, n, k): 5820 5737 """ 5821 5738 Initialize ``self``. … … 6277 6194 6278 6195 raise ValueError("unknown algorithm '%s'"%algorithm) 6279 6196 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 6280 6204 # This function was previously used to cache number_of_partitions with the 6281 6205 # justification that "Some function e.g.: Partitions(n).random() heavily use 6282 6206 # number_of_partitions", however, the random() method of Partitions() seems to be