Skip to content

Commit 7ea9bae

Browse files
author
Release Manager
committed
gh-41662: partial cython-lint cleanup in matrix/ mostly cosmetic pep8 details, as suggested by cython-lint ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #41662 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents 0197fbe + 8c3f892 commit 7ea9bae

14 files changed

+102
-98
lines changed

src/sage/matrix/action.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ cdef class MatrixMatrixAction(MatrixMulAction):
211211
"""
212212
if self.G.ncols() != self.underlying_set().nrows():
213213
raise TypeError("incompatible dimensions %s, %s" %
214-
(self.G.ncols(), self.underlying_set().nrows()))
214+
(self.G.ncols(), self.underlying_set().nrows()))
215215
return MatrixSpace(base, self.G.nrows(), self.underlying_set().ncols(),
216-
sparse = self.G.is_sparse() and self.underlying_set().is_sparse())
216+
sparse=self.G.is_sparse() and self.underlying_set().is_sparse())
217217

218218
cpdef _act_(self, g, s):
219219
"""
@@ -321,7 +321,7 @@ cdef class MatrixVectorAction(MatrixMulAction):
321321
"""
322322
if self.G.ncols() != self.underlying_set().degree():
323323
raise TypeError("incompatible dimensions %s, %s" % (self.G.ncols(),
324-
self.underlying_set().degree()))
324+
self.underlying_set().degree()))
325325
return FreeModule(base, self.G.nrows(), sparse = self.G.is_sparse())
326326

327327
cpdef _act_(self, g, s):
@@ -373,7 +373,7 @@ cdef class VectorMatrixAction(MatrixMulAction):
373373
"""
374374
if self.G.nrows() != self.underlying_set().degree():
375375
raise TypeError("incompatible dimensions %s, %s" % (self.G.nrows(),
376-
self.underlying_set().degree()))
376+
self.underlying_set().degree()))
377377
return FreeModule(base, self.G.ncols(), sparse = self.G.is_sparse())
378378

379379
cpdef _act_(self, g, s):
@@ -388,7 +388,7 @@ cdef class VectorMatrixAction(MatrixMulAction):
388388
v = v.sparse_vector()
389389
else:
390390
v = v.dense_vector()
391-
return (<Matrix>A)._vector_times_matrix_(v) # v * A
391+
return (<Matrix>A)._vector_times_matrix_(v) # v * A
392392

393393
cdef class MatrixPolymapAction(MatrixMulAction):
394394
"""
@@ -484,7 +484,7 @@ cdef class PolymapMatrixAction(MatrixMulAction):
484484
"""
485485
if not isinstance(S, SchemeHomset_generic):
486486
raise TypeError("not a scheme polynomial morphism: %s"% S)
487-
MatrixMulAction.__init__(self, G, S, False )
487+
MatrixMulAction.__init__(self, G, S, False)
488488

489489
def _create_codomain(self, base):
490490
"""
@@ -571,8 +571,8 @@ cdef class MatrixSchemePointAction(MatrixMulAction):
571571
sage: A.codomain()
572572
Set of rational points of Projective Space of dimension 1 over Rational Field
573573
"""
574-
#need to extend the base of the ambient space
575-
#and return the set of point over the base
574+
# need to extend the base of the ambient space
575+
# and return the set of point over the base
576576
amb = self.underlying_set().codomain()
577577
return amb.change_ring(base)(base)
578578

