Skip to content

Commit 6ba54bd

Browse files
author
Release Manager
committed
gh-40084: more fixes for E228 in pyx files outside of the `libs/` folder ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40084 Reported by: Frédéric Chapoton Reviewer(s): Edgar Costa
2 parents d1075d8 + 9e1a43c commit 6ba54bd

File tree

5 files changed

+60
-56
lines changed

5 files changed

+60
-56
lines changed

src/sage/coding/binary_code.pyx

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ cdef class BinaryCode:
10041004
[10101010]
10051005
"""
10061006
cdef int i, j
1007-
s = 'Binary [%d,%d] linear code, generator matrix\n'%(self.ncols, self.nrows)
1007+
s = 'Binary [%d,%d] linear code, generator matrix\n' % (self.ncols, self.nrows)
10081008
for i from 0 <= i < self.nrows:
10091009
s += '[' + self._word((<codeword> 1)<<i) + ']\n'
10101010
return s
@@ -1028,10 +1028,8 @@ cdef class BinaryCode:
10281028
Note that behavior under input which does not represent a word in
10291029
the code is unspecified (gives nonsense).
10301030
"""
1031-
s = ''
1032-
for j from 0 <= j < self.ncols:
1033-
s += '%d'%self.is_one(coords,j)
1034-
return s
1031+
return ''.join('%d' % self.is_one(coords, j)
1032+
for j in range(self.ncols))
10351033

10361034
def _is_one(self, word, col):
10371035
"""
@@ -1186,7 +1184,8 @@ cdef class BinaryCode:
11861184
if not parity:
11871185
while not combination & (1 << j): j += 1
11881186
j += 1
1189-
if j == self.nrows: break
1187+
if j == self.nrows:
1188+
break
11901189
else:
11911190
combination ^= (1 << j)
11921191
word ^= self.basis[j]
@@ -1309,22 +1308,23 @@ cdef class OrbitPartition:
13091308
"""
13101309
cdef int i
13111310
cdef int j
1312-
s = 'OrbitPartition on %d words and %d columns. Data:\n'%(self.nwords, self.ncols)
1311+
s = 'OrbitPartition on %d words and %d columns. Data:\n' % (self.nwords,
1312+
self.ncols)
13131313
# s += 'Parents::\n'
13141314
s += 'Words:\n'
13151315
for i from 0 <= i < self.nwords:
1316-
s += '%d,'%self.wd_parent[i]
1316+
s += '%d,' % self.wd_parent[i]
13171317
s = s[:-1] + '\nColumns:\n'
13181318
for j from 0 <= j < self.ncols:
1319-
s += '%d,'%self.col_parent[j]
1319+
s += '%d,' % self.col_parent[j]
13201320
# s = s[:-1] + '\n'
13211321
# s += 'Min Cell Reps::\n'
13221322
# s += 'Words:\n'
13231323
# for i from 0 <= i < self.nwords:
1324-
# s += '%d,'%self.wd_min_cell_rep[i]
1324+
# s += '%d,' % self.wd_min_cell_rep[i]
13251325
# s = s[:-1] + '\nColumns:\n'
13261326
# for j from 0 <= j < self.ncols:
1327-
# s += '%d,'%self.col_min_cell_rep[j]
1327+
# s += '%d,' % self.col_min_cell_rep[j]
13281328
return s[:-1]
13291329

13301330
def _wd_find(self, word):
@@ -1773,7 +1773,8 @@ cdef class PartitionStack:
17731773
current = ''
17741774
for k from 0 <= k < 2*self.ncols:
17751775
current = self._repr_at_k(k)
1776-
if current == last: break
1776+
if current == last:
1777+
break
17771778
s += current
17781779
last = current
17791780
return s
@@ -1985,7 +1986,7 @@ cdef class PartitionStack:
19851986
cdef int reps = (1 << self_col_ents[0]), length, word
19861987
cdef int radix = self.radix, nwords = self.nwords, ncols = self.ncols
19871988
length = 1 + nwords/radix
1988-
if nwords%radix:
1989+
if nwords % radix:
19891990
length += 1
19901991
for i from 0 <= i < length:
19911992
Omega[start+i] = 0
@@ -1995,7 +1996,7 @@ cdef class PartitionStack:
19951996
for i from 0 < i < nwords:
19961997
if self_wd_lvls[i-1] <= k:
19971998
word = self_wd_lvls[i-1]
1998-
Omega[start+1+word/radix] += (1 << word%radix)
1999+
Omega[start+1+word/radix] += (1 << word % radix)
19992000

