Skip to content

Commit 3e6db24

Browse files
author
Release Manager
committed
gh-36221: get rid of xrange again replace all `xrange` by `range` apparently `xrange` tends to creep in ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: #36221 Reported by: Frédéric Chapoton Reviewer(s): Matthias Köppe
2 parents 029450c + 33b3ea0 commit 3e6db24

18 files changed

+60
-62
lines changed

src/sage/cpython/_py2_random.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ def sample(self, population, k):
281281
population contains repeats, then each occurrence is a possible
282282
selection in the sample.
283283
284-
To choose a sample in a range of integers, use xrange as an argument.
284+
To choose a sample in a range of integers, use range as an argument.
285285
This is especially fast and space efficient for sampling from a
286-
large population: sample(xrange(10000000), 60)
286+
large population: sample(range(10000000), 60)
287287
"""
288288

289289
# Sampling without replacement entails tracking either potential

src/sage/geometry/integral_points.pxi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,13 +545,13 @@ cpdef rectangular_box_points(list box_min, list box_max,
545545
assert not (count_only and return_saturated)
546546
cdef int d = len(box_min)
547547
cdef int i, j
548-
cdef list diameter = sorted([ (box_max[i]-box_min[i], i) for i in range(d) ],
548+
cdef list diameter = sorted([(box_max[i]-box_min[i], i) for i in range(d)],
549549
reverse=True)
550550
cdef list diameter_value = [x[0] for x in diameter]
551551
cdef list diameter_index = [x[1] for x in diameter]
552552
553553
# Construct the inverse permutation
554-
cdef list orig_perm = list(xrange(len(diameter_index)))
554+
cdef list orig_perm = list(range(len(diameter_index)))
555555
for i, j in enumerate(diameter_index):
556556
orig_perm[j] = i
557557

src/sage/graphs/strongly_regular_db.pyx

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,25 +1070,25 @@ def is_polhill(int v, int k, int l, int mu):
10701070
# We now define the P_{i,j}. see section 6.
10711071
10721072
P = {}
1073-
P[0,1] = list(xrange((-1) + 1 , 2**(s-2)+1))
1074-
P[1,1] = list(xrange((-1) + 2**(s-2)+2 , 2**(s-1)+1))
1075-
P[2,1] = list(xrange((-1) + 2**(s-1)+2 , 2**(s-1)+2**(s-2)+1))
1076-
P[3,1] = list(xrange((-1) + 2**(s-1)+2**(s-2)+2, 2**(s)+1))
1077-
1078-
P[0,2] = list(xrange((-1) + 2**(s-2)+2 , 2**(s-1)+2))
1079-
P[1,2] = list(xrange((-1) + 2**(s-1)+3 , 2**(s-1)+2**(s-2)+2))
1080-
P[2,2] = list(xrange((-1) + 2**(s-1)+2**(s-2)+3, 2**(s)+1)) + [0]
1081-
P[3,2] = list(xrange((-1) + 2 , 2**(s-2)+1))
1082-
1083-
P[0,3] = list(xrange((-1) + 2**(s-1)+3 , 2**(s-1)+2**(s-2)+3))
1084-
P[1,3] = list(xrange((-1) + 2**(s-1)+2**(s-2)+4, 2**(s)+1)) + [0,1]
1085-
P[2,3] = list(xrange((-1) + 3 , 2**(s-2)+2))
1086-
P[3,3] = list(xrange((-1) + 2**(s-2)+3 , 2**(s-1)+2))
1087-
1088-
P[0,4] = list(xrange((-1) + 2**(s-1)+2**(s-2)+4, 2**(s)+1))
1089-
P[1,4] = list(xrange((-1) + 3 , 2**(s-2)+1)) + [2**(s-1)+1,2**(s-1)+2**(s-2)+2]
1090-
P[2,4] = list(xrange((-1) + 2**(s-2)+3 , 2**(s-1)+1)) + [2**(s-1)+2**(s-2)+1,1]
1091-
P[3,4] = list(xrange((-1) + 2**(s-1)+3 , 2**(s-1)+2**(s-2)+1)) + [2**(s-2)+1,0]
1073+
P[0,1] = list(range((-1) + 1 , 2**(s-2)+1))
1074+
P[1,1] = list(range((-1) + 2**(s-2)+2 , 2**(s-1)+1))
1075+
P[2,1] = list(range((-1) + 2**(s-1)+2 , 2**(s-1)+2**(s-2)+1))
1076+
P[3,1] = list(range((-1) + 2**(s-1)+2**(s-2)+2, 2**(s)+1))
1077+
1078+
P[0,2] = list(range((-1) + 2**(s-2)+2 , 2**(s-1)+2))
1079+
P[1,2] = list(range((-1) + 2**(s-1)+3 , 2**(s-1)+2**(s-2)+2))
1080+
P[2,2] = list(range((-1) + 2**(s-1)+2**(s-2)+3, 2**(s)+1)) + [0]
1081+
P[3,2] = list(range((-1) + 2 , 2**(s-2)+1))
1082+
1083+
P[0,3] = list(range((-1) + 2**(s-1)+3 , 2**(s-1)+2**(s-2)+3))
1084+
P[1,3] = list(range((-1) + 2**(s-1)+2**(s-2)+4, 2**(s)+1)) + [0,1]
1085+
P[2,3] = list(range((-1) + 3 , 2**(s-2)+2))
1086+
P[3,3] = list(range((-1) + 2**(s-2)+3 , 2**(s-1)+2))
1087+
1088+
P[0,4] = list(range((-1) + 2**(s-1)+2**(s-2)+4, 2**(s)+1))
1089+
P[1,4] = list(range((-1) + 3 , 2**(s-2)+1)) + [2**(s-1)+1,2**(s-1)+2**(s-2)+2]
1090+
P[2,4] = list(range((-1) + 2**(s-2)+3 , 2**(s-1)+1)) + [2**(s-1)+2**(s-2)+1,1]
1091+
P[3,4] = list(range((-1) + 2**(s-1)+3 , 2**(s-1)+2**(s-2)+1)) + [2**(s-2)+1,0]
10921092
10931093
R = {x: copy(P[x]) for x in P}
10941094
@@ -1102,10 +1102,10 @@ def is_polhill(int v, int k, int l, int mu):
11021102
11031103
# We now define the R_{i,j}. see *end* of section 6.
11041104
1105-
R[0,3] = list(xrange((-1) + 2**(s-1)+3 , 2**(s-1)+2**(s-2)+2))
1106-
R[1,3] = list(xrange((-1) + 2**(s-1)+2**(s-2)+4, 2**(s)+1)) + [0,1,2**(s-1)+2**(s-2)+2]
1107-
R[0,4] = list(xrange((-1) + 2**(s-1)+2**(s-2)+4, 2**(s)+1)) + [2**(s-1)+2**(s-2)+2]
1108-
R[1,4] = list(xrange((-1) + 3 , 2**(s-2)+1)) + [2**(s-1)+1]
1105+
R[0,3] = list(range((-1) + 2**(s-1)+3 , 2**(s-1)+2**(s-2)+2))
1106+
R[1,3] = list(range((-1) + 2**(s-1)+2**(s-2)+4, 2**(s)+1)) + [0,1,2**(s-1)+2**(s-2)+2]
1107+
R[0,4] = list(range((-1) + 2**(s-1)+2**(s-2)+4, 2**(s)+1)) + [2**(s-1)+2**(s-2)+2]
1108+
R[1,4] = list(range((-1) + 3 , 2**(s-2)+1)) + [2**(s-1)+1]
11091109
11101110
for x in R:
11111111
R[x] = [K[i] for i in R[x]]
@@ -2174,7 +2174,7 @@ def SRG_243_110_37_60():
21742174
from sage.coding.golay_code import GolayCode
21752175
M = GolayCode(GF(3), False).generator_matrix()
21762176
V = list(M.right_kernel())
2177-
g = Graph([list(xrange(len(V))), lambda x, y: (V[x] - V[y]).hamming_weight() == 9])
2177+
g = Graph([list(range(len(V))), lambda x, y: (V[x] - V[y]).hamming_weight() == 9])
21782178
g.name('Ternary Golay code')
21792179
return g
21802180

src/sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ def coset_rep(list perm=[0,1,2,3,4,5], list gens=[[1,2,3,4,5,0]]):
283283
output = get_aut_gp_and_can_lab(<void *> perm, part, n, &all_children_are_equivalent_trivial, &refine_and_return_invariant_trivial, &compare_perms, 1, group, NULL, NULL)
284284
SC_order(output.group, 0, I.value)
285285
assert I == 1
286-
r_inv = list(xrange(n))
287-
for i from 0 <= i < n:
286+
r_inv = list(range(n))
287+
for i in range(n):
288288
r_inv[output.relabeling[i]] = i
289289
label = [perm[r_inv[i]] for i in range(n)]
290290
PS_dealloc(part)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,7 @@ def SC_test_list_perms(list L, int n, int limit, bint gap, bint limit_complain,
15761576
print('element {}'.format(permy))
15771577
print('GAP says it is an element, SC_contains(modify=1) does not')
15781578
raise AssertionError
1579-
permy = list(xrange(1, n + 1))
1579+
permy = list(range(1, n + 1))
15801580
shuffle(permy)
15811581
gap_says = (PermutationGroupElement(permy) in G)
15821582
for j from 0 <= j < n:

src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def isomorphic(G1, G2, partn, ordering2, dig, use_indicator_function, sparse=Fal
8787
n = G_in.num_verts()
8888
elif n != G_in.num_verts():
8989
return False
90-
if G_in.vertices(sort=True) != list(xrange(n)):
90+
if G_in.vertices(sort=True) != list(range(n)):
9191
G_in = copy(G_in)
9292
to = G_in.relabel(return_map=True)
9393
frm = {}
@@ -98,7 +98,7 @@ def isomorphic(G1, G2, partn, ordering2, dig, use_indicator_function, sparse=Fal
9898
else:
9999
if first:
100100
partition = partn
101-
to = list(xrange(n))
101+
to = list(range(n))
102102
frm = to
103103
if sparse:
104104
G = SparseGraph(n)
@@ -392,7 +392,7 @@ def search_tree(G_in, partition, lab=True, dig=False, dict_rep=False, certificat
392392
if isinstance(G_in, GenericGraph):
393393
loops = G_in.has_loops()
394394
n = G_in.num_verts()
395-
if G_in.vertices(sort=False) != list(xrange(n)):
395+
if G_in.vertices(sort=False) != list(range(n)):
396396
G_in = copy(G_in)
397397
to = G_in.relabel(return_map=True)
398398
frm = {}
@@ -854,7 +854,7 @@ def random_tests(num=10, n_max=60, perms_per_graph=5):
854854
print(H.graph6_string())
855855
print(perm)
856856
return
857-
isom = isomorphic(G, H, [list(xrange(n))], list(xrange(n)), 0, 1)
857+
isom = isomorphic(G, H, [list(range(n))], list(range(n)), 0, 1)
858858
if not isom or G.relabel(isom, inplace=False) != H:
859859
print("isom FAILURE: graph6-")
860860
print(H.graph6_string())
@@ -879,7 +879,7 @@ def random_tests(num=10, n_max=60, perms_per_graph=5):
879879
print(E.dig6_string())
880880
print(perm)
881881
return
882-
isom = isomorphic(D, E, [list(xrange(n))], list(xrange(n)), 1, 1)
882+
isom = isomorphic(D, E, [list(range(n))], list(range(n)), 1, 1)
883883
if not isom or D.relabel(isom, inplace=False) != E:
884884
print("isom FAILURE: dig6-")
885885
print(E.dig6_string())
@@ -890,6 +890,7 @@ def random_tests(num=10, n_max=60, perms_per_graph=5):
890890
num_graphs += 2
891891
print("All passed: %d random tests on %d graphs." % (num_tests, num_graphs))
892892

893+
893894
def orbit_partition(gamma, list_perm=False):
894895
r"""
895896
Assuming that G is a graph on vertices 0,1,...,n-1, and gamma is an

