Skip to content

Commit 31a1892

Browse files
committed
fix E228 in pyx in matrix
1 parent 7888c42 commit 31a1892

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:
@@ -3646,7 +3644,7 @@ cdef class Matrix(Matrix1):
36463644
H = self.change_ring(K)
36473645
H.hessenbergize()
36483646
except TypeError as msg:
3649-
raise TypeError("%s\nHessenberg form only possible for matrices over a field"%msg)
3647+
raise TypeError("%s\nHessenberg form only possible for matrices over a field" % msg)
36503648
else:
36513649
H = self.__copy__()
36523650
H.hessenbergize()
@@ -5717,7 +5715,7 @@ cdef class Matrix(Matrix1):
57175715
return X, Y
57185716
return X
57195717
else:
5720-
raise ValueError("no algorithm '%s'"%algorithm)
5718+
raise ValueError("no algorithm '%s'" % algorithm)
57215719

57225720
def _decomposition_spin_generic(self, is_diagonalizable=False):
57235721
r"""
@@ -5780,14 +5778,16 @@ cdef class Matrix(Matrix1):
57805778
v = h.list()
57815779

57825780
while len(S) < tries:
5783-
t = verbose('%s-spinning %s-th random vector'%(num_iterates, len(S)), level=2, caller_name='generic spin decomp')
5781+
t = verbose('%s-spinning %s-th random vector' % (num_iterates, len(S)),
5782+
level=2, caller_name='generic spin decomp')
57845783
S.append(self.iterates(V.random_element(), num_iterates))
5785-
verbose('done spinning', level=2, t=t, caller_name='generic spin decomp')
5784+
verbose('done spinning',
5785+
level=2, t=t, caller_name='generic spin decomp')
57865786

57875787
for j in range(0 if W is None else W.nrows() // g.degree(), len(S)):
57885788
# Compute one element of the kernel of g(A)**m.
5789-
t = verbose('compute element of kernel of g(A), for g of degree %s'%g.degree(), level=2,
5790-
caller_name='generic spin decomp')
5789+
t = verbose('compute element of kernel of g(A), for g of degree %s' % g.degree(),
5790+
level=2, caller_name='generic spin decomp')
57915791
w = S[j].linear_combination_of_rows(h.list())
57925792
t = verbose('done computing element of kernel of g(A)', t=t, level=2, caller_name='generic spin decomp')
57935793

@@ -5806,7 +5806,7 @@ cdef class Matrix(Matrix1):
58065806
verbose('computed row space', level=2, t=t, caller_name='generic spin decomp')
58075807
break
58085808
else:
5809-
verbose('we have not yet generated all the kernel (rank so far=%s, target rank=%s)'%(
5809+
verbose('we have not yet generated all the kernel (rank so far=%s, target rank=%s)' % (
58105810
W.rank(), m*g.degree()), level=2, caller_name='generic spin decomp')
58115811
tries += 1
58125812
if tries > 1000*m: # avoid an insanely long infinite loop
@@ -5842,12 +5842,13 @@ cdef class Matrix(Matrix1):
58425842
return decomp_seq([(V, m==1)])
58435843
F.sort()
58445844
for g, m in f.factor():
5845-
t = verbose('decomposition -- Computing g(self) for an irreducible factor g of degree %s'%g.degree(), level=2)
5845+
t = verbose('decomposition -- Computing g(self) for an irreducible factor g of degree %s' % g.degree(), level=2)
58465846
if is_diagonalizable:
58475847
B = g(self)
58485848
else:
58495849
B = g(self)
5850-
t2 = verbose('decomposition -- raising g(self) to the power %s'%m, level=2)
5850+
t2 = verbose('decomposition -- raising g(self) to the power %s' % m,
5851+
level=2)
58515852
B = B ** m
58525853
verbose('done powering', level=2, t=t2)
58535854
t = verbose('decomposition -- done computing g(self)', level=2, t=t)
@@ -5938,7 +5939,7 @@ cdef class Matrix(Matrix1):
59385939
if not self.is_square():
59395940
raise ArithmeticError("self must be a square matrix")
59405941
if M.base_ring() != self.base_ring():
5941-
raise ArithmeticError("base rings must be the same, but self is over %s and module is over %s"%(
5942+
raise ArithmeticError("base rings must be the same, but self is over %s and module is over %s" % (
59425943
self.base_ring(), M.base_ring()))
59435944
if M.degree() != self.ncols():
59445945
raise ArithmeticError("M must be a subspace of an %s-dimensional space" % self.ncols())
@@ -5955,7 +5956,7 @@ cdef class Matrix(Matrix1):
59555956
sum_dim = sum([A.dimension() for A, _ in D])
59565957
assert sum_dim == M.dimension(), \
59575958
"bug in decomposition; " + \
5958-
"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)
5959+
"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)
59595960

59605961
# 3. Lift decomposition to subspaces of ambient vector space.
59615962
# Each basis vector for an element of D defines a linear
@@ -8143,7 +8144,7 @@ cdef class Matrix(Matrix1):
81438144
try:
81448145
a, d, p = self._echelon_form_PID()
81458146
except TypeError as msg:
8146-
raise NotImplementedError("%s\nechelon form over %s not yet implemented"%(msg, self.base_ring()))
8147+
raise NotImplementedError("%s\nechelon form over %s not yet implemented" % (msg, self.base_ring()))
81478148

81488149
for c from 0 <= c < self.ncols():
81498150
for r from 0 <= r < self.nrows():
@@ -8347,7 +8348,7 @@ cdef class Matrix(Matrix1):
83478348
kwds['algorithm'] = algorithm
83488349
return self._echelonize_ring(**kwds)
83498350
except ArithmeticError as msg:
8350-
raise NotImplementedError("%s\nEchelon form not implemented over '%s'."%(msg, basring))
8351+
raise NotImplementedError("%s\nEchelon form not implemented over '%s'." % (msg, basring))
83518352

83528353
def echelon_form(self, algorithm='default', cutoff=0, **kwds):
83538354
r"""
@@ -9332,7 +9333,8 @@ cdef class Matrix(Matrix1):
93329333
[ 0 0 0 0]
93339334
[ 0 0 0 0]
93349335
"""
9335-
tm = verbose('strassen echelon of %s x %s matrix'%(self._nrows, self._ncols), level=2)
9336+
tm = verbose('strassen echelon of %s x %s matrix' % (self._nrows, self._ncols),
9337+
level=2)
93369338

93379339
self.check_mutability()
93389340

@@ -9610,7 +9612,7 @@ cdef class Matrix(Matrix1):
96109612
"""
96119613
if self._subdivisions is None:
96129614
self._subdivisions = ([0, self._nrows], [0, self._ncols])
9613-
key = "subdivision %s %s"%(i, j)
9615+
key = "subdivision %s %s" % (i, j)
96149616
sd = self.fetch(key)
96159617
if sd is None:
96169618
sd = self[self._subdivisions[0][i]:self._subdivisions[0][i+1],
@@ -9658,10 +9660,10 @@ cdef class Matrix(Matrix1):
96589660
if not i and not j:
96599661
return self[x, y]
96609662
else:
9661-
raise IndexError("No such submatrix %s, %s"%(i, j))
9663+
raise IndexError("No such submatrix %s, %s" % (i, j))
96629664
if x >= self._subdivisions[0][i+1]-self._subdivisions[0][i] or \
96639665
y >= self._subdivisions[1][j+1]-self._subdivisions[1][j]:
9664-
raise IndexError("Submatrix %s,%s has no entry %s,%s"%(i, j, x, y))
9666+
raise IndexError("Submatrix %s,%s has no entry %s,%s" % (i, j, x, y))
96659667
return self[self._subdivisions[0][i] + x, self._subdivisions[1][j] + y]
96669668

96679669
def _subdivide_on_augment(self, left, right):
@@ -10839,7 +10841,7 @@ cdef class Matrix(Matrix1):
1083910841
raise ValueError("self must be a square matrix")
1084010842

1084110843
A = self.charpoly().shift(-1)(self)
10842-
return A if n%2 else -A
10844+
return A if n % 2 else -A
1084310845

1084410846
def QR(self, full=True):
1084510847
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)