Skip to content

Commit 4e65838

Browse files
author
Release Manager
committed
gh-36478: some details in pyx files in combinat This is fixing some of the messages of `cython-lint` on pyx files in the `combinat` folder. ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: #36478 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents b297c4d + 31f4fa6 commit 4e65838

19 files changed

+149
-112
lines changed

src/sage/combinat/combinat_cython.pyx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ cdef mpz_stirling_s2(mpz_t s, unsigned long n, unsigned long k):
134134
mpz_clear(t)
135135
mpz_clear(u)
136136

137+
137138
def _stirling_number2(n, k):
138139
"""
139140
Python wrapper of mpz_stirling_s2.
@@ -148,8 +149,9 @@ def _stirling_number2(n, k):
148149
mpz_stirling_s2(s.value, n, k)
149150
return s
150151

152+
151153
#####################################################################
152-
## Lyndon word iterator
154+
# Lyndon word iterator
153155

154156
def lyndon_word_iterator(Py_ssize_t n, Py_ssize_t k):
155157
r"""
@@ -204,7 +206,8 @@ def lyndon_word_iterator(Py_ssize_t n, Py_ssize_t k):
204206
while a[i] == n - 1:
205207
i -= 1
206208

207-
## Perfect matchings iterator
209+
210+
# Perfect matchings iterator
208211

209212
def perfect_matchings_iterator(Py_ssize_t n):
210213
r"""
@@ -276,6 +279,7 @@ def perfect_matchings_iterator(Py_ssize_t n):
276279
sig_free(e)
277280
sig_free(f)
278281

282+
279283
cdef list convert(Py_ssize_t* f, Py_ssize_t n):
280284
"""
281285
Convert a list ``f`` representing a fixed-point free involution
@@ -288,8 +292,9 @@ cdef list convert(Py_ssize_t* f, Py_ssize_t n):
288292
ret.append((i, f[i]))
289293
return ret
290294

295+
291296
#####################################################################
292-
## Set partition composition
297+
# Set partition composition
293298

294299
def set_partition_composition(tuple sp1, tuple sp2):
295300
r"""

src/sage/combinat/debruijn_sequence.pyx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,16 @@ AUTHOR:
5757
5858
"""
5959

60-
#*******************************************************************************
60+
# ******************************************************************************
6161
# Copyright (C) 2011 Eviatar Bach <[email protected]>
6262
#
6363
# Distributed under the terms of the GNU General Public License (GPL)
64-
# http://www.gnu.org/licenses/
65-
#*******************************************************************************
64+
# https://www.gnu.org/licenses/
65+
# ******************************************************************************
6666

6767
from sage.data_structures.bitset_base cimport *
6868

69+
6970
def debruijn_sequence(int k, int n):
7071
"""
7172
The generating function for De Bruijn sequences. This avoids the object
@@ -93,6 +94,7 @@ def debruijn_sequence(int k, int n):
9394
gen(1, 1, k, n)
9495
return sequence
9596

97+
9698
cdef gen(int t, int p, k, n):
9799
"""
98100
The internal generation function. This should not be accessed by the
@@ -183,13 +185,15 @@ def is_debruijn_sequence(seq, k, n):
183185

184186
return answer
185187

188+
186189
from sage.categories.finite_sets import FiniteSets
187190
from sage.structure.unique_representation import UniqueRepresentation
188191
from sage.structure.parent import Parent
189192

190193
from sage.rings.integer cimport Integer
191194
from sage.rings.integer_ring import ZZ
192195

