Skip to content

Commit 5272959

Browse files
author
Release Manager
committed
gh-35772: getting rid of many uses of xrange in pyx files <!-- Please provide a concise, informative and self-explanatory title. --> <!-- Don't put issue numbers in the title. Put it in the Description below. --> <!-- For example, instead of "Fixes #12345", use "Add a new method to multiply two integers" --> ### 📚 Description this is replacing `xrange` by `range` in many `pyx` files, where it has the exact same meaning (those are remnants of our py2 history) <!-- Describe your changes here in detail. --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35772 Reported by: Frédéric Chapoton Reviewer(s): Matthias Köppe
2 parents 361ba99 + 99b44f2 commit 5272959

File tree

23 files changed

+123
-124
lines changed

23 files changed

+123
-124
lines changed

src/sage/calculus/interpolators.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,21 @@ cdef class CCSpline:
225225
cdef int N, i, k
226226
N = len(pts)
227227
yvec = np.zeros(N, dtype=np.complex128)
228-
for i in xrange(N):
228+
for i in range(N):
229229
yvec[i] = 3 * (pts[(i - 1) % N] - 2*pts[i] + pts[(i + 1) % N])
230230
bmat = np.zeros([N, N], dtype=np.complex128)
231-
for i in xrange(N):
231+
for i in range(N):
232232
bmat[i, i] = 4
233233
bmat[(i - 1) % N, i] = 1
234234
bmat[(i + 1) % N, i] = 1
235235
bvec = (np.linalg.solve(bmat, yvec))
236236
cvec = np.zeros(N, dtype=np.complex128)
237-
for i in xrange(N):
237+
for i in range(N):
238238
cvec[i] = (pts[(i + 1) % N] - pts[i] - 1.0/3.0 *
239239
bvec[(i + 1) % N] - 2./3. * bvec[i])
240240
dvec = np.array(pts, dtype=np.complex128)
241241
avec = np.zeros(N, dtype=np.complex128)
242-
for i in xrange(N):
242+
for i in range(N):
243243
avec[i] = 1.0/3.0 * (bvec[(i + 1) % N] - bvec[i])
244244
self.avec = avec
245245
self.bvec = bvec