src/sage/matrix/args.pyx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
Helpers for creating matrices
55
"""
66

7-
#*****************************************************************************
7+
# ***************************************************************************
88
# Copyright (C) 2018 Jeroen Demeyer <J.Demeyer@UGent.be>
99
#
1010
# This program is free software: you can redistribute it and/or modify
1111
# it under the terms of the GNU General Public License as published by
1212
# the Free Software Foundation, either version 2 of the License, or
1313
# (at your option) any later version.
14-
# http://www.gnu.org/licenses/
15-
#*****************************************************************************
14+
# https://www.gnu.org/licenses/
15+
# ***************************************************************************
1616

1717
cimport cython
1818
from cpython.sequence cimport PySequence_Fast
@@ -23,7 +23,7 @@ MatrixSpace = None
2323
from sage.rings.integer_ring import ZZ
2424
from sage.rings.integer cimport Integer
2525
from sage.structure.coerce cimport (coercion_model,
26-
is_numpy_type, py_scalar_parent)
26+
is_numpy_type, py_scalar_parent)
2727
from sage.structure.element cimport Element, RingElement, Vector
2828
from sage.arith.long cimport pyobject_to_long
2929
from sage.misc.misc_c import sized_iter
@@ -375,7 +375,8 @@ cdef class MatrixArgs:
375375
# Parse positional arguments (base, nrows, ncols, entries)
376376
# where each of them is optional.
377377
cdef Py_ssize_t argi = 0, argc = len(args)
378-
if argi == argc: return
378+
if argi == argc:
379+
return
379380

380381
# fast check for certain types of entries which cannot be
381382
# confused with a base ring or a number.
@@ -424,7 +425,8 @@ cdef class MatrixArgs:
424425
if self.entries is None:
425426
self.entries = args[argi]
426427
argi += 1
427-
if argi == argc: return
428+
if argi == argc:
429+
return
428430

429431
raise TypeError("too many arguments in matrix constructor")
430432

src/sage/matrix/benchmark.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def nullspace_ZZ(n=200, min=0, max=2**32, system='sage'):
157157
t := Cputime();
158158
K := Kernel(A);
159159
s := Cputime(t);
160-
""" % (n,min,max)
160+
""" % (n, min, max)
161161
if verbose:
162162
print(code)
163163
magma.eval(code)
@@ -197,7 +197,7 @@ def charpoly_ZZ(n=100, min=0, max=9, system='sage'):
197197
t := Cputime();
198198
K := CharacteristicPolynomial(A);
199199
s := Cputime(t);
200-
""" % (n,min,max)
200+
""" % (n, min, max)
201201
if verbose:
202202
print(code)
203203
magma.eval(code)
@@ -237,7 +237,7 @@ def rank_ZZ(n=700, min=0, max=9, system='sage'):
237237
t := Cputime();
238238
K := Rank(A);
239239
s := Cputime(t);
240-
""" % (n,min,max)
240+
""" % (n, min, max)
241241
if verbose:
242242
print(code)
243243
magma.eval(code)
@@ -277,7 +277,7 @@ def rank2_ZZ(n=400, min=0, max=2**64, system='sage'):
277277
t := Cputime();
278278
K := Rank(A);
279279
s := Cputime(t);
280-
""" % (n,min,max)
280+
""" % (n, min, max)
281281
if verbose:
282282
print(code)
283283
magma.eval(code)
@@ -319,7 +319,7 @@ def smithform_ZZ(n=128, min=0, max=9, system='sage'):
319319
t := Cputime();
320320
K := ElementaryDivisors(A);
321321
s := Cputime(t);
322-
""" % (n,min,max)
322+
""" % (n, min, max)
323323
if verbose:
324324
print(code)
325325
magma.eval(code)
@@ -365,7 +365,7 @@ def matrix_multiply_ZZ(n=300, min=-9, max=9, system='sage', times=1):
365365
K := A * B;
366366
end for;
367367
s := Cputime(t);
368-
""" % (n,min,max,times)
368+
""" % (n, min, max, times)
369369
if verbose:
370370
print(code)
371371
magma.eval(code)
@@ -413,7 +413,7 @@ def matrix_add_ZZ(n=200, min=-9, max=9, system='sage', times=50):
413413
K := A + B;
414414
end for;
415415
s := Cputime(t);
416-
""" % (n,min,max,times)
416+
""" % (n, min, max, times)
417417
if verbose:
418418
print(code)
419419
magma.eval(code)
@@ -476,7 +476,7 @@ def det_ZZ(n=200, min=1, max=100, system='sage'):
476476
t := Cputime();
477477
d := Determinant(A);
478478
s := Cputime(t);
479-
""" % (n,min,max)
479+
""" % (n, min, max)
480480
if verbose:
481481
print(code)
482482
magma.eval(code)
@@ -565,7 +565,7 @@ def vecmat_ZZ(n=300, min=-9, max=9, system='sage', times=200):
565565
K := v * A;
566566
end for;
567567
s := Cputime(t);
568-
""" % (n,min,max,times)
568+
""" % (n, min, max, times)
569569
if verbose:
570570
print(code)
571571
magma.eval(code)
@@ -950,7 +950,7 @@ def echelon_QQ(n=100, min=0, max=9, system='sage'):
950950
t := Cputime();
951951
K := EchelonForm(A);
952952
s := Cputime(t);
953-
""" % (n,min,max)
953+
""" % (n, min, max)
954954
if verbose:
955955
print(code)
956956
magma.eval(code)
@@ -991,7 +991,7 @@ def inverse_QQ(n=100, min=0, max=9, system='sage'):
991991
t := Cputime();
992992
K := A^(-1);
993993
s := Cputime(t);
994-
""" % (n,min,max)
994+
""" % (n, min, max)
995995
if verbose:
996996
print(code)
997997
magma.eval(code)
@@ -1207,7 +1207,7 @@ def nullspace_RR(n=300, min=0, max=10, system='sage'):
12071207
t := Cputime();
12081208
K := Kernel(A);
12091209
s := Cputime(t);
1210-
""" % (n,min,max)
1210+
""" % (n, min, max)
12111211
if verbose:
12121212
print(code)
12131213
magma.eval(code)

src/sage/matrix/constructor.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
General matrix Constructor and display options
33
"""
44