src/sage/groups/perm_gps/partn_ref/refinement_sets.pyx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def sets_isom_py(generators, set1, set2):
383383
set2 = set(set2)
384384
if not generators:
385385
if set1 == set2:
386-
return list(xrange(max(set1) + 1))
386+
return list(range(max(set1) + 1))
387387
else:
388388
return False
389389

@@ -800,7 +800,6 @@ def sets_modulo_perm_group(list generators, int max_size,
800800
sage: X = sets_modulo_perm_group([[0,2,1,4,3,5,8,7,6],[8,7,6,3,5,4,2,1,0]], 9)
801801
sage: len(X)
802802
74
803-
804803
"""
805804
cdef list out_list = []
806805
cdef int i
@@ -809,7 +808,7 @@ def sets_modulo_perm_group(list generators, int max_size,
809808
if len(generators) == 0:
810809
ll = []
811810
for i in range(max_size,-1,-1):
812-
ll.append(list(xrange(i)))
811+
ll.append(list(range(i)))
813812
return ll
814813
cdef int n = len(generators[0]), n_gens = len(generators)
815814
cdef iterator *subset_iterator

src/sage/matrix/matrix0.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ cdef class Matrix(sage.structure.element.Matrix):
965965
if ind < 0 or ind >= nrows:
966966
raise IndexError("matrix index out of range")
967967
elif isinstance(row_index, slice):
968-
row_list = list(xrange(*row_index.indices(nrows)))
968+
row_list = list(range(*row_index.indices(nrows)))
969969
else:
970970
if not PyIndex_Check(row_index):
971971
raise TypeError("index must be an integer")
@@ -998,7 +998,7 @@ cdef class Matrix(sage.structure.element.Matrix):
998998
if ind < 0 or ind >= ncols:
999999
raise IndexError("matrix index out of range")
10001000
elif isinstance(col_index, slice):
1001-
col_list = list(xrange(*col_index.indices(ncols)))
1001+
col_list = list(range(*col_index.indices(ncols)))
10021002
else:
10031003
if not PyIndex_Check(col_index):
10041004
raise TypeError("index must be an integer")
@@ -1049,7 +1049,7 @@ cdef class Matrix(sage.structure.element.Matrix):
10491049
raise IndexError("matrix index out of range")
10501050
r = self.matrix_from_rows(row_list)
10511051
elif isinstance(row_index, slice):
1052-
row_list = list(xrange(*row_index.indices(nrows)))
1052+
row_list = list(range(*row_index.indices(nrows)))
10531053
r = self.matrix_from_rows(row_list)
10541054
else:
10551055
if not PyIndex_Check(row_index):
@@ -3745,7 +3745,7 @@ cdef class Matrix(sage.structure.element.Matrix):
37453745
- [FZ2001]_
37463746
"""
37473747
cdef dict d = {}
3748-
cdef list queue = list(xrange(self._ncols))
3748+
cdef list queue = list(range(self._ncols))
37493749
cdef int l, sign, i, j
37503750

37513751
if skew:

src/sage/matrix/matrix2.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6029,7 +6029,7 @@ cdef class Matrix(Matrix1):
60296029
# sequence corresponding to the 0-th entries of the iterates,
60306030
# then the 1-th entries, etc.
60316031
if t == 0:
6032-
R = list(xrange(n))
6032+
R = list(range(n))
60336033
else:
60346034
R = [t]
60356035
for i in R:
@@ -8584,7 +8584,7 @@ cdef class Matrix(Matrix1):
85848584
aM.append(aN)
85858585
# We construct line l:
85868586
for l in range(1, nrows - 1):
8587-
if not S == list(xrange(first_row[0] + ncols, first_row[0], -1)):
8587+
if not S == list(range(first_row[0] + ncols, first_row[0], -1)):
85888588
# Sort each row with respect to S for the first matrix in X = MS
85898589
X = copy(MS)
85908590
SM = [sorted([(S[j], X[0][k][j]) for j in range(ncols)], reverse=True)
@@ -13550,7 +13550,7 @@ cdef class Matrix(Matrix1):
1355013550
M = self.change_ring(F)
1355113551
m, n = M._nrows, M._ncols
1355213552
d = min(m, n)
13553-
perm = list(xrange(m))
13553+
perm = list(range(m))
1355413554
zero = F(0)
1355513555
for k in range(d):
1355613556
max_location = -1
@@ -18214,7 +18214,7 @@ def _choose(Py_ssize_t n, Py_ssize_t t):
1821418214
cdef Py_ssize_t j, temp
1821518215

1821618216
x = [] # initialize T1
18217-
c = list(xrange(t))
18217+
c = list(range(t))
1821818218
if t == n:
1821918219
x.append(c)
1822018220
return x

src/sage/matrix/matrix_integer_dense.pyx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4676,7 +4676,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
46764676
"""
46774677
if self._nrows == 0:
46784678
pivots = []
4679-
nonpivots = list(xrange(self._ncols))
4679+
nonpivots = list(range(self._ncols))
46804680
X = self.__copy__()
46814681
d = Integer(1)
46824682
return pivots, nonpivots, X, d
@@ -4945,15 +4945,14 @@ cdef class Matrix_integer_dense(Matrix_dense):
49454945
new_top = s*row_i + t*row_n
49464946
new_bot = bg*row_i - ag*row_n
49474947

4948-
49494948
# OK -- now we have to make sure the top part of the matrix
49504949
# but with row i replaced by
49514950
# r = s*row_i[j] + t*row_n[j]
49524951
# is put in rref. We do this by recursively calling this
49534952
# function with the top part of A (all but last row) and the
49544953
# row r.
49554954

4956-
zz = list(xrange(A.nrows() - 1))
4955+
zz = list(range(A.nrows() - 1))
49574956
del zz[i]
49584957
top_mat = A.matrix_from_rows(zz)
49594958
new_pivots = list(pivots)

0 commit comments

Comments
 (0)