196+
193197
class DeBruijnSequences(UniqueRepresentation, Parent):
194198
"""
195199
Represents the De Bruijn sequences of given parameters `k` and `n`.
@@ -256,35 +260,32 @@ class DeBruijnSequences(UniqueRepresentation, Parent):
256260
"""
257261
Constructor.
258262
259-
Checks the consistency of the given arguments.
263+
This checks the consistency of the given arguments.
260264
261265
TESTS:
262266
263-
Setting ``n`` orr ``k`` to anything under 1 will return a ValueError:
264-
265-
::
267+
Setting ``n`` or ``k`` to anything under 1 will return
268+
a :class:`ValueError`::
266269
267270
sage: DeBruijnSequences(3, 0).an_element()
268271
Traceback (most recent call last):
269272
...
270-
ValueError: k and n cannot be under 1.
273+
ValueError: k and n cannot be under 1
271274
272275
Setting ``n`` or ``k`` to any type except an integer will return a
273-
TypeError:
274-
275-
::
276+
:class:`TypeError`::
276277
277278
sage: DeBruijnSequences(2.5, 3).an_element()
278279
Traceback (most recent call last):
279280
...
280-
TypeError: k and n must be integers.
281+
TypeError: k and n must be integers
281282
"""
282283
Parent.__init__(self, category=FiniteSets())
283284
if n < 1 or k < 1:
284-
raise ValueError('k and n cannot be under 1.')
285+
raise ValueError('k and n cannot be under 1')
285286
if (not isinstance(n, (Integer, int)) or
286-
not isinstance(k, (Integer,int))):
287-
raise TypeError('k and n must be integers.')
287+
not isinstance(k, (Integer, int))):
288+
raise TypeError('k and n must be integers')
288289

289290
self.k = k
290291
self.n = n

src/sage/combinat/degree_sequences.pyx

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ An integer sequence need not necessarily be a degree sequence. Indeed, in a
5757
degree sequence of length `n` no integer can be larger than `n-1` -- the degree
5858
of a vertex is at most `n-1` -- and the sum of them is at most `n(n-1)`.
5959
60-
Degree sequences are completely characterized by a result from Erdos and Gallai:
60+
Degree sequences are completely characterized by a result from Erdős and Gallai:
6161
62-
**Erdos and Gallai:** *The sequence of integers* `d_1 \geq \cdots \geq d_n`
62+
**Erdős and Gallai:** *The sequence of integers* `d_1 \geq \cdots \geq d_n`
6363
*is a degree sequence if and only if* `\sum_i d_i` is even and `\forall i`
6464
6565
.. MATH::
@@ -281,6 +281,7 @@ from cysignals.signals cimport sig_on, sig_off
281281
cdef unsigned char * seq
282282
cdef list sequences
283283

284+
284285
class DegreeSequences:
285286

286287
def __init__(self, n):
@@ -307,16 +308,16 @@ class DegreeSequences:
307308
sage: DegreeSequences(-1)
308309
Traceback (most recent call last):
309310
...
310-
ValueError: The input parameter must be >= 0.
311+
ValueError: the input parameter must be >= 0
311312
"""
312313
if n < 0:
313-
raise ValueError("The input parameter must be >= 0.")
314+
raise ValueError("the input parameter must be >= 0")
314315
self._n = n
315316

316317
def __contains__(self, seq):
317318
"""
318-
Checks whether a given integer sequence is the degree sequence
319-
of a graph on `n` elements
319+
Check whether a given integer sequence is the degree sequence
320+
of a graph on `n` elements.
320321
321322
EXAMPLES::
322323
@@ -342,7 +343,7 @@ class DegreeSequences:
342343
[[0]]
343344
"""
344345
cdef int n = self._n
345-
if len(seq)!=n:
346+
if len(seq) != n:
346347
return False
347348

348349
# Is the sum even ?
@@ -352,13 +353,13 @@ class DegreeSequences:
352353
# Partial represents the left side of Erdos and Gallai's inequality,
353354
# i.e. the sum of the i first integers.
354355
cdef int partial = 0
355-
cdef int i,d,dd, right
356+
cdef int i, d, dd, right
356357

357358
# Temporary variable to ensure that the sequence is indeed
358359
# non-increasing
359-
cdef int prev = n-1
360+
cdef int prev = n - 1
360361

