From 6af38012df67a9d8327593d4c8f8a1b5649d59c7 Mon Sep 17 00:00:00 2001 From: Frederick Robinson Date: Sun, 1 Sep 2024 09:23:55 -0700 Subject: [PATCH] remove fallback implemenations of combination/permutation functions (#771) --- pulp/utilities.py | 52 +++-------------------------------------------- 1 file changed, 3 insertions(+), 49 deletions(-) diff --git a/pulp/utilities.py b/pulp/utilities.py index cbb73ee6..a792cf47 100644 --- a/pulp/utilities.py +++ b/pulp/utilities.py @@ -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(): @@ -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