Skip to content

Commit 0c9ab0e

Browse files
author
Release Manager
committed
gh-35917: some pep8 fixes in combinat <!-- Please provide a concise, informative and self-explanatory title. --> <!-- Don't put issue numbers in the title. Put it in the Description below. --> <!-- For example, instead of "Fixes #12345", use "Add a new method to multiply two integers" --> ### 📚 Description just fixing a few pycodestyle warnings in `combinat` folder <!-- Describe your changes here in detail. --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35917 Reported by: Frédéric Chapoton Reviewer(s): Frédéric Chapoton, Matthias Köppe
2 parents 41fa630 + 94881f8 commit 0c9ab0e

15 files changed

+222
-197
lines changed

src/sage/combinat/composition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,7 @@ def specht_module_dimension(self, base_ring=None):
14361436
from sage.combinat.specht_module import specht_module_rank
14371437
return specht_module_rank(self, base_ring)
14381438

1439+
14391440
Sequence.register(Composition)
14401441
##############################################################
14411442

src/sage/combinat/diagram.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def __init__(self, parent, cells, n_rows=None, n_cols=None, check=True):
152152
# minimum possible number of rows/cols
153153
N_rows = max(c[0] for c in self._cells)
154154
N_cols = max(c[1] for c in self._cells)
155-
else: # if there are no cells
155+
else: # if there are no cells
156156
N_rows = -1
157157
N_cols = -1
158158

@@ -344,18 +344,22 @@ def _latex_(self):
344344
def end_line(r):
345345
# give the line ending to row ``r``
346346
if r == 0:
347-
return "".join(r'\cline{%s-%s}'%(i+1, i+1) for i,j in enumerate(array[0]) if j is not None)
347+
return "".join(r'\cline{%s-%s}' % (i+1, i+1)
348+
for i, j in enumerate(array[0]) if j is not None)
348349
elif r == len(array):
349-
return r"\\" + "".join(r'\cline{%s-%s}'%(i+1, i+1) for i,j in enumerate(array[r-1]) if j is not None)
350+
return r"\\" + "".join(r'\cline{%s-%s}' % (i+1, i+1)
351+
for i, j in enumerate(array[r-1]) if j is not None)
350352
else:
351-
out = r"\\" + "".join(r'\cline{%s-%s}'%(i+1, i+1) for i,j in enumerate(array[r-1]) if j is not None)
352-
out += "".join(r'\cline{%s-%s}'%(i+1, i+1) for i,j in enumerate(array[r]) if j is not None)
353+
out = r"\\" + "".join(r'\cline{%s-%s}' % (i+1, i+1)
354+
for i, j in enumerate(array[r-1]) if j is not None)
355+
out += "".join(r'\cline{%s-%s}' % (i+1, i+1)
356+
for i, j in enumerate(array[r]) if j is not None)
353357
return out
354358

355-
tex=r'\raisebox{-.6ex}{$\begin{array}[b]{*{%s}{p{0.6ex}}}'%(max(map(len,array)))
356-
tex+=end_line(0)+'\n'
359+
tex = r'\raisebox{-.6ex}{$\begin{array}[b]{*{%s}{p{0.6ex}}}' % (max(map(len, array)))
360+
tex += end_line(0)+'\n'
357361
for r in range(len(array)):
358-
tex+='&'.join('' if c is None else r'\lr{%s}'%(c,) for c in array[r])
362+
tex += '&'.join('' if c is None else r'\lr{%s}' % (c,) for c in array[r])
359363
tex += end_line(r+1)+'\n'
360364
return '{%s\n%s\n}' % (lr, tex+r'\end{array}$}')
361365

@@ -531,6 +535,7 @@ def specht_module_dimension(self, base_ring=None):
531535
from sage.combinat.specht_module import specht_module_rank
532536
return specht_module_rank(self, base_ring)
533537

