Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove fallback implemenations of combination/permutation functions #771

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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