Skip to content

Commit ebc7130

Browse files
author
Release Manager
committed
gh-35822: most cython-lint suggestions fixed in algebras/ <!-- 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 This fixes most warnings issued by `cython-lint --ignore=E501,E741 src/sage/algebras/*/*.pyx ` except in letterplace subfolder <!-- 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: #35822 Reported by: Frédéric Chapoton Reviewer(s): Matthias Köppe
2 parents f9cb12c + 4d0a929 commit ebc7130

File tree

3 files changed

+71
-70
lines changed

3 files changed

+71
-70
lines changed

src/sage/algebras/lie_algebras/lie_algebra_element.pyx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ AUTHORS:
1717
# https://www.gnu.org/licenses/
1818
# ****************************************************************************
1919

20-
from copy import copy
2120
from cpython.object cimport Py_EQ, Py_NE, Py_GT, Py_GE
2221

2322
from sage.misc.repr import repr_lincomb
@@ -119,9 +118,11 @@ cdef class LieAlgebraElement(IndexedFreeModuleElement):
119118
return s
120119
names = self.parent().variable_names()
121120
if base_map is None:
122-
base_map = lambda x: x
121+
def base_map(x):
122+
return x
123+
123124
return codomain.sum(base_map(c) * t._im_gens_(codomain, im_gens, names)
124-
for t, c in self._monomial_coefficients.iteritems())
125+
for t, c in self._monomial_coefficients.items())
125126

126127
cpdef lift(self):
127128
"""
@@ -166,10 +167,10 @@ cdef class LieAlgebraElement(IndexedFreeModuleElement):
166167
# does not match the generators index set of the UEA.
167168
if hasattr(self._parent, '_UEA_names_map'):
168169
names_map = self._parent._UEA_names_map
169-
for t, c in self._monomial_coefficients.iteritems():
170+
for t, c in self._monomial_coefficients.items():
170171
s += c * gen_dict[names_map[t]]
171172
else:
172-
for t, c in self._monomial_coefficients.iteritems():
173+
for t, c in self._monomial_coefficients.items():
173174
s += c * gen_dict[t]
174175
return s
175176

@@ -459,7 +460,7 @@ cdef class LieAlgebraElementWrapper(ElementWrapper):
459460
((1,3,2), 1), ((1,3), 1)]
460461
"""
461462
cdef dict d = self.value.monomial_coefficients(copy=False)
462-
yield from d.iteritems()
463+
yield from d.items()
463464

464465

465466
# TODO: Also used for vectors, find a better name
@@ -598,7 +599,8 @@ cdef class LieSubalgebraElementWrapper(LieAlgebraElementWrapper):
598599
if self._monomial_coefficients is None:
599600
sm = self.parent().module()
600601
v = sm.coordinate_vector(self.to_vector())
601-
self._monomial_coefficients = {k: v[k] for k in range(len(v)) if v[k]}
602+
self._monomial_coefficients = {k: v[k] for k in range(len(v))
603+
if v[k]}
602604
if copy:
603605
return dict(self._monomial_coefficients)
604606
return self._monomial_coefficients
@@ -861,7 +863,7 @@ cdef class StructureCoefficientsElement(LieAlgebraMatrixWrapper):
861863
"""
862864
UEA = self._parent.universal_enveloping_algebra()
863865
gens = UEA.gens()
864-
return UEA.sum(c * gens[i] for i, c in self.value.iteritems())
866+
return UEA.sum(c * gens[i] for i, c in self.value.items())
865867

866868
cpdef dict monomial_coefficients(self, bint copy=True):
867869
"""
@@ -878,7 +880,7 @@ cdef class StructureCoefficientsElement(LieAlgebraMatrixWrapper):
878880
{'x': 2, 'z': -3/2}
879881
"""
880882
I = self._parent._indices
881-
return {I[i]: v for i, v in self.value.iteritems()}
883+
return {I[i]: v for i, v in self.value.items()}
882884

883885
def __getitem__(self, i):
884886
"""
@@ -1066,7 +1068,8 @@ cdef class UntwistedAffineLieAlgebraElement(Element):
10661068
( alpha[1] - alphacheck[1] + 2·-alpha[1] )⊗t⁰ + ( -alpha[1] )⊗t¹ + 3⋅c + -2⋅d
10671069
"""
10681070
from sage.typeset.unicode_art import unicode_art, unicode_superscript
1069-
return self._repr_generic(unicode_art, unicode_art, lambda t: "t" + unicode_superscript(t),
1071+
return self._repr_generic(unicode_art, unicode_art,
1072+
lambda t: "t" + unicode_superscript(t),
10701073
unicode_art(''), unicode_art(''))
10711074

10721075
cpdef dict t_dict(self):
@@ -1269,7 +1272,7 @@ cdef class UntwistedAffineLieAlgebraElement(Element):
12691272
"""
12701273
cdef dict d = {}
12711274
for t, g in self._t_dict.items():
1272-
for k, c in g.monomial_coefficients(copy=False).iteritems():
1275+
for k, c in g.monomial_coefficients(copy=False).items():
12731276
d[k, t] = c
12741277
if self._c_coeff:
12751278
d['c'] = self._c_coeff
@@ -1437,7 +1440,7 @@ class FreeLieAlgebraElement(LieAlgebraElement):
14371440
if not self:
14381441
return s
14391442
gen_dict = UEA.gens_dict()
1440-
for t, c in self._monomial_coefficients.iteritems():
1443+
for t, c in self._monomial_coefficients.items():
14411444
s += c * t.lift(gen_dict)
14421445
return s
14431446