5-
#*****************************************************************************
5+
# ***************************************************************************
66
# Copyright (C) 2005 William Stein <wstein@gmail.com>
77
# Copyright (C) 2016 Jeroen Demeyer <J.Demeyer@UGent.be>
88
#
@@ -11,7 +11,7 @@ General matrix Constructor and display options
1111
# the Free Software Foundation, either version 2 of the License, or
1212
# (at your option) any later version.
1313
# http://www.gnu.org/licenses/
14-
#*****************************************************************************
14+
# ***************************************************************************
1515

1616
from sage.matrix.args cimport MatrixArgs
1717
from sage.structure.global_options import GlobalOptions

src/sage/matrix/echelon_matrix.pyx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,33 +105,33 @@ def reduced_echelon_matrix_iterator(K, k, n, bint sparse=False, bint copy=True,
105105
sage: all(a.is_immutable() and a.echelon_form() == a for a in it)
106106
True
107107
"""
108-
cdef Matrix m0,m,mm
108+
cdef Matrix m0, m, mm
109109
cdef Py_ssize_t i
110110
n = int(n)
111111
k = int(k)
112112

113113
if n < k:
114114
raise NotImplementedError("echelon matrix with fewer rows than columns "
115-
"i.e. not full rank) are not implemented")
115+
"i.e. not full rank) are not implemented")
116116

117117
from sage.matrix.matrix_space import MatrixSpace
118-
from itertools import combinations,product
118+
from itertools import combinations, product
119119

120120
copy = copy or set_immutable
121121

122-
m0 = MatrixSpace(K,k,n,sparse=sparse)()
122+
m0 = MatrixSpace(K, k, n, sparse=sparse)()
123123
Klist = list(K)
124124
K1 = K.one()
125125

126126
# First, we select which columns will be pivots:
127-
for pivots in combinations(range(n),k):
127+
for pivots in combinations(range(n), k):
128128
m = m0.__copy__()
129129
free_positions = []
130130
for i in range(k):
131-
m[i,pivots[i]] = K1
132-
for j in range(pivots[i]+1,n):
131+
m[i, pivots[i]] = K1
132+
for j in range(pivots[i]+1, n):
133133
if j not in pivots:
134-
free_positions.append((i,j))
134+
free_positions.append((i, j))
135135

136136
# Next, we fill in those entries that are not
137137
# determined by the echelon form alone:
@@ -142,9 +142,9 @@ def reduced_echelon_matrix_iterator(K, k, n, bint sparse=False, bint copy=True,
142142

143143
if copy:
144144
mm = m.__copy__()
145-
mm.cache('pivots',pivots)
146-
mm.cache('rank',k)
147-
mm.cache('in_echelon_form',True)
145+
mm.cache('pivots', pivots)
146+
mm.cache('rank', k)
147+
mm.cache('in_echelon_form', True)
148148
if set_immutable:
149149
mm.set_immutable()
150150
yield mm

src/sage/matrix/matrix_cyclo_dense.pxd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
1111
cdef int _degree
1212
cdef int _n
1313

14-
cdef _randomize_rational_column_unsafe(Matrix_cyclo_dense self,
14+
cdef _randomize_rational_column_unsafe(
15+
Matrix_cyclo_dense self,
1516
Py_ssize_t col, mpz_t nump1, mpz_t denp1, distribution=?)

src/sage/matrix/matrix_double_sparse.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ cdef class Matrix_double_sparse(Matrix_generic_sparse):
176176
sage: (B.cholesky() - L).norm(1) < 1e-10 # needs scipy
177177
True
178178
"""
179-
cdef Matrix L # output matrix
179+
cdef Matrix L # output matrix
180180

181181
L = self.fetch('cholesky')
182182
if L is not None:

src/sage/matrix/matrix_generic_sparse.pyx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,14 @@ cdef class Matrix_generic_sparse(matrix_sparse.Matrix_sparse):
191191
cdef set_unsafe(self, Py_ssize_t i, Py_ssize_t j, value):
192192
if not value:
193193
try:
194-
del self._entries[(i,j)]
194+
del self._entries[(i, j)]
195195
except KeyError:
196196
pass
197197
else:
198-
self._entries[(i,j)] = value
198+
self._entries[(i, j)] = value
199199

200200
cdef get_unsafe(self, Py_ssize_t i, Py_ssize_t j):
201-
return self._entries.get((i,j), self._zero)
201+
return self._entries.get((i, j), self._zero)
202202

203203
cdef copy_from_unsafe(self, Py_ssize_t iDst, Py_ssize_t jDst, src, Py_ssize_t iSrc, Py_ssize_t jSrc):
204204
r"""
@@ -239,10 +239,10 @@ cdef class Matrix_generic_sparse(matrix_sparse.Matrix_sparse):
239239
[ 0 2]
240240
"""
241241
cdef Matrix_generic_sparse _src = <Matrix_generic_sparse>src
242-
if (iSrc,jSrc) in _src._entries:
243-
self._entries[(iDst,jDst)] = _src._entries.get((iSrc, jSrc), _src._zero)
244-
elif (iDst,jDst) in self._entries:
245-
del self._entries[(iDst,jDst)]
242+
if (iSrc, jSrc) in _src._entries:
243+
self._entries[(iDst, jDst)] = _src._entries.get((iSrc, jSrc), _src._zero)
244+
elif (iDst, jDst) in self._entries:
245+
del self._entries[(iDst, jDst)]
246246

247247
cdef bint get_is_zero_unsafe(self, Py_ssize_t i, Py_ssize_t j) except -1:
248248
"""
@@ -256,7 +256,7 @@ cdef class Matrix_generic_sparse(matrix_sparse.Matrix_sparse):
256256
[0 1 1 1]
257257
[1 1 1 0]
258258
"""
259-
return (i,j) not in self._entries
259+
return (i, j) not in self._entries
260260

261261
def _pickle(self):
262262
version = 0
@@ -392,11 +392,11 @@ cdef class Matrix_generic_sparse(matrix_sparse.Matrix_sparse):
392392
Return all entries of ``self`` as a list of numbers of rows times
393393
number of columns entries.
394394
"""
395-
cdef Py_ssize_t i,j
395+
cdef Py_ssize_t i, j
396396
cdef list v = self.fetch('list')
397397
if v is None:
398398
v = [self._zero]*(self._nrows * self._ncols)
399-
for (i,j), x in self._entries.items():
399+
for (i, j), x in self._entries.items():
400400
v[i*self._ncols + j] = x
401401
self.cache('list', v)
402402
return v

src/sage/matrix/matrix_integer_dense.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ cdef class Matrix_integer_dense(Matrix_dense):
2424

2525
# HNF Modn
2626
cdef int _hnf_modn(Matrix_integer_dense self, Matrix_integer_dense res,
27-
unsigned int det) except -1
27+
unsigned int det) except -1
2828
cdef int* _hnf_modn_impl(Matrix_integer_dense self, unsigned int det,
29-
Py_ssize_t nrows, Py_ssize_t ncols) except NULL
29+
Py_ssize_t nrows, Py_ssize_t ncols) except NULL
3030

3131
cdef Matrix_integer_dense _new(self, Py_ssize_t nrows, Py_ssize_t ncols)
3232

src/sage/matrix/matrix_modn_dense_double.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,3 @@ cdef class Matrix_modn_dense_double(Matrix_modn_dense_template):
216216
"""
217217
cdef Matrix_modn_dense_double _src = <Matrix_modn_dense_double>src
218218
self._matrix[iDst][jDst] = _src._matrix[iSrc][jSrc]
219-

0 commit comments

Comments
 (0)