538+
534539
class Diagrams(UniqueRepresentation, Parent):
535540
r"""
536541
The class of combinatorial diagrams.
@@ -624,7 +629,7 @@ def __iter__(self):
624629
while True:
625630
cells = next(X)
626631
try:
627-
yield self.element_class(self, tuple((i, j) for i,j in cells))
632+
yield self.element_class(self, tuple((i, j) for i, j in cells))
628633
except ValueError:
629634
# if cells causes the .check method of a
630635
# subclass to fail, just go to the next one
@@ -800,9 +805,9 @@ def from_zero_one_matrix(self, M, check=True):
800805
one = M.base_ring().one()
801806
for i in range(n_rows):
802807
for j in range(n_cols):
803-
if not (M[i,j] == zero or M[i,j] == one):
804-
raise ValueError("Matrix entries must be 0 or 1")
805-
cells = [(i, j) for i in range(n_rows) for j in range(n_cols) if M[i,j]]
808+
if not (M[i, j] == zero or M[i, j] == one):
809+
raise ValueError("matrix entries must be 0 or 1")
810+
cells = [(i, j) for i in range(n_rows) for j in range(n_cols) if M[i, j]]
806811

807812
return self.element_class(self, cells, n_rows, n_cols, check=False)
808813

src/sage/combinat/fully_packed_loop.py

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@
4949
D = (0, -1)
5050

5151
FPL_edges = (
52-
# 0 UD 1 RD, 2 UR, 3 LR, 4 LD 5 LU
53-
((D,U), (L,D), (D,R), (R,L), (L,U), (R,U)), # even
54-
((R,L), (R,U), (L,U), (D,U), (D,R), (L,D)) # odd
55-
)
52+
# 0 UD 1 RD, 2 UR, 3 LR, 4 LD 5 LU
53+
((D, U), (L, D), (D, R), (R, L), (L, U), (R, U)), # even
54+
((R, L), (R, U), (L, U), (D, U), (D, R), (L, D)) # odd
55+
)
5656

5757
FPL_turns = (
58-
# 0 UD 1 RD 2 UR 3 LR 4 LD 5 LU
59-
({U: U, D: D}, {R: D, U: L}, {U: R, L: D}, {L: L, R: R}, {R: U, D: L}, {L: U, D: R}), # even
60-
({L: L, R: R}, {L: U, D: R}, {R: U, D: L}, {U: U, D: D}, {U: R, L: D}, {R: D, U: L}) # odd
61-
)
58+
# 0 UD 1 RD 2 UR 3 LR 4 LD 5 LU
59+
({U: U, D: D}, {R: D, U: L}, {U: R, L: D}, {L: L, R: R}, {R: U, D: L}, {L: U, D: R}), # even
60+
({L: L, R: R}, {L: U, D: R}, {R: U, D: L}, {U: U, D: D}, {U: R, L: D}, {R: D, U: L}) # odd
61+
)
6262

6363

64-
def _make_color_list(n, colors=None, color_map=None, randomize=False):
64+
def _make_color_list(n, colors=None, color_map=None, randomize=False):
6565
r"""
6666
TESTS::
6767
@@ -530,7 +530,7 @@ def __classcall_private__(cls, generator):
530530
M = generator.to_alternating_sign_matrix().to_matrix()
531531
AlternatingSignMatrix(M)
532532
SVM = generator
533-
else: # Not ASM nor SVM
533+
else: # Not ASM nor SVM
534534
try:
535535
SVM = AlternatingSignMatrix(generator).to_six_vertex_model()
536536
except (TypeError, ValueError):
@@ -608,22 +608,22 @@ def _repr_(self):
608608
# List are in the order of URDL
609609
# One set of rules for how to draw around even vertex, one set of rules for odd vertex
610610
n = len(self._six_vertex_model) - 1
611-
ascii1 = [[r' ', ' -', r' ', '- '], # LR
612-
[r' | ', ' ', r' ', '- '], # LU
613-
[r' ', ' ', r' | ', '- '], # LD
614-
[r' | ', ' ', r' | ', ' '], # UD
615-
[r' | ', ' -', r' ', ' '], # UR
616-
[r' ', ' -', r' | ', ' ']] # RD
617-
618-
ascii2 = [[r' | ', ' ', r' | ', ' '], # LR
619-
[r' ', ' -', r' | ', ' '], # LU
620-
[r' | ', ' -', r' ', ' '], # LD
621-
[r' ', ' -', r' ', '- '], # UD
622-
[r' ', ' ', r' | ', '- '], # UR
623-
[r' | ', ' ', r' ', '- ']] # RD
611+
ascii1 = [[r' ', ' -', r' ', '- '], # LR
612+
[r' | ', ' ', r' ', '- '], # LU
613+
[r' ', ' ', r' | ', '- '], # LD
614+
[r' | ', ' ', r' | ', ' '], # UD
615+
[r' | ', ' -', r' ', ' '], # UR
616+
[r' ', ' -', r' | ', ' ']] # RD
617+
618+
ascii2 = [[r' | ', ' ', r' | ', ' '], # LR
619+
[r' ', ' -', r' | ', ' '], # LU
620+
[r' | ', ' -', r' ', ' '], # LD
621+
[r' ', ' -', r' ', '- '], # UD
622+
[r' ', ' ', r' | ', '- '], # UR
623+
[r' | ', ' ', r' ', '- ']] # RD
624624
ret = ' '
625625
# Do the top line
626-
for i,entry in enumerate(self._six_vertex_model[0]):
626+
for i, entry in enumerate(self._six_vertex_model[0]):
627627
if i % 2 == 0:
628628
ret += ' | '
629629
else:
@@ -632,47 +632,47 @@ def _repr_(self):
632632
plus_sign = '+'
633633