@@ -1446,6 +1449,7 @@ class FreeLieAlgebraElement(LieAlgebraElement):
14461449
Return ``self`` as a list of pairs ``(m, c)`` where ``m`` is a
14471450
basis key (i.e., a key of one of the basis elements)
14481451
and ``c`` is its coefficient.
1452+
14491453
This list is sorted from highest to lowest degree.
14501454
14511455
EXAMPLES::
@@ -1455,8 +1459,10 @@ class FreeLieAlgebraElement(LieAlgebraElement):
14551459
sage: elt.list()
14561460
[([x, y], -1), (x, 1)]
14571461
"""
1458-
k = lambda x: (-x[0]._grade, x[0]) if isinstance(x[0], GradedLieBracket) else (-1, x[0])
1459-
return sorted((<dict>self._monomial_coefficients).iteritems(), key=k)
1462+
def k(x):
1463+
y = x[0]
1464+
return (-y._grade, y) if isinstance(y, GradedLieBracket) else (-1, y)
1465+
return sorted((<dict>self._monomial_coefficients).items(), key=k)
14601466

14611467
def _bracket_(self, y):
14621468
"""
@@ -1479,16 +1485,16 @@ class FreeLieAlgebraElement(LieAlgebraElement):
14791485

14801486
cdef dict d = {}
14811487
zero = self.base_ring().zero()
1482-
for ml, cl in self._monomial_coefficients.iteritems(): # The left monomials
1483-
for mr, cr in y._monomial_coefficients.iteritems(): # The right monomials
1488+
for ml, cl in self._monomial_coefficients.items(): # The left monomials
1489+
for mr, cr in y._monomial_coefficients.items(): # The right monomials
14841490
if ml == mr:
14851491
continue
14861492
if ml < mr: # Make sure ml < mr
14871493
a, b = ml, mr
14881494
else:
14891495
a, b = mr, ml
14901496
cr = -cr
1491-
for b_elt, coeff in self.parent()._rewrite_bracket(a, b).iteritems():
1497+
for b_elt, coeff in self.parent()._rewrite_bracket(a, b).items():
14921498
d[b_elt] = d.get(b_elt, zero) + cl * cr * coeff
14931499
if d[b_elt] == zero:
14941500
del d[b_elt]

src/sage/algebras/quatalg/quaternion_algebra_cython.pyx

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ from sage.libs.flint.fmpz cimport fmpz_set_mpz
4343
from sage.libs.flint.fmpq cimport fmpq_canonicalise
4444
from sage.libs.flint.fmpq_mat cimport fmpq_mat_entry_num, fmpq_mat_entry_den, fmpq_mat_entry
4545

46+
4647
def integral_matrix_and_denom_from_rational_quaternions(v, reverse=False):
4748
r"""
4849
Given a list of rational quaternions, return matrix `A` over `\ZZ`
@@ -95,7 +96,6 @@ def integral_matrix_and_denom_from_rational_quaternions(v, reverse=False):
9596

9697
# Now fill in each row x of A, multiplying it by q = d/denom(x)
9798
cdef mpz_t q
98-
cdef mpz_t* row
9999
cdef mpz_t tmp
100100
mpz_init(q)
101101
mpz_init(tmp)
@@ -104,26 +104,27 @@ def integral_matrix_and_denom_from_rational_quaternions(v, reverse=False):
104104
mpz_fdiv_q(q, d.value, x.d)
105105
if reverse:
106106
mpz_mul(tmp, q, x.x)
107-
A.set_unsafe_mpz(n-i-1,3,tmp)
107+
A.set_unsafe_mpz(n-i-1, 3, tmp)
108108
mpz_mul(tmp, q, x.y)
109-
A.set_unsafe_mpz(n-i-1,2,tmp)
109+
A.set_unsafe_mpz(n-i-1, 2, tmp)
110110
mpz_mul(tmp, q, x.z)
111-
A.set_unsafe_mpz(n-i-1,1,tmp)
111+
A.set_unsafe_mpz(n-i-1, 1, tmp)
112112
mpz_mul(tmp, q, x.w)
113-
A.set_unsafe_mpz(n-i-1,0,tmp)
113+
A.set_unsafe_mpz(n-i-1, 0, tmp)
114114
else:
115115
mpz_mul(tmp, q, x.x)
116-
A.set_unsafe_mpz(i,0,tmp)
116+
A.set_unsafe_mpz(i, 0, tmp)
117117
mpz_mul(tmp, q, x.y)
118-
A.set_unsafe_mpz(i,1,tmp)
118+
A.set_unsafe_mpz(i, 1, tmp)
119119
mpz_mul(tmp, q, x.z)
120-
A.set_unsafe_mpz(i,2,tmp)
120+
A.set_unsafe_mpz(i, 2, tmp)
121121
mpz_mul(tmp, q, x.w)
122-
A.set_unsafe_mpz(i,3,tmp)
122+
A.set_unsafe_mpz(i, 3, tmp)
123123
mpz_clear(q)
124124
mpz_clear(tmp)
125125
return A, d
126126

127+
127128
def rational_matrix_from_rational_quaternions(v, reverse=False):
128129
r"""
129130
Return matrix over the rationals whose rows have entries the
@@ -165,7 +166,7 @@ def rational_matrix_from_rational_quaternions(v, reverse=False):
165166
fmpz_set_mpz(fmpq_mat_entry_num(A._matrix, n-i-1, 1), x.z)
166167
fmpz_set_mpz(fmpq_mat_entry_num(A._matrix, n-i-1, 0), x.w)
167168

