Skip to content

Commit 0fe4c81

Browse files
author
Release Manager
committed
gh-40685: cython-lint cleanup in modules folder fixing minor details, as suggested by cython-lint also converting a few loops to use `range` ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40685 Reported by: Frédéric Chapoton Reviewer(s): Frédéric Chapoton, Michael Orlitzky
2 parents e9f3727 + cb29640 commit 0fe4c81

14 files changed

+92
-87
lines changed

src/sage/modules/finite_submodule_iter.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from sage.structure.element cimport ModuleElement
22

33
cdef class FiniteZZsubmodule_iterator:
4-
#### Global Data
4+
# Global Data
55
cdef FiniteZZsubmodule_iterator _other_ZZ
66
cdef ModuleElement _basis
77
cdef ModuleElement _cw

src/sage/modules/finite_submodule_iter.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ will result in improved running times::
5757
True
5858
"""
5959

60-
#*****************************************************************************
60+
# ***************************************************************************
6161
# Copyright (C) 2012 Thomas Feulner <[email protected]>
6262
#
6363
# Distributed under the terms of the GNU General Public License (GPL)
6464
# as published by the Free Software Foundation; either version 2 of
6565
# the License, or (at your option) any later version.
66-
# http://www.gnu.org/licenses/
67-
#*****************************************************************************
66+
# https://www.gnu.org/licenses/
67+
# ***************************************************************************
6868

6969
cdef class FiniteZZsubmodule_iterator:
7070
r"""

src/sage/modules/free_module_element.pyx

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ def random_vector(ring, degree=None, *args, **kwds):
953953
if ring not in Rings():
954954
raise TypeError("elements of a vector, or module element, must come from a ring, not %s" % ring)
955955
if not hasattr(ring, "random_element"):
956-
raise AttributeError("cannot create a random vector since there is no random_element() method for %s" % ring )
956+
raise AttributeError("cannot create a random vector since there is no random_element() method for %s" % ring)
957957
sparse = kwds.pop('sparse', False)
958958
entries = [ring.random_element(*args, **kwds) for _ in range(degree)]
959959
return vector(ring, degree, entries, sparse)
@@ -1290,16 +1290,15 @@ cdef class FreeModuleElement(Vector): # abstract base class
12901290
# on the elements, which is sometimes much prettier than
12911291
# the coerced=False we would get otherwise.
12921292
if self.is_sparse_c():
1293-
items = [(n, sib(e, 2))
1294-
for n,e in self.dict().items()]
1293+
items = [(n, sib(e, 2)) for n, e in self.dict().items()]
12951294
items.sort()
12961295
if len(self):
12971296
# we may need to add an extra element on the end to
12981297
# set the size. (There doesn't seem to be a better way
12991298
# to do it.)
1300-
if len(items) == 0 or len(self)-1 > items[-1][0]:
1299+
if not items or len(self)-1 > items[-1][0]:
13011300
items.append((len(self)-1, sib.int(0)))
1302-
items_dict = sib.dict([(sib.int(n), e) for n,e in items])
1301+
items_dict = sib.dict([(sib.int(n), e) for n, e in items])
13031302

13041303
return sib.name('vector')(self.base_ring(), items_dict)
13051304
else:
@@ -1508,7 +1507,7 @@ cdef class FreeModuleElement(Vector): # abstract base class
15081507
"""
15091508
from sage.matrix.args import MatrixArgs
15101509
ma = MatrixArgs(self._parent._base, 1, self.degree(),
1511-
list(self), sparse=self.is_sparse())
1510+
list(self), sparse=self.is_sparse())
15121511
return ma.matrix()
15131512

15141513
def column(self):
@@ -1580,7 +1579,7 @@ cdef class FreeModuleElement(Vector): # abstract base class
15801579
"""
15811580
from sage.matrix.args import MatrixArgs
15821581
ma = MatrixArgs(self._parent._base, self.degree(), 1,
1583-
[(x,) for x in self], sparse=self.is_sparse())
1582+
[(x,) for x in self], sparse=self.is_sparse())
15841583
return ma.matrix()
15851584

15861585
def __copy__(self):
@@ -1622,7 +1621,7 @@ cdef class FreeModuleElement(Vector): # abstract base class
16221621
sage: v.subs(a=b, b=d)
16231622
(b, d, d, e)
16241623
"""
1625-
return self.parent()([ a.subs(in_dict, **kwds) for a in self.list() ])
1624+
return self.parent()([a.subs(in_dict, **kwds) for a in self.list()])
16261625

16271626
def change_ring(self, R):
16281627
"""
@@ -2481,7 +2480,9 @@ cdef class FreeModuleElement(Vector): # abstract base class
24812480
from sage.plot.plot3d.shapes2 import line3d, point3d
24822481

24832482
if plot_type == 'arrow':
2484-
return line3d([start, [(u+v) for u,v in zip(coords, start)]], arrow_head=True, **kwds)
2483+
return line3d([start,
2484+
[(u+v) for u, v in zip(coords, start)]],
2485+
arrow_head=True, **kwds)
24852486
else:
24862487
return point3d(coords, **kwds)
24872488
elif dimension < 3:
@@ -2492,7 +2493,8 @@ cdef class FreeModuleElement(Vector): # abstract base class
24922493

