Skip to content

Commit d49fe12

Browse files
author
Release Manager
committed
gh-40031: fix E228 in pyx in matrix just adding spaces aroung modulo where missing ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40031 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents c5c7d0b + 31a1892 commit d49fe12

12 files changed

+111
-98
lines changed

src/sage/matrix/matrix2.pyx

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,13 +1545,11 @@ cdef class Matrix(Matrix1):
15451545
m = self._nrows
15461546
n = self._ncols
15471547
if not m <= n:
1548-
raise ValueError("must have m <= n, but m (=%s) and n (=%s)"%(m, n))
1548+
raise ValueError(f"must have m <= n, but m (={m}) and n (={n})")
15491549

15501550
for r from 1 <= r < m+1:
15511551
lst = _choose(n, r)
1552-
tmp = []
1553-
for cols in lst:
1554-
tmp.append(self.prod_of_row_sums(cols))
1552+
tmp = [self.prod_of_row_sums(cols) for cols in lst]
15551553
s = sum(tmp)
15561554
# sn = (-1)^(m-r)
15571555
if (m - r) % 2 == 0:
@@ -3682,7 +3680,7 @@ cdef class Matrix(Matrix1):
36823680
H = self.change_ring(K)
36833681
H.hessenbergize()
36843682
except TypeError as msg:
3685-
raise TypeError("%s\nHessenberg form only possible for matrices over a field"%msg)
3683+
raise TypeError("%s\nHessenberg form only possible for matrices over a field" % msg)
36863684
else:
36873685
H = self.__copy__()
36883686
H.hessenbergize()
@@ -5753,7 +5751,7 @@ cdef class Matrix(Matrix1):
57535751
return X, Y
57545752
return X
57555753
else:
5756-
raise ValueError("no algorithm '%s'"%algorithm)
5754+
raise ValueError("no algorithm '%s'" % algorithm)
57575755