361-
for i,d in enumerate(seq):
362+
for i, d in enumerate(seq):
362363

363364
# Non-increasing ?
364365
if d > prev:
@@ -370,9 +371,9 @@ class DegreeSequences:
370371
partial += d
371372

372373
# Evaluating the right hand side
373-
right = i*(i+1)
374-
for dd in seq[i+1:]:
375-
right += min(dd,i+1)
374+
right = i * (i + 1)
375+
for dd in seq[i + 1:]:
376+
right += min(dd, i + 1)
376377

377378
# Comparing the two
378379
if partial > right:
@@ -404,14 +405,15 @@ class DegreeSequences:
404405
sage: all(seq in DS for seq in DS)
405406
True
406407
"""
407-
return iter( init(self._n) )
408+
yield from init(self._n)
408409

409410
def __dealloc__():
410411
"""
411412
Freeing the memory
412413
"""
413414
sig_free(seq)
414415

416+
415417
cdef init(int n):
416418
"""
417419
Initializes the memory and starts the enumeration algorithm.
@@ -432,7 +434,7 @@ cdef init(int n):
432434

433435
N = n
434436
sequences = []
435-
enum(1,0)
437+
enum(1, 0)
436438
sig_free(seq)
437439
return sequences
438440

@@ -467,7 +469,7 @@ cdef void enum(int k, int M):
467469
- ``k`` -- depth of the partial degree sequence
468470
- ``M`` -- value of a maximum element in the partial degree sequence
469471
"""
470-
cdef int i,j
472+
cdef int i, j
471473
global seq
472474
cdef int taken = 0
473475
cdef int current_box
@@ -491,21 +493,21 @@ cdef void enum(int k, int M):
491493
if M == 0:
492494

493495
seq[0] += 1
494-
enum(k+1, M)
496+
enum(k + 1, M)
495497
seq[0] -= 1
496498

497499
# We need not automatically increase the degree at each step. In this case,
498500
# we have no other choice but to link the new vertex of degree M to vertices
499501
# of degree M-1, which will become vertices of degree M too.
500-
elif seq[M-1] >= M:
502+
elif seq[M - 1] >= M:
501503

502-
seq[M] += M+1
503-
seq[M-1] -= M
504+
seq[M] += M + 1
505+
seq[M - 1] -= M
504506

505-
enum(k+1, M)
507+
enum(k + 1, M)
506508

507-
seq[M] -= M+1
508-
seq[M-1] += M
509+
seq[M] -= M + 1
510+
seq[M - 1] += M
509511

510512
###############################################
511513
# Creating vertices of Vertices of degree > M #
@@ -542,13 +544,13 @@ cdef void enum(int k, int M):
542544
seq[current_box] -= i
543545
seq[current_box+1] += i
544546

545-
for max(0,((M+1)-taken-i)) <= j <= n_previous_box:
547+
for max(0, ((M+1)-taken-i)) <= j <= n_previous_box:
546548
seq[current_box-1] -= j
547549
seq[current_box] += j
548550

549551
new_vertex = taken + i + j
550552
seq[new_vertex] += 1
551-
enum(k+1,new_vertex)
553+
enum(k+1, new_vertex)
552554
seq[new_vertex] -= 1
553555

554556
seq[current_box-1] += j
@@ -566,7 +568,7 @@ cdef void enum(int k, int M):
566568
# Now current_box = 0. All the vertices of nonzero degree are taken, we just
567569
# want to know how many vertices of degree 0 will be neighbors of the new
568570
# vertex.
569-
for max(0,((M+1)-taken)) <= i <= seq[0]:
571+
for max(0, ((M+1)-taken)) <= i <= seq[0]:
570572

571573
seq[1] += i
572574
seq[0] -= i

src/sage/combinat/designs/designs_pyx.pyx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ from cysignals.memory cimport sig_malloc, sig_calloc, sig_realloc, sig_free
1515

1616
from sage.misc.unknown import Unknown
1717

18+
1819
def is_covering_array(array, strength=None, levels=None, verbose=False, parameters=False):
1920
r"""
2021
Check if the input is a covering array with given strength.
@@ -349,6 +350,7 @@ def is_orthogonal_array(OA, int k, int n, int t=2, verbose=False, terminology="O
349350
bitset_free(seen)
350351
return True
351352

353+
352354
def is_group_divisible_design(groups,blocks,v,G=None,K=None,lambd=1,verbose=False):
353355
r"""
354356
Checks that input is a Group Divisible Design on `\{0,...,v-1\}`
@@ -588,6 +590,7 @@ def is_pairwise_balanced_design(blocks,v,K=None,lambd=1,verbose=False):
588590
lambd=lambd,
589591
verbose=verbose)
590592

593+
591594
def is_projective_plane(blocks, verbose=False):
592595
r"""
593596
Test whether the blocks form a projective plane on `\{0,...,v-1\}`
@@ -661,6 +664,7 @@ def is_projective_plane(blocks, verbose=False):
661664
lambd=1,
662665
verbose=verbose)
663666