src/sage/calculus/riemann.pyx

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ cdef class Riemann_Map:
233233
self.tk = np.array(np.arange(N) * TWOPI / N + 0.001 / N,
234234
dtype=FLOAT)
235235
self.tk2 = np.zeros(N + 1, dtype=FLOAT)
236-
for i in xrange(N):
236+
for i in range(N):
237237
self.tk2[i] = self.tk[i]
238238
self.tk2[N] = TWOPI
239239
self.B = len(fs) # number of boundaries of the figure
@@ -246,14 +246,14 @@ cdef class Riemann_Map:
246246
dtype=COMPLEX)
247247
# Find the points on the boundaries and their derivatives.
248248
if self.exterior:
249-
for k in xrange(self.B):
250-
for i in xrange(N):
249+
for k in range(self.B):
250+
for i in range(N):
251251
fk = fs[k](self.tk[N-i-1])
252252
cps[k, i] = complex(1/fk)
253253
dps[k, i] = complex(1/fk**2*fprimes[k](self.tk[N-i-1]))
254254
else:
255-
for k in xrange(self.B):
256-
for i in xrange(N):
255+
for k in range(self.B):
256+
for i in range(N):
257257
cps[k, i] = complex(fs[k](self.tk[i]))
258258
dps[k, i] = complex(fprimes[k](self.tk[i]))
259259
if self.exterior:
@@ -327,7 +327,7 @@ cdef class Riemann_Map:
327327
(normalized_dp[t]/(cp-cp[t])).conjugate())
328328
for t in np.arange(NB)], dtype=np.complex128)
329329
np.seterr(divide=errdivide,invalid=errinvalid) # resets the error handling
330-
for i in xrange(NB):
330+
for i in range(NB):
331331
K[i, i] = 1
332332
# Nystrom Method for solving 2nd kind integrals
333333
phi = np.linalg.solve(K, g) / NB * TWOPI
@@ -339,22 +339,22 @@ cdef class Riemann_Map:
339339
# regions.
340340
if B != 1:
341341
theta_array = np.zeros([1, NB])
342-
for i in xrange(NB):
342+
for i in range(NB):
343343
theta_array[0, i] = phase(-I * np.power(phi[i], 2) * dp[i])
344344
self.theta_array = np.concatenate(
345345
[theta_array.reshape([B, N]), np.zeros([B, 1])], axis=1)
346-
for k in xrange(B):
346+
for k in range(B):
347347
self.theta_array[k, N] = self.theta_array[k, 0] + TWOPI
348348
# Finding the theta correspondence using abs. Well behaved, but
349349
# doesn't work on multiply connected domains.
350350
else:
351351
phi2 = phi.reshape([self.B, N])
352352
theta_array = np.zeros([B, N + 1], dtype=np.float64)
353-
for k in xrange(B):
353+
for k in range(B):
354354
phik = phi2[k]
355355
saa = (np.dot(abs(phi), abs(phi))) * TWOPI / NB
356356
theta_array[k, 0] = 0
357-
for i in xrange(1, N):
357+
for i in range(1, N):
358358
theta_array[k, i] = (
359359
theta_array[k, i - 1] +
360360
((TWOPI / NB * TWOPI *
@@ -368,7 +368,7 @@ cdef class Riemann_Map:
368368
t0 = theta_array[k, tmax] + phase(phimax)
369369
else:
370370
t0 = theta_array[k, tmax] - phase(phimax)
371-
for i in xrange(N):
371+
for i in range(N):
372372
theta_array[k, i] = theta_array[k, i] - t0
373373
theta_array[k, N] = TWOPI + theta_array[k, 0]
374374
self.theta_array = theta_array
@@ -432,7 +432,7 @@ cdef class Riemann_Map:
432432
cdef int k, B
433433
if boundary < 0:
434434
temptk = self.tk
435-
for i in xrange(self.B - 1):
435+
for i in range(self.B - 1):
436436
temptk = np.concatenate([temptk, self.tk])
437437
if absolute_value:
438438
return np.column_stack(
@@ -504,7 +504,7 @@ cdef class Riemann_Map:
504504
"""
505505
if boundary < 0:
506506
temptk = self.tk2
507-
for i in xrange(self.B - 1):
507+
for i in range(self.B - 1):
508508
temptk = np.concatenate([temptk, self.tk2])
509509
return np.column_stack(
510510
[temptk, self.theta_array.flatten()]).tolist()
@@ -532,8 +532,8 @@ cdef class Riemann_Map:
532532
[self.B, N + 1], dtype=np.complex128)
533533
cdef int k, i
534534
# Lots of setup for Simpson's method of integration.
535-
for k in xrange(self.B):
536-
for i in xrange(N // 3):
535+
for k in range(self.B):
536+
for i in range(N // 3):
537537
p_vector[k, 3*i] = (2*coeff * dps[k, 3*i] *
538538
exp(I * theta_array[k, 3*i]))
539539
p_vector[k, 3*i + 1] = (3*coeff * dps[k, 3*i + 1] *
@@ -636,21 +636,21 @@ cdef class Riemann_Map:
636636
self.p_vector_inverse = np.zeros([B, N], dtype=np.complex128)
637637
# Setup for trapezoid integration because integration points are
638638
# not equally spaced.
639-
for k in xrange(B):
640-
for i in xrange(N):
639+
for k in range(B):
640+
for i in range(N):
641641
di = theta_array[k, (i + 1) % N] - theta_array[k, (i - 1) % N]
642642
if di > PI:
643643
di = di - TWOPI
644644
elif di < -PI:
645645
di = di + TWOPI
646646
self.p_vector_inverse[k, i] = di / 2
647647
self.sinalpha = np.zeros([B, N], dtype=np.float64)
648-
for k in xrange(B):
649-
for i in xrange(N):
648+
for k in range(B):
649+
for i in range(N):
650650
self.sinalpha[k, i] = sin(-theta_array[k, i])
651651
self.cosalpha = np.zeros([B, N], dtype=np.float64)
652-
for k in xrange(B):
653-
for i in xrange(N):
652+
for k in range(B):
653+
for i in range(N):
654654
self.cosalpha[k, i] = cos(-theta_array[k, i])
655655

656656
cpdef inverse_riemann_map(self, COMPLEX_T pt):
@@ -748,7 +748,7 @@ cdef class Riemann_Map:
748748
from sage.plot.all import list_plot
749749

750750
plots = list(range(self.B))
751-
for k in xrange(self.B):
751+
for k in range(self.B):
752752
# This conditional should be eliminated when the thickness/pointsize
753753
# issue is resolved later. Same for the others in plot_spiderweb().
754754
if plotjoined:
@@ -814,13 +814,13 @@ cdef class Riemann_Map:
814814
cdef np.ndarray[COMPLEX_T, ndim=2] z_values = np.empty(
815815
[y_points, x_points], dtype=np.complex128)
816816
if self.exterior:
817-
for i in xrange(x_points):
818-
for j in xrange(y_points):
817+
for i in range(x_points):
818+
for j in range(y_points):
819819
pt = 1/(xmin + 0.5*xstep + i*xstep + I*(ymin + 0.5*ystep + j*ystep))
820820
z_values[j, i] = 1/(-np.dot(p_vector,1/(pre_q_vector - pt)))
821821
else:
822-
for i in xrange(x_points):
823-
for j in xrange(y_points):
822+
for i in range(x_points):
823+
for j in range(y_points):
824824
pt = xmin + 0.5*xstep + i*xstep + I*(ymin + 0.5*ystep + j*ystep)
825825
z_values[j, i] = -np.dot(p_vector,1/(pre_q_vector - pt))
826826
return z_values, xmin, xmax, ymin, ymax
@@ -949,9 +949,9 @@ cdef class Riemann_Map:
949949
s = spline(np.column_stack([self.theta_array[0], self.tk2]).tolist())
950950
tmax = self.theta_array[0, self.N]
951951
tmin = self.theta_array[0, 0]
952-
for k in xrange(circles):
952+
for k in range(circles):
953953
temp = list(range(pts*2))
954-
for i in xrange(2*pts):
954+
for i in range(2*pts):
955955
temp[i] = self.inverse_riemann_map(
956956
(k + 1) / (circles + 1.0) * exp(I*i * TWOPI / (2*pts)))
957957
if plotjoined:
@@ -961,14 +961,14 @@ cdef class Riemann_Map:
961961
circle_list[k] = list_plot(comp_pt(temp, 1),
962962
rgbcolor=rgbcolor, pointsize=thickness)
963963
line_list = list(range(spokes))
964-
for k in xrange(spokes):
964+
for k in range(spokes):
965965
temp = list(range(pts))
966966
angle = (k*1.0) / spokes * TWOPI
967967
if angle >= tmax:
968968
angle -= TWOPI
969969
elif angle <= tmin:
970970
angle += TWOPI
971-
for i in xrange(pts - 1):
971+
for i in range(pts - 1):
972972
temp[i] = self.inverse_riemann_map(
973973
(i * 1.0) / (pts * 1.0) * exp(I * angle) * linescale)
974974
temp[pts - 1] = complex(
@@ -1238,8 +1238,8 @@ cpdef complex_to_spiderweb(np.ndarray[COMPLEX_T, ndim = 2] z_values,
12381238
spoke_angles = srange(-PI,PI+TWOPI/spokes,TWOPI/spokes)
12391239
else:
12401240
spoke_angles = []
1241-
for i in xrange(imax-2): # the d arrays are 1 smaller on each side
1242-
for j in xrange(jmax-2):
1241+
for i in range(imax-2): # the d arrays are 1 smaller on each side
1242+
for j in range(jmax-2):
12431243
z = z_values[i+1,j+1]
12441244
mag = abs(z)
12451245
arg = phase(z)
@@ -1309,9 +1309,9 @@ cpdef complex_to_rgb(np.ndarray[COMPLEX_T, ndim = 2] z_values):
13091309
dtype=FLOAT, shape=(imax, jmax, 3))
13101310

13111311
sig_on()
1312-
for i in xrange(imax):
1312+
for i in range(imax):
13131313
row = z_values[i]
1314-
for j in xrange(jmax):
1314+
for j in range(jmax):
13151315
z = row[j]
13161316
mag = abs(z)
13171317
arg = phase(z)

src/sage/coding/binary_code.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ def test_word_perms(t_limit=5.0):
205205
raise MemoryError("Error allocating memory.")
206206
from sage.misc.prandom import randint
207207
from sage.combinat.permutation import Permutations
208-
S = Permutations(list(xrange(n)))
208+
S = Permutations(list(range(n)))
209209
t = cputime()
210210
while cputime(t) < t_limit:
211-
word = [randint(0, 1) for _ in xrange(n)]
211+
word = [randint(0, 1) for _ in range(n)]
212212
cw1 = 0
213213
for j from 0 <= j < n:
214214
cw1 += (<codeword>word[j]) << (<codeword>j)
@@ -301,7 +301,7 @@ cdef WordPermutation *create_word_perm(object list_perm):
301301
word_perm.chunk_num = num_chunks
302302
words_per_chunk = 1 << chunk_size
303303
word_perm.gate = ( (<codeword>1) << chunk_size ) - 1
304-
list_perm += list(xrange(len(list_perm), chunk_size*num_chunks))
304+
list_perm += list(range(len(list_perm), chunk_size*num_chunks))
305305
word_perm.chunk_words = words_per_chunk
306306
for i from 0 <= i < num_chunks:
307307
images_i = <codeword *> sig_malloc(words_per_chunk * sizeof(codeword))
@@ -664,15 +664,15 @@ cdef codeword *expand_to_ortho_basis(BinaryCode B, int n):
664664
for j from i <= j < n:
665665
basis[j] = 0
666666
# now basis is length i
667-
perm = list(xrange(B.nrows))
667+
perm = list(range(B.nrows))
668668
perm_c = []
669669
for j from B.nrows <= j < B.ncols:
670670
if (<codeword>1 << j) & pivots:
671671
perm.append(j)
672672
else:
673673
perm_c.append(j)
674674
perm.extend(perm_c)
675-
perm.extend(list(xrange(B.ncols, n)))
675+
perm.extend(list(range(B.ncols, n)))
676676
perm_c = [0]*n
677677
for j from 0 <= j < n:
678678
perm_c[perm[j]] = j
@@ -4026,7 +4026,7 @@ cdef class BinaryCodeClassifier:
40264026

40274027

40284028
for i from 0 <= i < len(aut_gp_gens):
4029-
parent_generators[i] = create_word_perm(aut_gp_gens[i] + list(xrange(B.ncols, n)))
4029+
parent_generators[i] = create_word_perm(aut_gp_gens[i] + list(range(B.ncols, n)))
40304030

40314031
word = 0
40324032
while ortho_basis[k] & (((<codeword>1) << B.ncols) - 1):
@@ -4125,7 +4125,7 @@ cdef class BinaryCodeClassifier:
41254125
aut_B_aug = libgap(PermutationGroup([PermutationGroupElement([a+1 for a in g]) for g in aug_aut_gp_gens]))
41264126
H = libgap(aut_m).Intersection2(aut_B_aug)
41274127
rt_transversal = [[int(a) - 1 for a in g.ListPerm(n)] for g in aut_B_aug.RightTransversal(H) if not g.IsOne()]
4128-
rt_transversal.append(list(xrange(n)))
4128+
rt_transversal.append(list(range(n)))
41294129

41304130
bingo2 = 0
41314131
for coset_rep in rt_transversal:

src/sage/coding/codecan/autgroup_can_label.pyx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ def _cyclic_shift(n, p):
124124
sage: p.action(t)
125125
[0, 2, 7, 3, 1, 5, 6, 4, 8, 9]
126126
"""
127-
x = list(xrange(1, n + 1))
128-
for i in xrange(1, len(p)):
127+
x = list(range(1, n + 1))
128+
for i in range(1, len(p)):
129129
x[p[i - 1]] = p[i] + 1
130130
x[p[len(p) - 1]] = p[0] + 1
131131
return Permutation(x)
@@ -229,17 +229,17 @@ class LinearCodeAutGroupCanLabel:
229229
S = SemimonomialTransformationGroup(F, mat.ncols())
230230

231231
if P is None:
232-
P = [list(xrange(mat.ncols()))]
232+
P = [list(range(mat.ncols()))]
233233

234234
pos2P = [-1] * mat.ncols()
235-
for i in xrange(len(P)):
235+
for i in range(len(P)):
236236
P[i].sort(reverse=True)
237237
for x in P[i]:
238238
pos2P[x] = i
239239

240240
col_list = mat.columns()
241-
nz = [i for i in xrange(mat.ncols()) if not col_list[i].is_zero()]
242-
z = [(pos2P[i], i) for i in xrange(mat.ncols()) if col_list[i].is_zero()]
241+
nz = [i for i in range(mat.ncols()) if not col_list[i].is_zero()]
242+
z = [(pos2P[i], i) for i in range(mat.ncols()) if col_list[i].is_zero()]
243243
z.sort()
244244
z = [i for (p, i) in z]
245245

@@ -259,7 +259,7 @@ class LinearCodeAutGroupCanLabel:
259259
col2pos = []
260260
col2P = []
261261
for c in col_set:
262-
X = [(pos2P[y], y) for y in xrange(mat.ncols()) if col_list[y] == c ]
262+
X = [(pos2P[y], y) for y in range(mat.ncols()) if col_list[y] == c ]
263263
X.sort()
264264
col2pos.append([b for (a, b) in X ])
265265
col2P.append([a for (a, b) in X ])
@@ -272,7 +272,7 @@ class LinearCodeAutGroupCanLabel:
272272
P_refined = []
273273
p = [0]
274274
act_qty = col2P[0]
275-
for i in xrange(1, len(col_set)):
275+
for i in range(1, len(col_set)):
276276
if act_qty == col2P[i]:
277277
p.append(i)
278278
else:
@@ -357,7 +357,7 @@ class LinearCodeAutGroupCanLabel:
357357
perm = [-1] * mat.ncols()
358358
mult = [F.one()] * mat.ncols()
359359

360-
for i in xrange(len(can_col_set)):
360+
for i in range(len(can_col_set)):
361361
img = can_transp.get_perm()(i + 1)
362362
for j in col2pos[img - 1]:
363363
pos = P[ pos2P[j] ].pop()
@@ -378,7 +378,7 @@ class LinearCodeAutGroupCanLabel:
378378
self._full_autom_order *= a
379379

380380

381-
for i in xrange(len(col2P)):
381+
for i in range(len(col2P)):
382382
if len(col2P[i]) > 1:
383383
A, a = self._compute_trivial_automs(normalization,
384384
normalization_inverse, col2pos[i], col2P[i])
@@ -508,11 +508,11 @@ class LinearCodeAutGroupCanLabel:
508508
n = S.degree()
509509
A = []
510510
for g in gens:
511-
perm = list(xrange(1, n + 1))
511+
perm = list(range(1, n + 1))
512512
mult = [S.base_ring().one()] * n
513513
short_perm = g.get_perm()
514514
short_mult = g.get_v()
515-
for i in xrange(len(col2pos)):
515+
for i in range(len(col2pos)):
516516
c = col2pos[i]
517517
img_iter = iter(col2pos[short_perm(i + 1) - 1])
518518
for x in c:

src/sage/crypto/boolean_function.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ and also algebraic immunity.
1010
1111
EXAMPLES::
1212
13-
sage: R.<x>=GF(2^8,'a')[]
13+
sage: R.<x> = GF(2^8,'a')[]
1414
sage: from sage.crypto.boolean_function import BooleanFunction
1515
sage: B = BooleanFunction( x^254 ) # the Boolean function Tr(x^254)
1616
sage: B
@@ -900,7 +900,8 @@ cdef class BooleanFunction(SageObject):
900900
temp[i] = W[i]*W[i]
901901

902902
walsh_hadamard(temp, self._nvariables)
903-
self._autocorrelation = tuple([temp[i] >> self._nvariables for i in xrange(n)])
903+
self._autocorrelation = tuple([temp[i] >> self._nvariables
904+
for i in range(n)])
904905
sig_free(temp)
905906

906907
return self._autocorrelation

0 commit comments

Comments
 (0)