20002001
# def _fixed_cols(self, mcrs, k): #TODO
20012002
# """
@@ -2048,13 +2049,13 @@ cdef class PartitionStack:
20482049
Phi[start] = fixed & Omega[start]
20492050
# zero out the rest of Phi
20502051
length = 1 + nwords/self.radix
2051-
if nwords%self.radix:
2052+
if nwords % self.radix:
20522053
length += 1
20532054
for i from 0 < i < length:
20542055
Phi[start+i] = 0
20552056
for i from 0 <= i < nwords:
20562057
ell = self_wd_ents[i]
2057-
Phi[start+1+ell/radix] = ((self_wd_lvls[i] <= k) << ell%radix)
2058+
Phi[start+1+ell/radix] = ((self_wd_lvls[i] <= k) << ell % radix)
20582059
for i from 0 < i < length:
20592060
Phi[i] &= Omega[i]
20602061

@@ -2125,7 +2126,8 @@ cdef class PartitionStack:
21252126
min = i - j + 1
21262127
location = j
21272128
j = i + 1
2128-
if self_col_lvls[i] == -1: break
2129+
if self_col_lvls[i] == -1:
2130+
break
21292131
i += 1
21302132
# i = 0; j = 0
21312133
# while True:
@@ -2142,13 +2144,14 @@ cdef class PartitionStack:
21422144
j = location
21432145
# zero out this level of W:
21442146
ell = 1 + nwords/radix
2145-
if nwords%radix:
2147+
if nwords % radix:
21462148
ell += 1
21472149
for i from 0 <= i < ell:
21482150
W[start+i] = 0
21492151
if min_is_col:
21502152
while True:
2151-
if self_col_lvls[j] <= k: break
2153+
if self_col_lvls[j] <= k:
2154+
break
21522155
j += 1
21532156
# j now points to the last element of the cell
21542157
i = location
@@ -2158,13 +2161,14 @@ cdef class PartitionStack:
21582161
return self_col_ents[location]
21592162
else:
21602163
while True:
2161-
if self_wd_lvls[j] <= k: break
2164+
if self_wd_lvls[j] <= k:
2165+
break
21622166
j += 1
21632167
# j now points to the last element of the cell
21642168
i = location
21652169
while i <= j:
21662170
ell = self_wd_ents[i]
2167-
W[start+1+ell/radix] ^= (1 << ell%radix)
2171+
W[start+1+ell/radix] ^= (1 << ell % radix)
21682172
i += 1
21692173
return self_wd_ents[location] ^ self.flag
21702174

@@ -3492,9 +3496,9 @@ cdef class BinaryCodeClassifier:
34923496
for i from 0 <= i < jj:
34933497
Omega[ii+i] = ~0
34943498
Phi[ii+i] = 0
3495-
if nwords%self.radix:
3499+
if nwords % self.radix:
34963500
jj += 1
3497-
# Omega[ii+jj-1] = ~((1 << nwords%self.radix) - 1)
3501+
# Omega[ii+jj-1] = ~((1 << nwords % self.radix) - 1)
34983502
# Omega stores the minimum cell representatives
34993503
i = 0
35003504
while i < ncols:
@@ -3510,18 +3514,18 @@ cdef class BinaryCodeClassifier:
35103514
while i < nwords:
35113515
j = word_gamma[i]
35123516
while j != i:
3513-
Omega[ii+1+j/jj] ^= (1<<(j%jj))
3517+
Omega[ii+1+j/jj] ^= (1<<(j % jj))
35143518
j = word_gamma[j]
35153519
i += 1
3516-
while i < nwords and not Omega[ii+1+i/jj]&(1<<(i%jj)):
3520+
while i < nwords and not Omega[ii+1+i/jj]&(1<<(i % jj)):
35173521
i += 1
35183522
# Phi stores the columns fixed by the automorphism
35193523
for i from 0 <= i < ncols:
35203524
if col_gamma[i] == i:
35213525
Phi[ii] ^= (1 << i)
35223526
for i from 0 <= i < nwords:
35233527
if word_gamma[i] == i:
3524-
Phi[ii+1+i/jj] ^= (1<<(i%jj))
3528+
Phi[ii+1+i/jj] ^= (1<<(i % jj))
35253529