667+
664668
def is_difference_matrix(M,G,k,lmbda=1,verbose=False):
665669
r"""
666670
Test if `M` is a `(G,k,\lambda)`-difference matrix.
@@ -725,6 +729,7 @@ def is_difference_matrix(M,G,k,lmbda=1,verbose=False):
725729
"""
726730
return is_quasi_difference_matrix(M,G,k,lmbda=lmbda,mu=lmbda,u=0,verbose=verbose)
727731

732+
728733
def is_quasi_difference_matrix(M,G,int k,int lmbda,int mu,int u,verbose=False):
729734
r"""
730735
Test if the matrix is a `(G,k;\lambda,\mu;u)`-quasi-difference matrix
@@ -938,6 +943,7 @@ def is_quasi_difference_matrix(M,G,int k,int lmbda,int mu,int u,verbose=False):
938943
sig_free(M_c)
939944
return True
940945

946+
941947
# Cached information for OA constructions (see .pxd file for more info)
942948

943949
_OA_cache = <cache_entry *> sig_malloc(2*sizeof(cache_entry))

src/sage/combinat/designs/gen_quadrangles_with_spread.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def generalised_quadrangle_with_spread(const int s, const int t,
123123
raise RuntimeError(
124124
f"Sage can't build a GQ of order ({s}, {t}) with a spread")
125125

126+
126127
def is_GQ_with_spread(GQ, S, s=None, t=None):
127128
r"""
128129
Check if GQ is a generalised quadrangle of order `(s,t)` and
@@ -233,6 +234,7 @@ def dual_GQ_ovoid(GQ, O):
233234
D = IncidenceStructure(newBlocks)
234235
return (D, S)
235236

237+
236238
def generalised_quadrangle_hermitian_with_ovoid(const int q):
237239
r"""
238240
Construct the generalised quadrangle `H(3,q^2)` with an ovoid.

src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ from .orthogonal_arrays import orthogonal_array
5151
from sage.rings.integer cimport smallInteger
5252
from sage.arith.misc import prime_powers
5353

54+
5455
@cached_function
5556
def find_recursive_construction(k, n):
5657
r"""
@@ -114,6 +115,7 @@ def find_recursive_construction(k, n):
114115
return res
115116
return False
116117

118+
117119
cpdef find_product_decomposition(int k,int n):
118120
r"""
119121
Find `n_1n_2=n` to obtain an `OA(k,n)` by the product construction.
@@ -880,6 +882,7 @@ def int_as_sum(int value, list S, int k_max):
880882

881883
return None
882884

885+
883886
cpdef find_brouwer_van_rees_with_one_truncated_column(int k,int n):
884887
r"""
885888
Find `rm+x_1+...+x_c=n` such that the Brouwer-van Rees constructions yields a `OA(k,n)`.

0 commit comments

Comments
 (0)