168-
if mpz_cmp_si(x.d,1):
169+
if mpz_cmp_si(x.d, 1):
169170
for j in range(4):
170171
fmpz_set_mpz(fmpq_mat_entry_den(A._matrix, n-i-1, j), x.d)
171172
fmpq_canonicalise(fmpq_mat_entry(A._matrix, n-i-1, j))
@@ -177,13 +178,14 @@ def rational_matrix_from_rational_quaternions(v, reverse=False):
177178
fmpz_set_mpz(fmpq_mat_entry_num(A._matrix, i, 2), x.z)
178179
fmpz_set_mpz(fmpq_mat_entry_num(A._matrix, i, 3), x.w)
179180

180-
if mpz_cmp_si(x.d,1):
181+
if mpz_cmp_si(x.d, 1):
181182
for j in range(4):
182183
fmpz_set_mpz(fmpq_mat_entry_den(A._matrix, i, j), x.d)
183184
fmpq_canonicalise(fmpq_mat_entry(A._matrix, i, j))
184185

185186
return A
186187

188+
187189
def rational_quaternions_from_integral_matrix_and_denom(A, Matrix_integer_dense H, Integer d, reverse=False):
188190
r"""
189191
Given an integral matrix and denominator, returns a list of
@@ -221,7 +223,7 @@ def rational_quaternions_from_integral_matrix_and_denom(A, Matrix_integer_dense
221223
cdef Integer a, b
222224
a = Integer(A.invariants()[0])
223225
b = Integer(A.invariants()[1])
224-
cdef Py_ssize_t i, j
226+
cdef Py_ssize_t i
225227
cdef mpz_t tmp
226228
mpz_init(tmp)
227229

@@ -236,26 +238,26 @@ def rational_quaternions_from_integral_matrix_and_denom(A, Matrix_integer_dense
236238
mpz_set(x.a, a.value)
237239
mpz_set(x.b, b.value)
238240
if reverse:
239-
H.get_unsafe_mpz(i,3,tmp)
241+
H.get_unsafe_mpz(i, 3, tmp)
240242
mpz_init_set(x.x, tmp)
241-
H.get_unsafe_mpz(i,2,tmp)
243+
H.get_unsafe_mpz(i, 2, tmp)
242244
mpz_init_set(x.y, tmp)
243-
H.get_unsafe_mpz(i,1,tmp)
245+
H.get_unsafe_mpz(i, 1, tmp)
244246
mpz_init_set(x.z, tmp)
245-
H.get_unsafe_mpz(i,0,tmp)
247+
H.get_unsafe_mpz(i, 0, tmp)
246248
mpz_init_set(x.w, tmp)
247249
else:
248-
H.get_unsafe_mpz(i,0,tmp)
250+
H.get_unsafe_mpz(i, 0, tmp)
249251
mpz_init_set(x.x, tmp)
250-
H.get_unsafe_mpz(i,1,tmp)
252+
H.get_unsafe_mpz(i, 1, tmp)
251253
mpz_init_set(x.y, tmp)
252-
H.get_unsafe_mpz(i,2,tmp)
254+
H.get_unsafe_mpz(i, 2, tmp)
253255
mpz_init_set(x.z, tmp)
254-
H.get_unsafe_mpz(i,3,tmp)
256+
H.get_unsafe_mpz(i, 3, tmp)
255257
mpz_init_set(x.w, tmp)
256258
mpz_init_set(x.d, d.value)
257-
# WARNING -- we do *not* canonicalize the entries in the quaternion. This is
258-
# I think _not_ needed for quaternion_element.pyx
259+
# WARNING -- we do *not* canonicalize the entries in the quaternion.
260+
# This is I think _not_ needed for quaternion_element.pyx
259261
v.append(x)
260262
mpz_clear(tmp)
261263
return v

0 commit comments

Comments
 (0)