24932494
from sage.plot.all import arrow, point
24942495
if plot_type == 'arrow':
2495-
return arrow(start, [(u+v) for u,v in zip(coords, start)], **kwds)
2496+
return arrow(start,
2497+
[(u+v) for u, v in zip(coords, start)], **kwds)
24962498
else:
24972499
return point(coords, **kwds)
24982500
else:
@@ -2504,7 +2506,7 @@ cdef class FreeModuleElement(Vector): # abstract base class
25042506
raise NotImplementedError("plot_type was unrecognized")
25052507

25062508
def plot_step(self, xmin=0, xmax=1, eps=None, res=None,
2507-
connect=True, **kwds):
2509+
connect=True, **kwds):
25082510
r"""
25092511
INPUT:
25102512
@@ -2542,9 +2544,9 @@ cdef class FreeModuleElement(Vector): # abstract base class
25422544
y = float(self[i])
25432545
if x > xmax:
25442546
break
2545-
v.append((x,y))
2547+
v.append((x, y))
25462548
x += eps
2547-
v.append((x,y))
2549+
v.append((x, y))
25482550
from sage.plot.all import line, points
25492551
if connect:
25502552
return line(v, **kwds)
@@ -2885,9 +2887,9 @@ cdef class FreeModuleElement(Vector): # abstract base class
28852887
MS = MatrixSpace(R, rank, rank, sparse=self.is_sparse())
28862888
s = self.list(copy=False)
28872889
return MS([
2888-
[ zero, -s[2], s[1]],
2889-
[ s[2], zero, -s[0]],
2890-
[-s[1], s[0], zero]])
2890+
[zero, -s[2], s[1]],
2891+
[s[2], zero, -s[0]],
2892+
[-s[1], s[0], zero]])
28912893
elif rank == 7:
28922894
MS = MatrixSpace(R, rank, rank, sparse=self.is_sparse())
28932895
s = self.list(copy=False)
@@ -4031,16 +4033,16 @@ cdef class FreeModuleElement(Vector): # abstract base class
40314033
zero_res = 0
40324034
if len(self.dict(copy=False)) < self._degree:
40334035
# OK, we have some zero entries.
4034-
zero_res = phi(self.base_ring()(0))
4036+
zero_res = phi(self.base_ring().zero())
40354037
if not zero_res.is_zero():
40364038
# And phi maps 0 to a nonzero value.
40374039
v = [zero_res] * self._degree
4038-
for i,z in self.dict(copy=False).items():
4040+
for i, z in self.dict(copy=False).items():
40394041
v[i] = phi(z)
40404042
40414043
if v is None:
40424044
# phi maps 0 to 0 (or else we don't have any zeroes at all)
4043-
v = dict([(i,phi(z)) for i,z in self.dict(copy=False).items()])
4045+
v = {i: phi(z) for i, z in self.dict(copy=False).items()}
40444046
# add a zero at the last position, if it is not already set.
40454047
# This will help the constructor to determine the right degree.
40464048
v.setdefault(self._degree-1, zero_res)
@@ -4189,14 +4191,14 @@ cdef class FreeModuleElement(Vector): # abstract base class
41894191
# return self.apply_map(lambda x: x.nintegral(*args, **kwds) for x in self)
41904192
41914193
if self.is_sparse():
4192-
v = [(i,z.nintegral(*args, **kwds)) for i,z in self.dict(copy=False).items()]
4193-
answers = dict([(i,a[0]) for i,a in v])
4194-
v=dict(v)
4194+
v = {i: z.nintegral(*args, **kwds)
4195+
for i, z in self.dict(copy=False).items()}
4196+
answers = {i: a[0] for i, a in v.items()}
41954197
else:
41964198
v = [z.nintegral(*args, **kwds) for z in self.list()]
41974199
answers = [a[0] for a in v]
41984200
4199-
return (vector(answers,sparse=self.is_sparse()), v)
4201+
return (vector(answers, sparse=self.is_sparse()), v)
42004202
42014203
nintegrate = nintegral
42024204
@@ -5518,4 +5520,4 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement):
55185520
if prec is None:
55195521
prec = digits_to_bits(digits)
55205522
return vector({k: v.numerical_approx(prec, algorithm=algorithm)
5521-
for k, v in self._entries.iteritems()}, sparse=True)
5523+
for k, v in self._entries.iteritems()}, sparse=True)

src/sage/modules/module.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ A minimal example of a module::
4949
sage: TestSuite(M).run()
5050
"""
5151

52-
#*****************************************************************************
52+
# ***************************************************************************
5353
# Copyright (C) 2005 William Stein <[email protected]>
5454
# 2014 Julian Rueth <[email protected]>
5555
#
@@ -62,8 +62,8 @@ A minimal example of a module::
6262
#
6363
# The full text of the GPL is available at:
6464
#
65-
# http://www.gnu.org/licenses/
66-
#*****************************************************************************
65+
# https://www.gnu.org/licenses/
66+
# ***************************************************************************
6767

