Skip to content

Commit 4bca48d

Browse files
committed
-
1 parent a3e2688 commit 4bca48d

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

source_py3/python_toolbox/combi/_variation_removing_mixin.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from python_toolbox import caching
22

3+
from . import misc
4+
35
# (`PermSpace` exported to here from `perm_space.py` to avoid import loop.)
46

57

@@ -27,12 +29,35 @@ def unrapplied(self):
2729
self.sequence_length, domain=self.domain,
2830
fixed_map={key: self.sequence.index(value) for
2931
key, value in self.fixed_map.items()},
30-
degrees=self.degrees, slice_=self.canonical_slice,
31-
n_elements=self.n_elements, is_combination=self.is_combination
32+
degrees=self.degrees, n_elements=self.n_elements,
33+
is_combination=self.is_combination
3234
)
3335

34-
# There's no `.unrecurrented`; if you want to make a perm space
35-
# non-recurrented, use `.unrapplied`.
36+
@caching.CachedProperty
37+
def unrecurrented(self):
38+
'''A version of this `PermSpace` with no recurrences.'''
39+
assert self.is_recurrent # Otherwise was overridden in `__init__`
40+
if self.is_sliced:
41+
raise Exception(
42+
"You can't get an unrecurrented version of a sliced "
43+
"`PermSpace` because after unrecurrenting it, it'll have a "
44+
"different number of elements, and thus the slice wouldn't be "
45+
"usable. Please use `.unsliced` first."
46+
)
47+
48+
sequence_copy = list(self.sequence)
49+
processed_fixed_map = {}
50+
for key, value in self.fixed_map:
51+
index = sequence_copy.index(value)
52+
sequence_copy[value] = misc.MISSING_ELEMENT
53+
processed_fixed_map[key] = (index, value)
54+
55+
return PermSpace(
56+
enumerate(self.sequence), domain=self.domain,
57+
fixed_map=processed_fixed_map, degrees=self.degrees,
58+
n_elements=self.n_elements, is_combination=self.is_combination
59+
)
60+
3661

3762
@caching.CachedProperty
3863
def unpartialled(self):

source_py3/python_toolbox/combi/misc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
infinity = float('inf')
1616

17-
17+
18+
class MISSING_ELEMENT:
19+
'''blocktotodoc'''
1820

1921

2022
def get_short_factorial_string(number, minus_one=False):

source_py3/python_toolbox/combi/perm.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323

2424
infinity = float('inf')
2525

26-
class MISSING_ELEMENT:
27-
'''blocktotodoc'''
28-
2926

3027
class _BasePermView:
3128
def __init__(self, perm):
@@ -264,7 +261,7 @@ def unrapplied(self):
264261
new_perm_sequence = []
265262
for i in self:
266263
i_index = rapplied_sequence.index(i)
267-
rapplied_sequence[i_index] = MISSING_ELEMENT
264+
rapplied_sequence[i_index] = misc.MISSING_ELEMENT
268265
new_perm_sequence.append(i_index)
269266
# #
270267
### Finished calculating the new perm sequence. #######################

0 commit comments

Comments
 (0)