Skip to content

Commit 68826a4

Browse files
committed
cylint: some fixes in combinat/(crystals,matrices,words)
1 parent 853d070 commit 68826a4

File tree

11 files changed

+45
-43
lines changed

11 files changed

+45
-43
lines changed

src/sage/combinat/crystals/letters.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ class ClassicalCrystalOfLetters(UniqueRepresentation, Parent):
319319
# temporary workaround while an_element is overridden by Parent
320320
_an_element_ = EnumeratedSets.ParentMethods._an_element_
321321

322+
322323
# Utility. Note: much of this class should be factored out at some point!
323324
cdef class Letter(Element):
324325
r"""
@@ -2571,6 +2572,7 @@ class CrystalOfBKKLetters(ClassicalCrystalOfLetters):
25712572

25722573
Element = BKKLetter
25732574

2575+
25742576
#################
25752577
# Type q(n) queer
25762578
#################
@@ -2981,6 +2983,7 @@ cdef class LetterWrapped(Element):
29812983
"""
29822984
return self.value.phi(i)
29832985

2986+
29842987
class ClassicalCrystalOfLettersWrapped(ClassicalCrystalOfLetters):
29852988
r"""
29862989
Crystal of letters by wrapping another crystal.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
cpdef tuple compute_new_lusztig_datum(list enhanced_braid_chain, initial_lusztig_datum)
22
cpdef tuple tropical_plucker_relation(tuple a, lusztig_datum)
33
cpdef list enhance_braid_move_chain(braid_move_chain, cartan_type)
4-

src/sage/combinat/crystals/pbw_datum.pyx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ from sage.combinat.root_system.braid_move_calculator import BraidMoveCalculator
3030

3131
cimport cython
3232

33+
3334
class PBWDatum():
3435
"""
3536
Helper class which represents a PBW datum.
@@ -277,7 +278,8 @@ class PBWData(): # UniqueRepresentation?
277278
w0 = self.weyl_group.long_element()
278279
return tuple([i] + (si * w0).reduced_word())
279280

