Skip to content

Commit 7287b45

Browse files
author
Release Manager
committed
gh-35877: cython-lint:some care for groups/perm_gps <!-- 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 fixes a few cython-lint warnings in groups/perm_gps. Removing some unused variables and imports, converting some loop to python-style, fixing some E701 (line break missing after colon) <!-- 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: #35877 Reported by: Frédéric Chapoton Reviewer(s): Matthias Köppe
2 parents eef9eea + 9193cbc commit 7287b45

11 files changed

+169
-125
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,12 @@ from .data_structures cimport *
116116
from sage.data_structures.bitset_base cimport *
117117

118118
cdef inline int agcl_cmp(int a, int b):
119-
if a < b: return -1
120-
elif a == b: return 0
121-
else: return 1
119+
if a < b:
120+
return -1
121+
elif a == b:
122+
return 0
123+
else:
124+
return 1
122125

123126
# Functions
124127

@@ -212,9 +215,10 @@ cdef int compare_perms(int *gamma_1, int *gamma_2, void *S1, void *S2, int degre
212215
cdef list MS1 = <list> S1
213216
cdef list MS2 = <list> S2
214217
cdef int i, j
215-
for i from 0 <= i < degree:
218+
for i in range(degree):
216219
j = agcl_cmp(MS1[gamma_1[i]], MS2[gamma_2[i]])
217-
if j != 0: return j
220+
if j != 0:
221+
return j
218222
return 0
219223

220224
def coset_rep(list perm=[0,1,2,3,4,5], list gens=[[1,2,3,4,5,0]]):
@@ -480,7 +484,7 @@ cdef aut_gp_and_can_lab *get_aut_gp_and_can_lab(void *S,
480484

481485
cdef int i, j, k, ell, b
482486
cdef bint discrete, automorphism, update_label
483-
cdef bint backtrack, new_vertex, narrow, mem_err = 0
487+
cdef bint backtrack, new_vertex, mem_err = 0
484488

485489
cdef aut_gp_and_can_lab *output
486490
cdef agcl_work_space *work_space

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ cdef void *canonical_generator_next(void *can_gen_data, int *degree, bint *mem_e
211211
aug, cgd.object_stack[cgd.level], &cgd.degree_stack[cgd.level],
212212
&cgd.mem_err)
213213
cgd.object_stack[cgd.level] = next_candidate
214-
if cgd.mem_err: continue
214+
if cgd.mem_err:
215+
continue
215216
next_cand_deg = cgd.degree_stack[cgd.level]
216217
if cgd.agcl_work_spaces[cgd.level] is NULL:
217218
# allocate a work space if it hasn't been allocated already

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

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ REFERENCES:
2323
# it under the terms of the GNU General Public License as published by
2424
# the Free Software Foundation, either version 2 of the License, or
2525
# (at your option) any later version.
26-
# http://www.gnu.org/licenses/
26+
# https://www.gnu.org/licenses/
2727
#*****************************************************************************
2828

2929
from libc.math cimport log, ceil
@@ -134,7 +134,8 @@ def OP_represent(int n, merges, perm):
134134
if not OP_find(OP, i) == i:
135135
print("Failed at i = %d!" % i)
136136
good = False
137-
if good: print("Each element reports itself as its root.")
137+
if good:
138+
print("Each element reports itself as its root.")
138139
print("Merging:")
139140
for i,j in merges:
140141
OP_join(OP, i, j)
@@ -296,14 +297,16 @@ cdef int PS_first_smallest(PartitionStack *PS, bitset_t b, int *second_pos=NULL,
296297
n = i - j + 1
297298
location = j
298299
j = i + 1
299-
if PS.levels[i] == -1: break
300+
if PS.levels[i] == -1:
301+
break
300302
i += 1
301303
# location now points to the beginning of the first, smallest,
302304
# nontrivial cell
303305
i = location
304306
while 1:
305307
bitset_flip(b, PS.entries[i])
306-
if PS.levels[i] <= PS.depth: break
308+
if PS.levels[i] <= PS.depth:
309+
break
307310
i += 1
308311

309312
if second_pos != NULL:
@@ -480,7 +483,8 @@ def PS_represent(partition, splits):
480483
if not PS.degree == n or not PS.depth == 0:
481484
print("Incorrect degree or depth!")
482485
good = False
483-
if good: print("Everything seems in order, deallocating.")
486+
if good:
487+
print("Everything seems in order, deallocating.")
484488
PS_dealloc(PS)
485489
print("Deallocated.")
486490
print("Creating PartitionStack from partition %s."%partition)
@@ -633,11 +637,13 @@ cdef inline int SC_realloc_gens(StabilizerChain *SC, int level, int size):
633637
cdef int n = SC.degree
634638

635639
temp = <int *> sig_realloc( SC.generators[level], n * size * sizeof(int) )
636-
if temp is NULL: return 1
640+
if temp is NULL:
641+
return 1
637642
SC.generators[level] = temp
638643

639644
temp = <int *> sig_realloc( SC.gen_inverses[level], n * size * sizeof(int) )
640-
if temp is NULL: return 1
645+
if temp is NULL:
646+
return 1
641647
SC.gen_inverses[level] = temp
642648

643649
SC.array_size[level] = size
@@ -751,7 +757,8 @@ cdef int SC_realloc_bitsets(StabilizerChain *SC, unsigned long size):
751757
Returns 1 in case of an allocation failure.
752758
"""
753759
cdef unsigned long size_old = SC.gen_used.size
754-
if size <= size_old: return 0
760+
if size <= size_old:
761+
return 0
755762
cdef unsigned long new_size = size_old
756763
while new_size < size:
757764
new_size *= 2
@@ -1041,8 +1048,10 @@ cdef int SC_insert_and_sift(StabilizerChain *SC, int level, int *pi, int num_per
10411048
break
10421049
else:
10431050
bitset_set(&SC.gen_is_id, perm_gen_index)
1044-
if b != -1: break
1045-
if b == -1: return 0
1051+
if b != -1:
1052+
break
1053+
if b == -1:
1054+
return 0
10461055
if sift and level == SC.base_size:
10471056
SC_add_base_point(SC, b)
10481057
else:
@@ -1064,18 +1073,22 @@ cdef int SC_insert_and_sift(StabilizerChain *SC, int level, int *pi, int num_per
10641073
for i from 0 <= i < SC.orbit_sizes[level]:
10651074
x = SC.base_orbits[level][i]
10661075
for perm_gen_index from 0 <= perm_gen_index < num_perms:
1067-
if sift and bitset_check(&SC.gen_is_id, perm_gen_index): continue
1076+
if sift and bitset_check(&SC.gen_is_id, perm_gen_index):
1077+
continue
10681078
perm = pi + n*perm_gen_index
10691079
if SC.parents[level][perm[x]] == -1:
10701080
# now we have an x which maps to a new point under perm,
10711081
re_treed = 1
1072-
if sift: bitset_set(&SC.gen_used, perm_gen_index)
1082+
if sift:
1083+
bitset_set(&SC.gen_used, perm_gen_index)
10731084
if SC_re_tree(SC, level, perm, x):
10741085
return 1
10751086
start_over = 1 # we must look anew
10761087
break
1077-
if start_over: break
1078-
if not re_treed: continue
1088+
if start_over:
1089+
break
1090+
if not re_treed:
1091+
continue
10791092
for perm_gen_index from 0 <= perm_gen_index < old_num_gens:
10801093
perm = SC.generators[level] + n*perm_gen_index
10811094
if SC.parents[level][perm[x]] == -1:
@@ -1084,7 +1097,8 @@ cdef int SC_insert_and_sift(StabilizerChain *SC, int level, int *pi, int num_per
10841097
return 1
10851098
start_over = 1 # we must look anew
10861099
break
1087-
if start_over: break
1100+
if start_over:
1101+
break
10881102
for j from level < j < SC.base_size:
10891103
for perm_gen_index from 0 <= perm_gen_index < SC.num_gens[j]:
10901104
perm = SC.generators[j] + n*perm_gen_index
@@ -1361,7 +1375,8 @@ def SC_test_list_perms(list L, int n, int limit, bint gap, bint limit_complain,
13611375
if gap:
13621376
G = PermutationGroup([[i+1 for i in p] for p in L])
13631377
if G.order() > limit:
1364-
if limit_complain: print('TOO BIG')
1378+
if limit_complain:
1379+
print('TOO BIG')
13651380
return
13661381
SC = SC_new(n)
13671382
cdef int *perm = <int *>sig_malloc(n * (len(L)+3) * sizeof(int))

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ cdef int compare_perms(int *gamma_1, int *gamma_2, void *S1, void *S2, int degre
110110
cdef list MS1 = <list> S1
111111
cdef list MS2 = <list> S2
112112
cdef int i, j
113-
for i from 0 <= i < degree:
113+
for i in range(degree):
114114
j = int_cmp(MS1[gamma_1[i]], MS2[gamma_2[i]])
115-
if j != 0: return j
115+
if j != 0:
116+
return j
116117
return 0
117118

118119
def coset_eq(list perm1=[0,1,2,3,4,5], list perm2=[1,2,3,4,5,0], list gens=[[1,2,3,4,5,0]]):
@@ -351,8 +352,8 @@ cdef int double_coset(void *S1, void *S2, PartitionStack *partition1, int *order
351352
cdef StabilizerChain *tmp_gp
352353

353354
cdef int i, j, k, ell, b
354-
cdef bint discrete, automorphism, update_label
355-
cdef bint backtrack, new_vertex, narrow, mem_err = 0
355+
cdef bint automorphism
356+
cdef bint new_vertex, mem_err = 0
356357

357358
if n == 0:
358359
return 0
@@ -591,7 +592,7 @@ cdef int double_coset(void *S1, void *S2, PartitionStack *partition1, int *order
591592
# (same!) primary orbit, then all children of the first
592593
# stack at this point are equivalent.
593594
j = 0
594-
for i from 0 <= i < n:
595+
for i in range(n):
595596
if bitset_check(vertices_to_split[current_ps.depth], i):
596597
j += 1
597598
if j == subgroup_primary_orbit_size and first_kids_are_same == current_ps.depth+1:
@@ -608,7 +609,6 @@ cdef int double_coset(void *S1, void *S2, PartitionStack *partition1, int *order
608609

609610
# II. Refine down to a discrete partition, or until
610611
# we leave the part of the tree we are interested in
611-
discrete = 0
612612
while True:
613613
i = current_ps.depth
614614
while True:
@@ -642,7 +642,8 @@ cdef int double_coset(void *S1, void *S2, PartitionStack *partition1, int *order
642642
possible = 1
643643
vertices_determining_current_stack[i] = j
644644
current_ps.depth -= 1 # reset for next refinement
645-
else: break
645+
else:
646+
break
646647
if not possible:
647648
break
648649
if PS_is_discrete(current_ps):
@@ -682,7 +683,7 @@ cdef int double_coset(void *S1, void *S2, PartitionStack *partition1, int *order
682683
index_in_fp_and_mcr += 1
683684
bitset_zero(fixed_points_of_generators[index_in_fp_and_mcr])
684685
bitset_zero(minimal_cell_reps_of_generators[index_in_fp_and_mcr])
685-
for i from 0 <= i < n:
686+
for i in range(n):
686687
if permutation[i] == i:
687688
bitset_set(fixed_points_of_generators[index_in_fp_and_mcr], i)
688689
bitset_set(minimal_cell_reps_of_generators[index_in_fp_and_mcr], i)
@@ -691,7 +692,8 @@ cdef int double_coset(void *S1, void *S2, PartitionStack *partition1, int *order
691692
k = i
692693
j = permutation[i]
693694
while j != i:
694-
if j < k: k = j
695+
if j < k:
696+
k = j
695697
j = permutation[j]
696698
if k == i:
697699
bitset_set(minimal_cell_reps_of_generators[index_in_fp_and_mcr], i)

0 commit comments

Comments
 (0)