57585756
def _decomposition_spin_generic(self, is_diagonalizable=False):
57595757
r"""
@@ -5816,14 +5814,16 @@ cdef class Matrix(Matrix1):
58165814
v = h.list()
58175815

58185816
while len(S) < tries:
5819-
t = verbose('%s-spinning %s-th random vector'%(num_iterates, len(S)), level=2, caller_name='generic spin decomp')
5817+
t = verbose('%s-spinning %s-th random vector' % (num_iterates, len(S)),
5818+
level=2, caller_name='generic spin decomp')
58205819
S.append(self.iterates(V.random_element(), num_iterates))
5821-
verbose('done spinning', level=2, t=t, caller_name='generic spin decomp')
5820+
verbose('done spinning',
5821+
level=2, t=t, caller_name='generic spin decomp')
58225822

58235823
for j in range(0 if W is None else W.nrows() // g.degree(), len(S)):
58245824
# Compute one element of the kernel of g(A)**m.
5825-
t = verbose('compute element of kernel of g(A), for g of degree %s'%g.degree(), level=2,
5826-
caller_name='generic spin decomp')
5825+
t = verbose('compute element of kernel of g(A), for g of degree %s' % g.degree(),
5826+
level=2, caller_name='generic spin decomp')
58275827
w = S[j].linear_combination_of_rows(h.list())
58285828
t = verbose('done computing element of kernel of g(A)', t=t, level=2, caller_name='generic spin decomp')
58295829

@@ -5842,7 +5842,7 @@ cdef class Matrix(Matrix1):
58425842
verbose('computed row space', level=2, t=t, caller_name='generic spin decomp')
58435843
break
58445844
else:
5845-
verbose('we have not yet generated all the kernel (rank so far=%s, target rank=%s)'%(
5845+
verbose('we have not yet generated all the kernel (rank so far=%s, target rank=%s)' % (
58465846
W.rank(), m*g.degree()), level=2, caller_name='generic spin decomp')
58475847
tries += 1
58485848
if tries > 1000*m: # avoid an insanely long infinite loop
@@ -5878,12 +5878,13 @@ cdef class Matrix(Matrix1):
58785878
return decomp_seq([(V, m==1)])
58795879
F.sort()
58805880
for g, m in f.factor():
5881-
t = verbose('decomposition -- Computing g(self) for an irreducible factor g of degree %s'%g.degree(), level=2)
5881+
t = verbose('decomposition -- Computing g(self) for an irreducible factor g of degree %s' % g.degree(), level=2)
58825882
if is_diagonalizable:
58835883
B = g(self)
58845884
else:
58855885
B = g(self)
5886-
t2 = verbose('decomposition -- raising g(self) to the power %s'%m, level=2)
5886+
t2 = verbose('decomposition -- raising g(self) to the power %s' % m,
5887+
level=2)
58875888
B = B ** m
58885889
verbose('done powering', level=2, t=t2)
58895890
t = verbose('decomposition -- done computing g(self)', level=2, t=t)
@@ -5974,7 +5975,7 @@ cdef class Matrix(Matrix1):
59745975
if not self.is_square():
59755976
raise ArithmeticError("self must be a square matrix")
59765977
if M.base_ring() != self.base_ring():
5977-
raise ArithmeticError("base rings must be the same, but self is over %s and module is over %s"%(
5978+
raise ArithmeticError("base rings must be the same, but self is over %s and module is over %s" % (
59785979
self.base_ring(), M.base_ring()))
59795980
if M.degree() != self.ncols():
59805981
raise ArithmeticError("M must be a subspace of an %s-dimensional space" % self.ncols())
@@ -5991,7 +5992,7 @@ cdef class Matrix(Matrix1):
59915992
sum_dim = sum([A.dimension() for A, _ in D])
59925993
assert sum_dim == M.dimension(), \
59935994
"bug in decomposition; " + \
5994-
"the sum of the dimensions (=%s) of the factors must equal the dimension (%s) of the acted on space:\nFactors found: %s\nSpace: %s"%(sum_dim, M.dimension(), D, M)
5995+
"the sum of the dimensions (=%s) of the factors must equal the dimension (%s) of the acted on space:\nFactors found: %s\nSpace: %s" % (sum_dim, M.dimension(), D, M)
59955996

59965997
# 3. Lift decomposition to subspaces of ambient vector space.
59975998
# Each basis vector for an element of D defines a linear
@@ -8179,7 +8180,7 @@ cdef class Matrix(Matrix1):
81798180
try:
81808181
a, d, p = self._echelon_form_PID()
81818182
except TypeError as msg:
8182-
raise NotImplementedError("%s\nechelon form over %s not yet implemented"%(msg, self.base_ring()))
8183+
raise NotImplementedError("%s\nechelon form over %s not yet implemented" % (msg, self.base_ring()))
81838184

81848185
for c from 0 <= c < self.ncols():
81858186
for r from 0 <= r < self.nrows():
@@ -8383,7 +8384,7 @@ cdef class Matrix(Matrix1):
83838384
kwds['algorithm'] = algorithm
83848385
return self._echelonize_ring(**kwds)
83858386
except ArithmeticError as msg:
8386-
raise NotImplementedError("%s\nEchelon form not implemented over '%s'."%(msg, basring))
8387+
raise NotImplementedError("%s\nEchelon form not implemented over '%s'." % (msg, basring))
83878388

83888389
def echelon_form(self, algorithm='default', cutoff=0, **kwds):
83898390
r"""
@@ -9368,7 +9369,8 @@ cdef class Matrix(Matrix1):
93689369
[ 0 0 0 0]
93699370
[ 0 0 0 0]
93709371
"""
9371-
tm = verbose('strassen echelon of %s x %s matrix'%(self._nrows, self._ncols), level=2)
9372+
tm = verbose('strassen echelon of %s x %s matrix' % (self._nrows, self._ncols),
9373+
level=2)
93729374

93739375
self.check_mutability()
93749376

@@ -9646,7 +9648,7 @@ cdef class Matrix(Matrix1):
96469648
"""
96479649
if self._subdivisions is None:
96489650
self._subdivisions = ([0, self._nrows], [0, self._ncols])
9649-
key = "subdivision %s %s"%(i, j)
9651+
key = "subdivision %s %s" % (i, j)
96509652
sd = self.fetch(key)
96519653
if sd is None:
96529654
sd = self[self._subdivisions[0][i]:self._subdivisions[0][i+1],
@@ -9694,10 +9696,10 @@ cdef class Matrix(Matrix1):
96949696
if not i and not j:
96959697
return self[x, y]
96969698
else:
9697-
raise IndexError("No such submatrix %s, %s"%(i, j))
9699+
raise IndexError("No such submatrix %s, %s" % (i, j))
96989700
if x >= self._subdivisions[0][i+1]-self._subdivisions[0][i] or \
96999701
y >= self._subdivisions[1][j+1]-self._subdivisions[1][j]:
9700-
raise IndexError("Submatrix %s,%s has no entry %s,%s"%(i, j, x, y))
9702+
raise IndexError("Submatrix %s,%s has no entry %s,%s" % (i, j, x, y))
97019703
return self[self._subdivisions[0][i] + x, self._subdivisions[1][j] + y]
97029704

97039705
def _subdivide_on_augment(self, left, right):
@@ -10875,7 +10877,7 @@ cdef class Matrix(Matrix1):
1087510877
raise ValueError("self must be a square matrix")
1087610878

1087710879
A = self.charpoly().shift(-1)(self)
10878-
return A if n%2 else -A
10880+
return A if n % 2 else -A
1087910881

1088010882
def QR(self, full=True):
1088110883
r"""

src/sage/matrix/matrix_cyclo_dense.pyx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
12681268
sage: Matrix(CyclotomicField(10),0).charpoly()
12691269
1
12701270
"""
1271-
key = 'charpoly-%s-%s'%(algorithm,proof)
1271+
key = 'charpoly-%s-%s' % (algorithm, proof)
12721272
f = self.fetch(key)
12731273
if f is not None:
12741274
return f.change_variable_name(var)
@@ -1611,7 +1611,7 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
16111611
sage: a == b # long time (depends on previous)
16121612
True
16131613
"""
1614-
key = 'echelon_form-%s'%algorithm
1614+
key = 'echelon_form-%s' % algorithm
16151615
E = self.fetch(key)
16161616
if E is not None:
16171617
return E
@@ -1767,10 +1767,12 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
17671767
# on a few more primes, and try again.
17681768

17691769
num_primes += echelon_primes_increment
1770-
verbose("rational reconstruction failed, trying with %s primes"%num_primes, level=echelon_verbose_level)
1770+
verbose("rational reconstruction failed, trying with %s primes" % num_primes,
1771+
level=echelon_verbose_level)
17711772
continue
17721773

1773-
verbose("rational reconstruction succeeded with %s primes!"%num_primes, level=echelon_verbose_level)
1774+
verbose("rational reconstruction succeeded with %s primes!" % num_primes,
1775+
level=echelon_verbose_level)
17741776

17751777
if ((res * res.denominator()).coefficient_bound() *
17761778
self.coefficient_bound() * self.ncols()) > prod:
@@ -1783,7 +1785,8 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
17831785
level=echelon_verbose_level)
17841786
continue
17851787

1786-
verbose("found echelon form with %s primes, whose product is %s"%(num_primes, prod), level=echelon_verbose_level)
1788+
verbose("found echelon form with %s primes, whose product is %s" % (num_primes, prod),
1789+
level=echelon_verbose_level)
17871790
self.cache('pivots', max_pivots)
17881791
return res
17891792

src/sage/matrix/matrix_generic_sparse.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ cdef class Matrix_generic_sparse(matrix_sparse.Matrix_sparse):
233233
self._entries = data
234234
self._zero = self._base_ring(0)
235235
else:
236-
raise RuntimeError("unknown matrix version (=%s)"%version)
236+
raise RuntimeError(f"unknown matrix version (={version})")
237237

238238
########################################################################
239239
# LEVEL 2 functionality

src/sage/matrix/matrix_gf2e_dense.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ cdef class Matrix_gf2e_dense(matrix_dense.Matrix_dense):
930930
self._echelon_in_place(algorithm='classical')
931931

932932
else:
933-
raise ValueError("No algorithm '%s'."%algorithm)
933+
raise ValueError("No algorithm '%s'." % algorithm)
934934

935935
self.cache('in_echelon_form',True)
936936
self.cache('rank', r)
@@ -1327,16 +1327,16 @@ cdef class Matrix_gf2e_dense(matrix_dense.Matrix_dense):
13271327
cdef int highc = col + ncols
13281328

13291329
if row < 0:
1330-
raise TypeError("Expected row >= 0, but got %d instead."%row)
1330+
raise TypeError("Expected row >= 0, but got %d instead." % row)
13311331

13321332
if col < 0:
1333-
raise TypeError("Expected col >= 0, but got %d instead."%col)
1333+
raise TypeError("Expected col >= 0, but got %d instead." % col)
13341334

13351335
if highc > self._entries.ncols:
1336-
raise TypeError("Expected highc <= self.ncols(), but got %d > %d instead."%(highc, self._entries.ncols))
1336+
raise TypeError("Expected highc <= self.ncols(), but got %d > %d instead." % (highc, self._entries.ncols))
13371337

13381338
if highr > self._entries.nrows:
1339-
raise TypeError("Expected highr <= self.nrows(), but got %d > %d instead."%(highr, self._entries.nrows))
1339+
raise TypeError("Expected highr <= self.nrows(), but got %d > %d instead." % (highr, self._entries.nrows))
13401340

13411341
cdef Matrix_gf2e_dense A = self.new_matrix(nrows=nrows, ncols=ncols)
13421342
if ncols == 0 or nrows == 0:

src/sage/matrix/matrix_gfpn_dense.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -740,44 +740,44 @@ cdef class Matrix_gfpn_dense(Matrix_dense):
740740
MPB += 1
741741
tmp *= fl
742742
O = (fl**MPB)
743-
if nc%MPB:
743+
if nc % MPB:
744744
for i in range(nr):
745745
y = <unsigned char*>x
746746
for j in range(FfCurrentRowSizeIo-1):
747-
y[j] = RandState.c_random()%O
747+
y[j] = RandState.c_random() % O
748748
sig_check()
749-
for j in range(nc-(nc%MPB), nc):
750-
FfInsert(x, j, FfFromInt( (RandState.c_random()%fl) ))
749+
for j in range(nc-(nc % MPB), nc):
750+
FfInsert(x, j, FfFromInt( (RandState.c_random() % fl) ))
751751
sig_check()
752752
FfStepPtr(&(x))
753753
else:
754754
for i in range(nr):
755755
y = <unsigned char*>x
756756
for j in range(FfCurrentRowSizeIo):
757-
y[j] = RandState.c_random()%O
757+
y[j] = RandState.c_random() % O
758758
sig_check()
759759
FfStepPtr(&(x))
760760
else:
761761
for i in range(nr):
762762
for j in range(nc):
763763
if RandState.c_rand_double() < density:
764-
FfInsert(x, j, FfFromInt( (RandState.c_random()%fl) ))
764+
FfInsert(x, j, FfFromInt( (RandState.c_random() % fl) ))
765765
sig_check()
766766
FfStepPtr(&(x))
767767
else:
768768
if density == 1:
769769
fl -= 1
770770
for i in range(nr):
771771
for j in range(nc):
772-
FfInsert(x, j, FfFromInt( (RandState.c_random()%fl)+1 ))
772+
FfInsert(x, j, FfFromInt( (RandState.c_random() % fl)+1 ))
773773
sig_check()
774774
FfStepPtr(&(x))
775775
else:
776776
fl -= 1
777777
for i in range(nr):
778778
for j in range(nc):
779779
if RandState.c_rand_double() < density:
780-
FfInsert(x, j, FfFromInt( (RandState.c_random()%fl)+1 ))
780+
FfInsert(x, j, FfFromInt( (RandState.c_random() % fl)+1 ))
781781
sig_check()
782782
FfStepPtr(&(x))
783783

0 commit comments

Comments
 (0)