|
1 | 1 | from python_toolbox import caching |
2 | 2 |
|
| 3 | +from . import misc |
| 4 | + |
3 | 5 | # (`PermSpace` exported to here from `perm_space.py` to avoid import loop.) |
4 | 6 |
|
5 | 7 |
|
@@ -27,12 +29,35 @@ def unrapplied(self): |
27 | 29 | self.sequence_length, domain=self.domain, |
28 | 30 | fixed_map={key: self.sequence.index(value) for |
29 | 31 | 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 |
32 | 34 | ) |
33 | 35 |
|
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 | + |
36 | 61 |
|
37 | 62 | @caching.CachedProperty |
38 | 63 | def unpartialled(self): |
|
0 commit comments