6868
cdef class Module(Parent):
6969
"""

src/sage/modules/vector_complex_double_dense.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ AUTHORS:
3131
Vector_double_dense class
3232
"""
3333

34-
#*****************************************************************************
34+
# ***************************************************************************
3535
# Copyright (C) 2008 Jason Grout <[email protected]>
3636
#
3737
# This program is free software: you can redistribute it and/or modify
3838
# it under the terms of the GNU General Public License as published by
3939
# the Free Software Foundation, either version 2 of the License, or
4040
# (at your option) any later version.
41-
# http://www.gnu.org/licenses/
42-
#*****************************************************************************
41+
# https://www.gnu.org/licenses/
42+
# ***************************************************************************
4343

4444
from sage.rings.complex_double import CDF
4545

src/sage/modules/vector_double_dense.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ AUTHORS:
3333
- William Stein
3434
"""
3535

36-
#*****************************************************************************
36+
# ***************************************************************************
3737
# Copyright (C) 2006-2010 William Stein <[email protected]>
3838
# Copyright (C) 2009 Alexandru Ghitza
3939
# Copyright (C) 2020 Antonio Rojas
@@ -48,7 +48,7 @@ AUTHORS:
4848
# the Free Software Foundation, either version 2 of the License, or
4949
# (at your option) any later version.
5050
# https://www.gnu.org/licenses/
51-
#*****************************************************************************
51+
# ***************************************************************************
5252

5353
cimport numpy
5454
import numpy

src/sage/modules/vector_integer_sparse.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ from sage.libs.gmp.types cimport mpz_t
88

99
cdef struct mpz_vector:
1010
mpz_t *entries # array of nonzero entries
11-
Py_ssize_t *positions # positions of those nonzero entries, starting at 0
12-
Py_ssize_t degree # the degree of this sparse vector
13-
Py_ssize_t num_nonzero # the number of nonzero entries of this vector.
11+
Py_ssize_t *positions # positions of those nonzero entries, starting at 0
12+
Py_ssize_t degree # the degree of this sparse vector
13+
Py_ssize_t num_nonzero # the number of nonzero entries of this vector.
1414

1515
cdef int allocate_mpz_vector(mpz_vector* v, Py_ssize_t num_nonzero) except -1
1616
cdef int mpz_vector_init(mpz_vector* v, Py_ssize_t degree, Py_ssize_t num_nonzero) except -1

src/sage/modules/vector_integer_sparse.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ cdef object mpz_vector_to_list(mpz_vector* v):
163163
cdef Integer a
164164
cdef Py_ssize_t i
165165
X = []
166-
for i from 0 <= i < v.num_nonzero:
166+
for i in range(v.num_nonzero):
167167
a = Integer()
168168
a.set_from_mpz(v.entries[i])
169-
X.append( (v.positions[i], a) )
169+
X.append((v.positions[i], a))
170170
return X
171171

172172

@@ -318,7 +318,7 @@ cdef int add_mpz_vector_init(mpz_vector* sum,
318318
mpz_set(z.entries[k], v.entries[i])
319319
i = i + 1
320320
k = k + 1
321-
elif v.positions[i] > w.positions[j]: # copy entry from w in
321+
elif v.positions[i] > w.positions[j]: # copy entry from w in
322322
if do_multiply:
323323
# This means: tmp = multiple*w.entries[j]
324324
mpz_mul(tmp, multiple, w.entries[j])
@@ -343,7 +343,7 @@ cdef int add_mpz_vector_init(mpz_vector* sum,
343343
k = k + 1 # only increment if sum is nonzero!
344344
i = i + 1
345345
j = j + 1
346-
#end if
346+
# end if
347347
# end while
348348
for i from k <= i < z.num_nonzero:
349349
mpz_clear(z.entries[i])
@@ -357,7 +357,7 @@ cdef int mpz_vector_scale(mpz_vector* v, mpz_t scalar) except -1:
357357
mpz_vector_init(v, v.degree, 0)
358358
return 0
359359
cdef Py_ssize_t i
360-
for i from 0 <= i < v.num_nonzero:
360+
for i in range(v.num_nonzero):
361361
# v.entries[i] = scalar * v.entries[i]
362362
mpz_mul(v.entries[i], v.entries[i], scalar)
363363
return 0

src/sage/modules/vector_modn_sparse.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ cdef int add_c_vector_modint_init(c_vector_modint* sum, c_vector_modint* v,
264264
z.entries[k] = v.entries[i]
265265
i = i + 1
266266
k = k + 1
267-
elif v.positions[i] > w.positions[j]: # copy entry from w in
267+
elif v.positions[i] > w.positions[j]: # copy entry from w in
268268
s = (multiple * w.entries[j]) % v.p
269269
if s != 0:
270270
z.positions[k] = w.positions[j]

0 commit comments

Comments
 (0)