Skip to content

Commit fc3fd28

Browse files
committed
-
1 parent 9887bca commit fc3fd28

File tree

4 files changed

+51
-48
lines changed

4 files changed

+51
-48
lines changed

source_py3/python_toolbox/combi/perming/_variation_adding_mixin.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def get_rapplied(self, sequence):
1414
if len(sequence) != self.sequence_length:
1515
raise Exception
1616
return PermSpace(
17-
sequence, domain=self.domain,
17+
sequence, n_elements=self.n_elements, domain=self.domain,
1818
fixed_map={key: sequence[value] for key, value in
1919
self.fixed_map.items()},
2020
degrees=self.degrees, slice_=self.canonical_slice,
21-
n_elements=self.n_elements, is_combination=self.is_combination,
21+
is_combination=self.is_combination,
2222
perm_type=self.perm_type
2323
)
2424

@@ -35,9 +35,9 @@ def get_partialled(self, n_elements):
3535
"first."
3636
)
3737
return PermSpace(
38-
self.sequence, domain=self.domain, fixed_map=self.fixed_map,
39-
degrees=self.degrees, slice_=None,
40-
is_combination=self.is_combination, n_elements=n_elements,
38+
self.sequence, n_elements=n_elements, domain=self.domain,
39+
fixed_map=self.fixed_map, degrees=self.degrees, slice_=None,
40+
is_combination=self.is_combination,
4141
perm_type=self.perm_type
4242
)
4343

@@ -60,7 +60,7 @@ def combinationed(self):
6060
raise TypeError("Can't use degrees with combination spaces.")
6161

6262
return PermSpace(
63-
self.sequence, domain=self.domain, n_elements=self.n_elements,
63+
self.sequence, n_elements=self.n_elements, domain=self.domain,
6464
fixed_map=self.fixed_map, is_combination=True,
6565
perm_type=Comb
6666
)
@@ -75,11 +75,11 @@ def get_dapplied(self, domain):
7575
if len(domain) != self.n_elements:
7676
raise Exception
7777
return PermSpace(
78-
self.sequence, domain,
78+
self.sequence, n_elements=self.n_elements, domain=domain,
7979
fixed_map={domain[key]: value for key, value in
8080
self._undapplied_fixed_map},
8181
degrees=self.degrees, slice_=self.canonical_slice,
82-
n_elements=self.n_elements, is_combination=self.is_combination,
82+
is_combination=self.is_combination,
8383
perm_type=self.perm_type
8484
)
8585

@@ -95,10 +95,9 @@ def get_fixed(self, fixed_map):
9595
combined_fixed_map[key] = value
9696

9797
return PermSpace(
98-
self.sequence, domain=self.domain, fixed_map=combined_fixed_map,
99-
degrees=self.degrees, slice_=None,
100-
n_elements=self.n_elements, is_combination=self.is_combination,
101-
perm_type=self.perm_type
98+
self.sequence, n_elements=self.n_elements, domain=self.domain,
99+
fixed_map=combined_fixed_map, degrees=self.degrees, slice_=None,
100+
is_combination=self.is_combination, perm_type=self.perm_type
102101
)
103102

104103
def get_degreed(self, degrees):
@@ -114,10 +113,9 @@ def get_degreed(self, degrees):
114113
degrees_to_use = \
115114
degrees if not self.is_degreed else set(degrees) & set(self.degrees)
116115
return PermSpace(
117-
self.sequence, domain=self.domain, fixed_map=self.fixed_map,
118-
degrees=degrees_to_use, n_elements=self.n_elements,
119-
is_combination=self.is_combination,
120-
perm_type=self.perm_type
116+
self.sequence, n_elements=self.n_elements, domain=self.domain,
117+
fixed_map=self.fixed_map, degrees=degrees_to_use,
118+
is_combination=self.is_combination, perm_type=self.perm_type
121119
)
122120

123121

@@ -132,10 +130,9 @@ def get_processed(self, perm_type):
132130
perm_type = lambda perm: added_perm_type(
133131
old_perm_type(perm))
134132
return PermSpace(
135-
self.sequence, domain=self.domain,
136-
fixed_map=self.fixed_map,
137-
degrees=self.degrees, slice_=self.canonical_slice,
138-
n_elements=self.n_elements, is_combination=self.is_combination,
133+
self.sequence, n_elements=self.n_elements, domain=self.domain,
134+
fixed_map=self.fixed_map, degrees=self.degrees,
135+
slice_=self.canonical_slice, is_combination=self.is_combination,
139136
perm_type=perm_type
140137
)
141138

source_py3/python_toolbox/combi/perming/_variation_removing_mixin.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ def unrapplied(self):
2727
"first."
2828
)
2929
return PermSpace(
30-
self.sequence_length, domain=self.domain,
30+
self.sequence_length, n_elements=self.n_elements,
31+
domain=self.domain,
3132
fixed_map={key: self.sequence.index(value) for
3233
key, value in self.fixed_map.items()},
33-
degrees=self.degrees, n_elements=self.n_elements,
34-
slice_=self.canonical_slice, is_combination=self.is_combination,
35-
perm_type=self.perm_type
34+
degrees=self.degrees, slice_=self.canonical_slice,
35+
is_combination=self.is_combination, perm_type=self.perm_type
3636
)
3737

3838
@caching.CachedProperty
@@ -64,9 +64,9 @@ def unrecurrented(self):
6464

6565