634634
# Do the meat of the ascii art
635-
for j,row in enumerate(self._six_vertex_model):
635+
for j, row in enumerate(self._six_vertex_model):
636636
ret += '\n '
637637
# Do the top row
638-
for i,entry in enumerate(row):
638+
for i, entry in enumerate(row):
639639
if (i + j) % 2 == 0:
640640
ret += ascii1[entry][0]
641641
else:
642642
ret += ascii2[entry][0]
643643
ret += '\n'
644644

645645
# Do the left-most entry
646-
if (j) % 2 == 0:
646+
if j % 2 == 0:
647647
ret += ' '
648648
else:
649649
ret += ' -'
650650

651651
# Do the middle row
652-
for i,entry in enumerate(row):
652+
for i, entry in enumerate(row):
653653
if (i + j) % 2 == 0:
654654
ret += ascii1[entry][3] + plus_sign + ascii1[entry][1]
655655
else:
656656
ret += ascii2[entry][3] + plus_sign + ascii2[entry][1]
657657

658658
# Do the right-most entry
659-
if (j+n) % 2 ==0:
659+
if (j+n) % 2 == 0:
660660
ret += ' '
661661
else:
662662
ret += '- '
663663

664664
# Do the bottom row
665665
ret += '\n '
666-
for i,entry in enumerate(row):
667-
if (i + j) % 2 ==0:
666+
for i, entry in enumerate(row):
667+
if (i + j) % 2 == 0:
668668
ret += ascii1[entry][2]
669669
else:
670670
ret += ascii2[entry][2]
671671

672672
# Do the bottom line
673673
ret += '\n '
674-
for i,entry in enumerate(self._six_vertex_model[-1]):
675-
if (i+n+1) % 2 ==0:
674+
for i, entry in enumerate(self._six_vertex_model[-1]):
675+
if (i+n+1) % 2 == 0:
676676
ret += ' '
677677
else:
678678
ret += ' | '
@@ -879,7 +879,7 @@ def plot(self, **options):
879879
unrank = self.parent()._boundary
880880
seen = [False] * (2*n)
881881

882-
squares = set((i,j) for i in range(n) for j in range(n))
882+
squares = set((i, j) for i in range(n) for j in range(n))
883883

