Skip to content

Commit

Permalink
remove fallback implemenations of combination/permutation functions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
frrad authored Sep 1, 2024
1 parent 2aa580c commit 6af3801
Showing 1 changed file with 3 additions and 49 deletions.
52 changes: 3 additions & 49 deletions pulp/utilities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Utility functions
import itertools
import collections
import itertools
from itertools import combinations as combination
from itertools import permutations as permutation


def resource_clock():
Expand Down Expand Up @@ -32,54 +34,6 @@ def valueOrDefault(x):
return x.valueOrDefault()


def __combination(orgset, k):
"""
fall back if probstat is not installed note it is GPL so cannot
be included
"""
if k == 1:
for i in orgset:
yield (i,)
elif k > 1:
for i, x in enumerate(orgset):
# iterates though to near the end
for s in __combination(orgset[i + 1 :], k - 1):
yield (x,) + s


try: # python >= 3.4
from itertools import combinations as combination
except ImportError:
try: # python 2.7
from itertools import combination
except ImportError: # pulp's
combination = __combination


def __permutation(orgset, k):
"""
fall back if probstat is not installed note it is GPL so cannot
be included
"""
if k == 1:
for i in orgset:
yield (i,)
elif k > 1:
for i, x in enumerate(orgset):
# iterates though to near the end
for s in __permutation(orgset[:i] + orgset[i + 1 :], k - 1):
yield (x,) + s


try: # python >= 3.4
from itertools import permutations as permutation
except ImportError:
try: # python 2.7
from itertools import permutation
except ImportError: # pulp's
permutation = __permutation


def allpermutations(orgset, k):
"""
returns all permutations of orgset with up to k items
Expand Down

0 comments on commit 6af3801

Please sign in to comment.