6666
return PermSpace(
67-
enumerate(self.sequence), domain=self.domain,
68-
fixed_map=processed_fixed_map, degrees=self.degrees,
69-
n_elements=self.n_elements, is_combination=self.is_combination,
67+
enumerate(self.sequence), n_elements=self.n_elements,
68+
domain=self.domain, fixed_map=processed_fixed_map,
69+
degrees=self.degrees, is_combination=self.is_combination,
7070
perm_type=UnrecurrentedComb if self.is_combination
7171
else UnrecurrentedPerm
7272
)
@@ -113,17 +113,16 @@ def uncombinationed(self):
113113
"subclass of `Comb`."
114114
)
115115
return PermSpace(
116-
self.sequence, domain=self.domain, fixed_map=self.fixed_map,
117-
degrees=self.degrees, slice_=None,
118-
n_elements=self.n_elements, is_combination=False,
119-
perm_type=Perm
116+
self.sequence, n_elements=self.n_elements, domain=self.domain,
117+
fixed_map=self.fixed_map, degrees=self.degrees, slice_=None,
118+
is_combination=False, perm_type=Perm
120119
)
121120

122121
undapplied = caching.CachedProperty(
123122
lambda self: PermSpace(
124-
self.sequence, fixed_map=self._undapplied_fixed_map,
125-
degrees=self.degrees, slice_=self.canonical_slice,
126-
n_elements=self.n_elements, is_combination=self.is_combination,
123+
self.sequence, n_elements=self.n_elements,
124+
fixed_map=self._undapplied_fixed_map, degrees=self.degrees,
125+
slice_=self.canonical_slice, is_combination=self.is_combination,
127126
perm_type=self.perm_type
128127
),
129128
doc='''A version of this `PermSpace` without a custom domain.'''
@@ -136,10 +135,9 @@ def unfixed(self):
136135
raise TypeError("Can't be used on sliced perm spaces. Try "
137136
"`perm_space.unsliced.unfixed`.")
138137
return PermSpace(
139-
self.sequence, domain=self.domain, fixed_map=None,
140-
degrees=self.degrees, n_elements=self.n_elements,
141-
is_combination=self.is_combination,
142-
perm_type=self.perm_type
138+
self.sequence, n_elements=self.n_elements,
139+
domain=self.domain, fixed_map=None, degrees=self.degrees,
140+
is_combination=self.is_combination, perm_type=self.perm_type
143141
)
144142

145143
@caching.CachedProperty
@@ -149,18 +147,16 @@ def undegreed(self):
149147
raise TypeError("Can't be used on sliced perm spaces. Try "
150148
"`perm_space.unsliced.undegreed`.")
151149
return PermSpace(
152-
self.sequence, domain=self.domain, fixed_map=self.fixed_map,
153-
degrees=None, n_elements=self.n_elements,
154-
is_combination=self.is_combination,
155-
perm_type=self.perm_type
150+
self.sequence, n_elements=self.n_elements, domain=self.domain,
151+
fixed_map=self.fixed_map, degrees=None,
152+
is_combination=self.is_combination, perm_type=self.perm_type
156153
)
157154

158155
unsliced = caching.CachedProperty(
159156
lambda self: PermSpace(
160-
self.sequence, domain=self.domain, fixed_map=self.fixed_map,
161-
n_elements=self.n_elements, is_combination=self.is_combination,
162-
degrees=self.degrees, slice_=None,
163-
perm_type=self.perm_type
157+
self.sequence, n_elements=self.n_elements, domain=self.domain,
158+
fixed_map=self.fixed_map, is_combination=self.is_combination,
159+
degrees=self.degrees, slice_=None, perm_type=self.perm_type
164160
),
165161
doc='''An unsliced version of this `PermSpace`.'''
166162
)

source_py3/python_toolbox/combi/perming/perm_space.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def coerce(cls, argument):
128128
else:
129129
return cls(argument)
130130

131-
def __init__(self, iterable_or_length, domain=None, *, n_elements=None,
131+
def __init__(self, iterable_or_length, n_elements=None, *, domain=None,
132132
fixed_map=None, degrees=None, is_combination=False,
133133
slice_=None, perm_type=None):
134134

@@ -478,14 +478,19 @@ def __repr__(self):
478478
sequence_repr = \
479479
''.join((sequence_repr[:35], ' ... ', sequence_repr[-1]))
480480

481+
fixed_map_repr = repr(self.fixed_map)
482+
if len(fixed_map_repr) > 40:
483+
fixed_map_repr = ''.join(
484+
(fixed_map_repr[:35], ' ... ', fixed_map_repr[-1]))
485+
481486
return '<%s: %s%s%s%s%s%s%s>%s' % (
482487
type(self).__name__,
483488
domain_snippet,
484489
sequence_repr,
485490
(', n_elements=%s' % (self.n_elements,)) if self.is_partial
486491
else '',
487492
', is_combination=True' if self.is_combination else '',
488-
(', fixed_map=%s' % (self.fixed_map,)) if self.is_fixed else '',
493+
(', fixed_map=%s' % (fixed_map_repr,)) if self.is_fixed else '',
489494
(', degrees=%s' % (self.degrees,)) if self.is_degreed else '',
490495
(', perm_type=%s' % (self.perm_type.__name__,)) if self.is_typed
491496
else '',

source_py3/test_python_toolbox/test_combi/test_perm_space.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ def test_fixed_perm_space():
212212

213213
assert big_fixed_perm_space.index(small_fixed_perm_space[1]) != 1
214214

215+
weird_fixed_perm_space = PermSpace(range(100),
216+
fixed_map=zip(range(90), range(90)))
217+
assert weird_fixed_perm_space.length == math_tools.factorial(10)
218+
assert len(repr(weird_fixed_perm_space)) <= 100
219+
215220

216221
def test_rapplied_perm_space():
217222
rapplied_perm_space = PermSpace('meow')

0 commit comments

Comments
 (0)