35263530
# Now incorporate the automorphism into Theta
35273531
j = Theta.merge_perm(col_gamma, word_gamma)
@@ -3571,7 +3575,7 @@ cdef class BinaryCodeClassifier:
35713575
ii = self.Phi_size*l
35723576
jj = self.Phi_size*k
35733577
j = 1 + nwords/self.radix
3574-
if nwords%self.radix:
3578+
if nwords % self.radix:
35753579
j += 1
35763580
W[jj] &= Omega[ii]
35773581
for i from 0 < i < j:
@@ -3623,7 +3627,7 @@ cdef class BinaryCodeClassifier:
36233627
if v[k]&nu.flag:
36243628
ii = self.radix
36253629
i = (v[k]^nu.flag) + 1
3626-
while i < nwords and not (1 << i%ii) & W[jj+1+i/ii]:
3630+
while i < nwords and not (1 << i % ii) & W[jj+1+i/ii]:
36273631
i += 1
36283632
if i < nwords:
36293633
v[k] = i^nu.flag
@@ -3695,14 +3699,14 @@ cdef class BinaryCodeClassifier:
36953699
# intersect W[k] with each Omega[i] such that v[0]...v[k-1] is in Phi[i]
36963700
jj = self.Phi_size*self.L
36973701
iii = nwords/self.radix
3698-
if nwords%self.radix:
3702+
if nwords % self.radix:
36993703
iii += 1
37003704
for ii from 0 <= ii < iii:
37013705
Phi[jj+ii] = 0
37023706
for ii from 0 <= ii < k:
37033707
if v[ii]&nu.flag:
37043708
i = v[ii]^nu.flag
3705-
Phi[jj+1+i/self.radix] ^= (1 << i%self.radix)
3709+
Phi[jj+1+i/self.radix] ^= (1 << i % self.radix)
37063710
else:
37073711
Phi[jj] ^= (1 << v[ii])
37083712
for i from 0 <= i <= l:
@@ -3722,7 +3726,7 @@ cdef class BinaryCodeClassifier:
37223726
i = (v[k]^nu.flag)
37233727
while i < nwords:
37243728
i += 1
3725-
if (1 << i%self.radix) & W[jjj+1+i/self.radix]: break
3729+
if (1 << i % self.radix) & W[jjj+1+i/self.radix]: break
37263730
if i < nwords:
37273731
v[k] = i^nu.flag
37283732
state = 15
@@ -3852,9 +3856,9 @@ cdef class BinaryCodeClassifier:
38523856
sage: soc_iter = codes.databases.self_orthogonal_binary_codes(12, 6, 4)
38533857
sage: L = list(soc_iter)
38543858
sage: for n in range(13):
3855-
....: s = 'n=%2d : '%n
3859+
....: s = 'n=%2d : ' % n
38563860
....: for k in range(1,7):
3857-
....: s += '%3d '%len([C for C in L
3861+
....: s += '%3d ' % len([C for C in L
38583862
....: if C.length() == n and C.dimension() == k])
38593863
....: print(s)
38603864
n= 0 : 0 0 0 0 0 0
@@ -3972,7 +3976,7 @@ cdef class BinaryCodeClassifier:
39723976

39733977
while True:
39743978
if nonzero_gate & word == nonzero_gate and \
3975-
(ham_wts[word & 65535] + ham_wts[(word >> 16) & 65535])%d == 0:
3979+
(ham_wts[word & 65535] + ham_wts[(word >> 16) & 65535]) % d == 0:
39763980
temp = (word >> B.nrows) & ((<codeword>1 << k) - 1)
39773981
if not orbit_checks[temp >> log_2_radix] & ((<codeword>1) << (temp & radix_gate)):
39783982
B_aug = BinaryCode(B, word)

src/sage/groups/perm_gps/partn_ref/data_structures.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ cdef inline void SC_random_element(StabilizerChain *SC, int level, int *perm) no
529529
cdef int i, x, n = SC.degree
530530
SC_identify(perm, n)
531531
for i from level <= i < SC.base_size:
532-
x = SC.base_orbits[i][rand()%SC.orbit_sizes[i]]
532+
x = SC.base_orbits[i][rand() % SC.orbit_sizes[i]]
533533
SC_compose_up_to_base(SC, i, x, perm)
534534

535535
cdef int compute_relabeling(StabilizerChain *group,

src/sage/stats/distributions/discrete_gaussian_integer.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,10 @@ cdef class DiscreteGaussianDistributionIntegerSampler(SageObject):
344344
-3
345345
"""
346346
if sigma <= 0.0:
347-
raise ValueError("sigma must be > 0.0 but got %f"%sigma)
347+
raise ValueError("sigma must be > 0.0 but got %f" % sigma)
348348

349349
if tau < 1:
350-
raise ValueError("tau must be >= 1 but got %d"%tau)
350+
raise ValueError("tau must be >= 1 but got %d" % tau)
351351

352352
if algorithm is None:
353353
if sigma*tau <= DiscreteGaussianDistributionIntegerSampler.table_cutoff:
@@ -362,15 +362,15 @@ cdef class DiscreteGaussianDistributionIntegerSampler(SageObject):
362362
elif algorithm == "uniform+online":
363363
algorithm = DGS_DISC_GAUSS_UNIFORM_ONLINE
364364
elif algorithm == "uniform+logtable":
365-
if (c%1):
365+
if (c % 1):
366366
raise ValueError("algorithm 'uniform+logtable' requires c%1 == 0")
367367
algorithm = DGS_DISC_GAUSS_UNIFORM_LOGTABLE
368368
elif algorithm == "sigma2+logtable":
369-
if (c%1):
369+
if (c % 1):
370370
raise ValueError("algorithm 'uniform+logtable' requires c%1 == 0")
371371
algorithm = DGS_DISC_GAUSS_SIGMA2_LOGTABLE
372372
else:
373-
raise ValueError("Algorithm '%s' not supported by class 'DiscreteGaussianDistributionIntegerSampler'"%(algorithm))
373+
raise ValueError("Algorithm '%s' not supported by class 'DiscreteGaussianDistributionIntegerSampler'" % (algorithm))
374374

375375
if precision == "mp":
376376
if not isinstance(sigma, RealNumber):
@@ -397,7 +397,7 @@ cdef class DiscreteGaussianDistributionIntegerSampler(SageObject):
397397
self.sigma = RR(sigma)
398398
self.c = RR(c)
399399
else:
400-
raise ValueError("Parameter precision '%s' not supported."%precision)
400+
raise ValueError(f"Parameter precision '{precision}' not supported")
401401

402402
self.tau = Integer(tau)
403403
self.algorithm = algorithm_str

src/sage/stats/hmm/chmm.pyx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ cdef class GaussianHiddenMarkovModel(HiddenMarkovModel):
330330
sage: hmm.GaussianHiddenMarkovModel([[.1,.9],[.5,.5]], [(1,.5), (-1,3)], [.1,.9]).__repr__()
331331
'Gaussian Hidden Markov Model with 2 States\nTransition matrix:\n[0.1 0.9]\n[0.5 0.5]\nEmission parameters:\n[(1.0, 0.5), (-1.0, 3.0)]\nInitial probabilities: [0.1000, 0.9000]'
332332
"""
333-
s = "Gaussian Hidden Markov Model with %s States"%self.N
334-
s += '\nTransition matrix:\n%s'%self.transition_matrix()
335-
s += '\nEmission parameters:\n%s'%self.emission_parameters()
336-
s += '\nInitial probabilities: %s'%self.initial_probabilities()
333+
s = "Gaussian Hidden Markov Model with %s States" % self.N
334+
s += '\nTransition matrix:\n%s' % self.transition_matrix()
335+
s += '\nEmission parameters:\n%s' % self.emission_parameters()
336+
s += '\nInitial probabilities: %s' % self.initial_probabilities()
337337
return s
338338

339339
def generate_sequence(self, Py_ssize_t length, starting_state=None):
@@ -421,7 +421,7 @@ cdef class GaussianHiddenMarkovModel(HiddenMarkovModel):
421421
else:
422422
q = starting_state
423423
if q < 0 or q>= self.N:
424-
raise ValueError("starting state must be between 0 and %s"%(self.N-1))
424+
raise ValueError("starting state must be between 0 and %s" % (self.N-1))
425425

426426
states._values[0] = q
427427
obs._values[0] = self.random_sample(q, rstate)
@@ -1143,10 +1143,10 @@ cdef class GaussianMixtureHiddenMarkovModel(GaussianHiddenMarkovModel):
11431143
sage: hmm.GaussianMixtureHiddenMarkovModel([[.9,.1],[.4,.6]], [[(.4,(0,1)), (.6,(1,0.1))],[(1,(0,1))]], [.7,.3]).__repr__()
11441144
'Gaussian Mixture Hidden Markov Model with 2 States\nTransition matrix:\n[0.9 0.1]\n[0.4 0.6]\nEmission parameters:\n[0.4*N(0.0,1.0) + 0.6*N(1.0,0.1), 1.0*N(0.0,1.0)]\nInitial probabilities: [0.7000, 0.3000]'
11451145
"""
1146-
s = "Gaussian Mixture Hidden Markov Model with %s States"%self.N
1147-
s += '\nTransition matrix:\n%s'%self.transition_matrix()
1148-
s += '\nEmission parameters:\n%s'%self.emission_parameters()
1149-
s += '\nInitial probabilities: %s'%self.initial_probabilities()
1146+
s = "Gaussian Mixture Hidden Markov Model with %s States" % self.N
1147+
s += '\nTransition matrix:\n%s' % self.transition_matrix()
1148+
s += '\nEmission parameters:\n%s' % self.emission_parameters()
1149+
s += '\nInitial probabilities: %s' % self.initial_probabilities()
11501150
return s
11511151

11521152
def __reduce__(self):

src/sage/stats/hmm/hmm.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,13 @@ cdef class DiscreteHiddenMarkovModel(HiddenMarkovModel):
443443
sage: m.__repr__()
444444
'Discrete Hidden Markov Model with 2 States and 2 Emissions\nTransition matrix:\n[0.4 0.6]\n[0.1 0.9]\nEmission matrix:\n[0.1 0.9]\n[0.5 0.5]\nInitial probabilities: [0.2000, 0.8000]'
445445
"""
446-
s = "Discrete Hidden Markov Model with %s States and %s Emissions"%(
446+
s = "Discrete Hidden Markov Model with %s States and %s Emissions" % (
447447
self.N, self.n_out)
448-
s += '\nTransition matrix:\n%s'%self.transition_matrix()
449-
s += '\nEmission matrix:\n%s'%self.emission_matrix()
450-
s += '\nInitial probabilities: %s'%self.initial_probabilities()
448+
s += '\nTransition matrix:\n%s' % self.transition_matrix()
449+
s += '\nEmission matrix:\n%s' % self.emission_matrix()
450+
s += '\nInitial probabilities: %s' % self.initial_probabilities()
451451
if self._emission_symbols is not None:
452-
s += '\nEmission symbols: %s'%self._emission_symbols
452+
s += '\nEmission symbols: %s' % self._emission_symbols
453453
return s
454454

455455
def _emission_symbols_to_IntList(self, obs):
@@ -773,7 +773,7 @@ cdef class DiscreteHiddenMarkovModel(HiddenMarkovModel):
773773
else:
774774
q = starting_state
775775
if q < 0 or q >= self.N:
776-
raise ValueError("starting state must be between 0 and %s"%(self.N-1))
776+
raise ValueError("starting state must be between 0 and %s" % (self.N-1))
777777

778778
states._values[0] = q
779779
# Generate a symbol from state q

0 commit comments

Comments
 (0)