280-
#enhanced_braid_chain is an ugly data structure.
281+
282+
# enhanced_braid_chain is an ugly data structure.
281283
@cython.boundscheck(False)
282284
@cython.wraparound(False)
283285
cpdef tuple compute_new_lusztig_datum(list enhanced_braid_chain, initial_lusztig_datum):
@@ -314,17 +316,18 @@ cpdef tuple compute_new_lusztig_datum(list enhanced_braid_chain, initial_lusztig
314316
"""
315317
cdef tuple interval_of_change
316318
# Does not currently check that len(initial_lusztig_datum) is appropriate
317-
cdef list new_lusztig_datum = list(initial_lusztig_datum) #shallow copy
319+
cdef list new_lusztig_datum = list(initial_lusztig_datum) # shallow copy
318320
cdef int i
319321
for i in range(1, len(enhanced_braid_chain)):
320322
interval_of_change, type_data = enhanced_braid_chain[i]
321-
a,b = interval_of_change
323+
a, b = interval_of_change
322324
old_interval_datum = new_lusztig_datum[a:b]
323325
new_interval_datum = tropical_plucker_relation(type_data, old_interval_datum)
324326
new_lusztig_datum[a:b] = new_interval_datum
325327
return tuple(new_lusztig_datum)
326328

327-
# The tropical plucker relations
329+
330+
# The tropical Plücker relations
328331
@cython.boundscheck(False)
329332
@cython.wraparound(False)
330333
cpdef tuple tropical_plucker_relation(tuple a, lusztig_datum):
@@ -395,6 +398,7 @@ cpdef tuple tropical_plucker_relation(tuple a, lusztig_datum):
395398
return tuple(reversed(tropical_plucker_relation((a[1], a[0]),
396399
reversed_lusztig_datum)))
397400

401+
398402
# Maybe we need to be more specific, and pass not the Cartan type, but the root lattice?
399403
# TODO: Move to PBW_data?
400404
@cython.boundscheck(False)

src/sage/combinat/crystals/spins.pxd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ cdef class Spin_crystal_type_D_element(Spin):
1818
cpdef Spin f(self, int i)
1919
cpdef int epsilon(self, int i)
2020
cpdef int phi(self, int i)
21-

src/sage/combinat/crystals/spins.pyx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def CrystalOfSpins(ct):
9999
else:
100100
raise NotImplementedError
101101

102+
102103
#########################
103104
# Type D spins
104105
#########################
@@ -135,6 +136,7 @@ def CrystalOfSpinsPlus(ct):
135136
else:
136137
raise NotImplementedError
137138

139+
138140
def CrystalOfSpinsMinus(ct):
139141
r"""
140142
Return the minus spin crystal of the given type D.
@@ -168,6 +170,7 @@ def CrystalOfSpinsMinus(ct):
168170
else:
169171
raise NotImplementedError
170172

173+
171174
class GenericCrystalOfSpins(UniqueRepresentation, Parent):
172175
"""
173176
A generic crystal of spins.
@@ -181,11 +184,11 @@ class GenericCrystalOfSpins(UniqueRepresentation, Parent):
181184
"""
182185
self._cartan_type = CartanType(ct)
183186
if case == "spins":
184-
self.rename("The crystal of spins for type %s"%ct)
187+
self.rename("The crystal of spins for type %s" % ct)
185188
elif case == "plus":
186-
self.rename("The plus crystal of spins for type %s"%ct)
189+
self.rename("The plus crystal of spins for type %s" % ct)
187190
else:
188-
self.rename("The minus crystal of spins for type %s"%ct)
191+
self.rename("The minus crystal of spins for type %s" % ct)
189192

190193
self.Element = element_class
191194
Parent.__init__(self, category=ClassicalCrystals())
@@ -250,6 +253,7 @@ class GenericCrystalOfSpins(UniqueRepresentation, Parent):
250253
raise ValueError("both elements must be in this crystal")
251254
return self._digraph_closure.has_edge(x, y)
252255

256+
253257
cdef class Spin(Element):
254258
"""
255259
A spin letter in the crystal of spins.

src/sage/combinat/crystals/tensor_product_element.pxd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ cdef class InfinityQueerCrystalOfTableauxElement(TensorProductOfQueerSuperCrysta
3232
cdef list _row_lengths
3333

3434
cdef Py_ssize_t count_leading(list row, letter)
35-

src/sage/combinat/crystals/tensor_product_element.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ cdef class InfinityCrystalOfTableauxElementTypeD(InfinityCrystalOfTableauxElemen
11581158
return ret
11591159

11601160
#####################################################################
1161-
## BKK crystal elements
1161+
# BKK crystal elements
11621162

11631163
cdef class TensorProductOfSuperCrystalsElement(TensorProductOfRegularCrystalsElement):
11641164
r"""
@@ -1405,7 +1405,7 @@ cdef class CrystalOfBKKTableauxElement(TensorProductOfSuperCrystalsElement):
14051405
return Tableau(tab).conjugate()
14061406

14071407
#####################################################################
1408-
## Queer crystal elements
1408+
# Queer crystal elements
14091409

14101410
cdef class TensorProductOfQueerSuperCrystalsElement(TensorProductOfRegularCrystalsElement):
14111411
r"""

src/sage/combinat/matrices/dancing_links.pyx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ cdef class dancing_linksWrapper:
330330
"""
331331
return PyObject_RichCompare(left._rows, right._rows, op)
332332

333-
334333
def get_solution(self):
335334
"""
336335
Return the current solution.
@@ -473,7 +472,7 @@ cdef class dancing_linksWrapper:
473472
from copy import copy
474473
rows = copy(self._rows)
475474
ncols = self.ncols()
476-
for i,row_index in enumerate(indices):
475+
for i, row_index in enumerate(indices):
477476
# in the line below we want the creation of a new list
478477
rows[row_index] = rows[row_index] + [ncols+i]
479478
return dlx_solver(rows)
@@ -546,8 +545,8 @@ cdef class dancing_linksWrapper:
546545
if not 0 <= column < self.ncols():
547546
raise ValueError("column(={}) must be in range(ncols) "
548547
"where ncols={}".format(column, self.ncols()))
549-
indices = [i for (i,row) in enumerate(self._rows) if column in row]
550-
return {i:self.restrict([i]) for i in indices}
548+
indices = (i for i, row in enumerate(self._rows) if column in row)
549+
return {i: self.restrict([i]) for i in indices}
551550

552551
def solutions_iterator(self):
553552
r"""
@@ -792,7 +791,7 @@ cdef class dancing_linksWrapper:
792791
L.append(dlx.get_solution())
793792
return L
794793

795-
indices = [i for (i,row) in enumerate(self._rows) if column in row]
794+
indices = [i for i, row in enumerate(self._rows) if column in row]
796795
L = []
797796
for (args_kwds, val) in all_solutions(indices):
798797
L.extend(val)
@@ -892,7 +891,7 @@ cdef class dancing_linksWrapper:
892891
N += 1
893892
return N
894893

895-
indices = [i for (i,row) in enumerate(self._rows) if column in row]
894+
indices = [i for i, row in enumerate(self._rows) if column in row]
896895
return sum(val for (args_kwds, val) in nb_sol(indices))
897896

898897
@cached_method
@@ -935,7 +934,7 @@ cdef class dancing_linksWrapper:
935934
# Note that row number i is associated to SAT variable i+1 to
936935
# avoid a variable zero
937936
columns = [[] for _ in range(self.ncols())]
938-
for i,row in enumerate(self.rows(), start=1):
937+
for i, row in enumerate(self.rows(), start=1):
939938
for a in row:
940939
columns[a].append(i)
941940

@@ -946,8 +945,8 @@ cdef class dancing_linksWrapper:
946945
# At most one 1 in each column
947946
import itertools
948947
for clause in columns:
949-
for p,q in itertools.combinations(clause, 2):
950-
sub_clause = [-p,-q]
948+
for p, q in itertools.combinations(clause, 2):
949+
sub_clause = [-p, -q]
951950
s.add_clause(sub_clause)
952951

953952
return s
@@ -995,13 +994,12 @@ cdef class dancing_linksWrapper:
995994
sage: d = dlx_solver(rows)
996995
sage: d.one_solution_using_sat_solver() is None
997996
True
998-
999997
"""
1000998
sat_solver = self.to_sat_solver(solver)
1001999
solution = sat_solver()
10021000
if not solution:
10031001
return None
1004-
return [key for (key,val) in enumerate(solution, start=-1) if val]
1002+
return [key for key, val in enumerate(solution, start=-1) if val]
10051003

10061004
@cached_method
10071005
def to_milp(self, solver=None):
@@ -1123,18 +1121,17 @@ cdef class dancing_linksWrapper:
11231121
sage: d = dlx_solver(rows)
11241122
sage: d.one_solution_using_milp_solver() is None
11251123
True
1126-
11271124
"""
11281125
from sage.numerical.mip import MIPSolverException
1129-
p,x = self.to_milp(solver)
1126+
p, x = self.to_milp(solver)
11301127
try:
11311128
p.solve()
11321129
except MIPSolverException:
11331130
return None
1134-
else:
1135-
soln = p.get_values(x, convert=bool, tolerance=integrality_tolerance)
1136-
support = sorted(key for key in soln if soln[key])
1137-
return support
1131+
1132+
soln = p.get_values(x, convert=bool, tolerance=integrality_tolerance)
1133+
return sorted(key for key in soln if soln[key])
1134+
11381135

11391136
def dlx_solver(rows):
11401137
"""

src/sage/combinat/words/word_char.pyx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import itertools
3232
# the maximum value of a size_t
3333
cdef size_t SIZE_T_MAX = -(<size_t> 1)
3434

35+
3536
def reversed_word_iterator(WordDatatype_char w):
3637
r"""
3738
This function exists only because it is not possible to use yield in the
@@ -48,6 +49,7 @@ def reversed_word_iterator(WordDatatype_char w):
4849
for i in range(w._length-1, -1, -1):
4950
yield w._data[i]
5051

52+
5153
cdef class WordDatatype_char(WordDatatype):
5254
r"""
5355
A Fast class for words represented by an array ``unsigned char *``.
@@ -361,7 +363,7 @@ cdef class WordDatatype_char(WordDatatype):
361363
"""
362364
cdef Py_ssize_t i, start, stop, step, slicelength
363365
cdef unsigned char * data
364-
cdef size_t j,k
366+
cdef size_t j, k
365367
if isinstance(key, slice):
366368
# here the key is a slice
367369
PySlice_GetIndicesEx(key,
@@ -374,7 +376,7 @@ cdef class WordDatatype_char(WordDatatype):
374376
return self._new_c(self._data+start, stop-start, self)
375377
data = <unsigned char *>check_allocarray(slicelength, sizeof(unsigned char))
376378
j = 0
377-
for k in range(start,stop,step):
379+
for k in range(start, stop, step):
378380
data[j] = self._data[k]
379381
j += 1
380382
return self._new_c(data, slicelength, None)
@@ -392,7 +394,7 @@ cdef class WordDatatype_char(WordDatatype):
392394
393395
def __iter__(self):
394396
r"""
395-
Iterator over the letter of self
397+
Iterator over the letters of ``self``.
396398
397399
EXAMPLES::
398400
@@ -406,7 +408,7 @@ cdef class WordDatatype_char(WordDatatype):
406408
407409
def __reversed__(self):
408410
r"""
409-
Reversed iterator over the letter of self
411+
Reversed iterator over the letters of ``self``.
410412
411413
EXAMPLES::
412414
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
cdef class WordDatatype():
22
cdef public _parent
33
cdef _hash
4-

0 commit comments

Comments
 (0)