884884
colors = _make_color_list(2*n,
885885
colors=link_options.pop('colors', None),
@@ -922,7 +922,7 @@ def plot(self, **options):
922922
loop_options['color'] = colors.pop()
923923

924924
# make it upside down
925-
orbit = [(j, n - i - 1) for i,j in orbit]
925+
orbit = [(j, n - i - 1) for i, j in orbit]
926926

927927
if fill:
928928
G += polygon2d(orbit, **loop_options)
@@ -1025,13 +1025,13 @@ def _link_or_loop_from(self, pos, d0=None):
10251025
raise RuntimeError
10261026

10271027
if i == -1 or j == -1 or i == n or j == n:
1028-
i0,j0 = orbit[0]
1028+
i0, j0 = orbit[0]
10291029
if d0 is None and i0 != -1 and i0 != n and j0 != -1 and j0 != n:
10301030
# only half of a link -> compute the other half
1031-
i1,j1 = orbit[1]
1031+
i1, j1 = orbit[1]
10321032
d = (i0-i1, j0-j1)
10331033
orbit2 = self._link_or_loop_from(orbit[1], d)
1034-
assert orbit2[0] == (i1,j1) and orbit2[1] == (i0,j0)
1034+
assert orbit2[0] == (i1, j1) and orbit2[1] == (i0, j0)
10351035
return orbit2[:1:-1] + orbit
10361036
return orbit
10371037
else:
@@ -1156,7 +1156,7 @@ def link_pattern(self):
11561156
if seen[k]:
11571157
continue
11581158

1159-
i,j = unrank(k)
1159+
i, j = unrank(k)
11601160

11611161
# initial direction
11621162
if i == -1:
@@ -1180,7 +1180,7 @@ def link_pattern(self):
11801180
d = FPL_turns[parity][conf][d]
11811181

11821182
# update seen and link_pattern
1183-
l = rank((i,j))
1183+
l = rank((i, j))
11841184
seen[k] = seen[l] = True
11851185
link_pattern.append((k+1, l+1))
11861186

@@ -1294,7 +1294,7 @@ def _repr_(self):
12941294
sage: FPLs = FullyPackedLoops(4); FPLs
12951295
Fully packed loops on a 4x4 grid
12961296
"""
1297-
return "Fully packed loops on a %sx%s grid" % (self._n,self._n)
1297+
return "Fully packed loops on a %sx%s grid" % (self._n, self._n)
12981298

12991299
def __contains__(self, fpl):
13001300
"""
@@ -1368,7 +1368,7 @@ def _element_constructor_(self, generator):
13681368
if isinstance(generator, AlternatingSignMatrix):
13691369
SVM = generator.to_six_vertex_model()
13701370
elif isinstance(generator, SquareIceModel.Element) or \
1371-
isinstance(generator, SixVertexConfiguration):
1371+
isinstance(generator, SixVertexConfiguration):
13721372
SVM = generator
13731373
else: # Not ASM nor SVM
13741374
try:
@@ -1407,11 +1407,11 @@ def cardinality(self):
14071407
14081408
EXAMPLES::
14091409
1410-
sage: [AlternatingSignMatrices(n).cardinality() for n in range(11)]
1411-
[1, 1, 2, 7, 42, 429, 7436, 218348, 10850216, 911835460, 129534272700]
1410+
sage: [AlternatingSignMatrices(n).cardinality() for n in range(10)]
1411+
[1, 1, 2, 7, 42, 429, 7436, 218348, 10850216, 911835460]
14121412
"""
1413-
return Integer(prod( [ factorial(3*k+1)/factorial(self._n+k)
1414-
for k in range(self._n)] ))
1413+
return Integer(prod(factorial(3 * k + 1) / factorial(self._n + k)
1414+
for k in range(self._n)))
14151415

14161416
def _an_element_(self):
14171417
"""
@@ -1433,9 +1433,9 @@ def _an_element_(self):
14331433
| |
14341434
| |
14351435
"""
1436-
#ASM = AlternatingSignMatrix(matrix.identity(self._n))
1437-
#SVM = ASM.to_six_vertex_model()
1438-
SVM = SixVertexModel(self._n,boundary_conditions='ice').an_element()
1436+
# ASM = AlternatingSignMatrix(matrix.identity(self._n))
1437+
# SVM = ASM.to_six_vertex_model()
1438+
SVM = SixVertexModel(self._n, boundary_conditions='ice').an_element()
14391439
return self.element_class(self, SVM)
14401440

14411441
def _boundary(self, k):
@@ -1457,19 +1457,19 @@ def _boundary(self, k):
14571457
True
14581458
"""
14591459
n = self._n
1460-
n_LR = n//2 if n%2 == 0 else (n+1) // 2
1461-
n_TB = n//2 if n%2 == 0 else (n-1) // 2
1460+
n_LR = n//2 if n % 2 == 0 else (n+1) // 2
1461+
n_TB = n//2 if n % 2 == 0 else (n-1) // 2
14621462
if k < n_LR:
14631463
return (-1, 2*k)
14641464
k -= n_LR
14651465
if k < n_TB:
1466-
return (n%2 + 2*k, n)
1466+
return (n % 2 + 2*k, n)
14671467
k -= n_TB
14681468
if k < n_LR:
14691469
return (n, n - 1 - 2*k)
14701470
k -= n_LR
14711471
if k < n_TB:
1472-
return (n - 1 - n%2 - 2*k, -1)
1472+
return (n - 1 - n % 2 - 2*k, -1)
14731473

14741474
def _boundary_index(self, pos):
14751475
r"""

src/sage/combinat/growth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,8 @@ def rotate(self):
797797
"""
798798
l = self._lambda[0]
799799
h = len(self._lambda)
800-
shape_lambda = [l-p for p in self._mu] + [l]*(h-len(self._mu))
801-
shape_mu = [l-p for p in self._lambda]
800+
shape_lambda = [l - p for p in self._mu] + [l] * (h - len(self._mu))
801+
shape_mu = [l - p for p in self._lambda]
802802
shape = SkewPartition([shape_lambda[::-1], shape_mu[::-1]])
803803
F = {(l-i-1, h-j-1): v for (i,j),v in self._filling.items()}
804804
return GrowthDiagram(self.rule,

src/sage/combinat/key_polynomial.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ def divided_difference(f, i):
794794
si_f = f.subs({z[i]: z[i-1], z[i-1]: z[i]})
795795
return (si_f - f) // (z[i] - z[i-1])
796796

797+
797798
def isobaric_divided_difference(f, w):
798799
r"""
799800
Apply the isobaric divided difference operator `\pi_w` to the
@@ -839,6 +840,7 @@ def isobaric_divided_difference(f, w):
839840
f = (si_fp - fp) // (z[i] - z[i-1])
840841
return f
841842

843+
842844
def sorting_word(alpha):
843845
r"""
844846
Get a reduced word for the permutation which sorts ``alpha``

0 commit comments

Comments
 (0)