Skip to content

Commit

Permalink
Change order of cases in Partitions to put cheaper tests first
Browse files Browse the repository at this point in the history
  • Loading branch information
nbruin authored and mkoeppe committed Dec 18, 2022
1 parent 05ea54e commit 9837dec
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/sage/combinat/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -5812,26 +5812,7 @@ def __classcall_private__(cls, n=None, **kwargs):
"""
if n == infinity:
raise ValueError("n cannot be infinite")
if n is None or n is NN or n is NonNegativeIntegers():
if len(kwargs) > 0:
if len(kwargs) == 1:
if 'max_part' in kwargs:
return Partitions_all_bounded(kwargs['max_part'])
if 'regular' in kwargs:
return RegularPartitions_all(kwargs['regular'])
if 'restricted' in kwargs:
return RestrictedPartitions_all(kwargs['restricted'])
elif len(kwargs) == 2:
if 'regular' in kwargs:
if kwargs['regular'] < 1 or kwargs['regular'] not in ZZ:
raise ValueError("the regularity must be a positive integer")
if 'max_part' in kwargs:
return RegularPartitions_bounded(kwargs['regular'], kwargs['max_part'])
if 'max_length' in kwargs:
return RegularPartitions_truncated(kwargs['regular'], kwargs['max_length'])
raise ValueError("the size must be specified with any keyword argument")
return Partitions_all()
elif isinstance(n, (int,Integer)):
if isinstance(n, (int,Integer)):
if len(kwargs) == 0:
return Partitions_n(n)

Expand Down Expand Up @@ -5885,6 +5866,25 @@ def __classcall_private__(cls, n=None, **kwargs):
kwargs.get('min_length',0))
del kwargs['inner']
return Partitions_with_constraints(n, **kwargs)
elif n is None or n is NN or n is NonNegativeIntegers():
if len(kwargs) > 0:
if len(kwargs) == 1:
if 'max_part' in kwargs:
return Partitions_all_bounded(kwargs['max_part'])
if 'regular' in kwargs:
return RegularPartitions_all(kwargs['regular'])
if 'restricted' in kwargs:
return RestrictedPartitions_all(kwargs['restricted'])
elif len(kwargs) == 2:
if 'regular' in kwargs:
if kwargs['regular'] < 1 or kwargs['regular'] not in ZZ:
raise ValueError("the regularity must be a positive integer")
if 'max_part' in kwargs:
return RegularPartitions_bounded(kwargs['regular'], kwargs['max_part'])
if 'max_length' in kwargs:
return RegularPartitions_truncated(kwargs['regular'], kwargs['max_length'])
raise ValueError("the size must be specified with any keyword argument")
return Partitions_all()

raise ValueError("n must be an integer or be equal to one of "
"None, NN, NonNegativeIntegers()")
Expand Down

0 comments on commit 9837dec

Please sign in to comment.