Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

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 Matthias Koeppe committed Dec 18, 2022
1 parent 2a352f3 commit 406e6f8
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 @@ -5815,26 +5815,7 @@ def __classcall_private__(cls, n=None, **kwargs):
# n is prone to being a LazyImport shim, so we have to unpack in that case
if type(n) is LazyImport:
n = n._get_object()
if n is None or n is NonNegativeIntegerSemiring() 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 @@ -5888,6 +5869,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 NonNegativeIntegerSemiring() 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 406e6f8

Please sign in to comment.