Skip to content

Commit 69d03d3

Browse files
author
Release Manager
committed
gh-36623: cylint cleanup in combinatorial polyhedra fixes all cython-lint warnings in combinatorial_polyhedron folder ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: #36623 Reported by: Frédéric Chapoton Reviewer(s): Kwankyu Lee
2 parents 7b3e208 + 6f8168f commit 69d03d3

13 files changed

+90
-91
lines changed

src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from sage.geometry.polyhedron.combinatorial_polyhedron.list_of_faces
66
from sage.geometry.polyhedron.combinatorial_polyhedron.face_data_structure cimport face_t
77
from sage.geometry.polyhedron.combinatorial_polyhedron.polyhedron_face_lattice cimport PolyhedronFaceLattice
88

9+
910
@cython.final
1011
cdef class CombinatorialPolyhedron(SageObject):
1112
cdef public dict _cached_methods

src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,10 @@ from sage.geometry.cone import ConvexRationalPolyhedralCone
9393
from sage.structure.element import Matrix
9494
from sage.matrix.matrix_dense cimport Matrix_dense
9595
from sage.misc.misc import is_iterator
96-
from .conversions \
97-
import incidence_matrix_to_bit_rep_of_facets, \
98-
incidence_matrix_to_bit_rep_of_Vrep, \
99-
facets_tuple_to_bit_rep_of_facets, \
100-
facets_tuple_to_bit_rep_of_Vrep
96+
from .conversions import (incidence_matrix_to_bit_rep_of_facets,
97+
incidence_matrix_to_bit_rep_of_Vrep,
98+
facets_tuple_to_bit_rep_of_facets,
99+
facets_tuple_to_bit_rep_of_Vrep)
101100
from sage.geometry.polyhedron.combinatorial_polyhedron.conversions cimport Vrep_list_to_bit_rep
102101
from sage.misc.cachefunc import cached_method
103102

@@ -437,7 +436,7 @@ cdef class CombinatorialPolyhedron(SageObject):
437436
from sage.matrix.constructor import matrix
438437
from sage.rings.integer_ring import ZZ
439438
incidence_matrix = matrix(ZZ, data.incidence_matrix().rows()
440-
+ [[ZZ.one() for _ in range(len(data.facet_normals()))]])
439+
+ [[ZZ.one() for _ in range(len(data.facet_normals()))]])
441440
return self._init_from_incidence_matrix(incidence_matrix)
442441

443442
cdef _init_facet_names(self, facets) noexcept:
@@ -481,11 +480,10 @@ cdef class CombinatorialPolyhedron(SageObject):
481480
data.set_immutable()
482481
self.incidence_matrix.set_cache(data)
483482

484-
485483
# Delete equations.
486484
data = data.delete_columns(
487485
[i for i in range(data.ncols())
488-
if all(data[j,i] for j in range(data.nrows()))],
486+
if all(data[j, i] for j in range(data.nrows()))],
489487
check=False)
490488

491489
# Initializing the facets in their Bit-representation.
@@ -515,7 +513,7 @@ cdef class CombinatorialPolyhedron(SageObject):
515513
n_Vrepresentation = len(Vrep)
516514
if Vrep != range(len(Vrep)):
517515
self._Vrep = tuple(Vrep)
518-
Vinv = {v: i for i,v in enumerate(self._Vrep)}
516+
Vinv = {v: i for i, v in enumerate(self._Vrep)}
519517
else:
520518
# Assuming the user gave as correct names for the vertices
521519
# and labeled them instead by `0,...,n`.
@@ -548,7 +546,7 @@ cdef class CombinatorialPolyhedron(SageObject):
548546
Initialize self from two ``ListOfFaces``.
549547
"""
550548
self._bitrep_facets = facets
551-
self._bitrep_Vrep = Vrep
549+
self._bitrep_Vrep = Vrep
552550

553551
self._n_Hrepresentation = self._bitrep_facets.n_faces()
554552
self._n_Vrepresentation = self._bitrep_Vrep.n_faces()
@@ -629,7 +627,7 @@ cdef class CombinatorialPolyhedron(SageObject):
629627
'A 2-dimensional combinatorial polyhedron with 1 facet'
630628
"""
631629
desc = "A {}-dimensional combinatorial polyhedron with {} facet"\
632-
.format(self.dimension(), self.n_facets())
630+
.format(self.dimension(), self.n_facets())
633631
if self.n_facets() != 1:
634632
desc += "s"
635633
return desc
@@ -1694,7 +1692,7 @@ cdef class CombinatorialPolyhedron(SageObject):
16941692

16951693
if not names:
16961694
vertices = [i for i in range(n_facets + n_Vrep)]
1697-
edges = tuple((j, n_Vrep + n_facets - 1 - i) for i,facet in enumerate(facet_iter) for j in facet.ambient_V_indices())
1695+
edges = tuple((j, n_Vrep + n_facets - 1 - i) for i, facet in enumerate(facet_iter) for j in facet.ambient_V_indices())
16981696
else:
16991697
facet_names = self.facet_names()
17001698
if facet_names is None:
@@ -1707,7 +1705,7 @@ cdef class CombinatorialPolyhedron(SageObject):
17071705
Vrep = [("V", i) for i in range(n_Vrep)]
17081706

17091707
vertices = Vrep + facet_names
1710-
edges = tuple((Vrep[j], facet_names[n_facets - 1 - i]) for i,facet in enumerate(facet_iter) for j in facet.ambient_V_indices())
1708+
edges = tuple((Vrep[j], facet_names[n_facets - 1 - i]) for i, facet in enumerate(facet_iter) for j in facet.ambient_V_indices())
17111709
return DiGraph([vertices, edges], format='vertices_and_edges', immutable=True)
17121710

17131711
@cached_method
@@ -2126,7 +2124,7 @@ cdef class CombinatorialPolyhedron(SageObject):
21262124
cdef simpliciality = dim - 1
21272125

21282126
# For each face in the iterator, check if its a simplex.
2129-
face_iter.structure.lowest_dimension = 2 # every 1-face is a simplex
2127+
face_iter.structure.lowest_dimension = 2 # every 1-face is a simplex
21302128
d = face_iter.next_dimension()
21312129
while d < dim:
21322130
sig_check()
@@ -2237,7 +2235,7 @@ cdef class CombinatorialPolyhedron(SageObject):
22372235
cdef simplicity = dim - 1
22382236

22392237
# For each coface in the iterator, check if its a simplex.
2240-
coface_iter.structure.lowest_dimension = 2 # every coface of dimension 1 is a simplex
2238+
coface_iter.structure.lowest_dimension = 2 # every coface of dimension 1 is a simplex
22412239
d = coface_iter.next_dimension()
22422240
while d < dim:
22432241
sig_check()
@@ -2623,7 +2621,6 @@ cdef class CombinatorialPolyhedron(SageObject):
26232621

26242622
return (False, None)
26252623

2626-
26272624
def join_of_Vrep(self, *indices):
26282625
r"""
26292626
Return the smallest face containing all Vrepresentatives indicated by the indices.
@@ -2793,7 +2790,6 @@ cdef class CombinatorialPolyhedron(SageObject):
27932790
if 'dual' in kwds and dual == -1 and kwds['dual'] in (False, True):
27942791
dual = int(kwds['dual'])
27952792

2796-
cdef FaceIterator face_iter
27972793
if dual == -1:
27982794
# Determine the faster way, to iterate through all faces.
27992795
if not self.is_bounded() or self.n_facets() <= self.n_Vrepresentation():
@@ -3354,7 +3350,6 @@ cdef class CombinatorialPolyhedron(SageObject):
33543350
and self.far_face_tuple() == other_C.far_face_tuple()
33553351
and self.incidence_matrix() == other.incidence_matrix())
33563352

3357-
33583353
# Methods to obtain a different combinatorial polyhedron.
33593354

33603355
cpdef CombinatorialPolyhedron dual(self) noexcept:
@@ -3484,7 +3479,6 @@ cdef class CombinatorialPolyhedron(SageObject):
34843479

34853480
return CombinatorialPolyhedron((new_facets, new_Vrep), Vrep=new_Vrep_names, facets=new_facet_names)
34863481

3487-
34883482
# Internal methods.
34893483

34903484
cdef int _compute_f_vector(self, size_t num_threads, size_t parallelization_depth, int dual) except -1:
@@ -3497,7 +3491,6 @@ cdef class CombinatorialPolyhedron(SageObject):
34973491
return 0 # There is no need to recompute the f_vector.
34983492

34993493
cdef int dim = self.dimension()
3500-
cdef int d # dimension of the current face of the iterator
35013494
cdef MemoryAllocator mem = MemoryAllocator()
35023495

35033496
if num_threads == 0:
@@ -3686,7 +3679,7 @@ cdef class CombinatorialPolyhedron(SageObject):
36863679

36873680
from sage.arith.misc import binomial
36883681
estimate_n_faces = self.dimension() * binomial(min(self.n_facets(), self.n_Vrepresentation()),
3689-
self.dimension() // 2)
3682+
self.dimension() // 2)
36903683

36913684
# Note that the runtime per face already computes the coatoms of the next level, i.e.
36923685
# the runtime for each facet suffices to compute all ridges in primal,

src/sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from sage.geometry.polyhedron.combinatorial_polyhedron.list_of_faces
44
from sage.geometry.polyhedron.combinatorial_polyhedron.face_data_structure cimport face_t
55
from sage.geometry.polyhedron.combinatorial_polyhedron.face_iterator cimport FaceIterator
66

7+
78
@cython.final
89
cdef class CombinatorialFace(SageObject):
910
cdef readonly bint _dual # if 1, then iterate over dual Polyhedron

src/sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pyx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -173,25 +173,25 @@ cdef class CombinatorialFace(SageObject):
173173

174174
# Copy data from FaceIterator.
175175
it = data
176-
self._dual = it.dual
177-
self.atoms = it.atoms
178-
self.coatoms = it.coatoms
176+
self._dual = it.dual
177+
self.atoms = it.atoms
178+
self.coatoms = it.coatoms
179179

180180
if it.structure.face_status == FaceStatus.NOT_INITIALIZED:
181181
raise LookupError("face iterator not set to a face")
182182

183183
face_init(self.face, self.coatoms.n_atoms(), self.coatoms.n_coatoms())
184184
face_copy(self.face, it.structure.face)
185185

186-
self._dimension = it.structure.current_dimension
186+
self._dimension = it.structure.current_dimension
187187
self._ambient_dimension = it.structure.dimension
188-
self._ambient_Vrep = it._Vrep
189-
self._ambient_facets = it._facet_names
190-
self._n_ambient_facets = it._n_facets
191-
self._equations = it._equations
192-
self._n_equations = it._n_equations
193-
self._hash_index = it.structure._index
194-
self._ambient_bounded = it._bounded
188+
self._ambient_Vrep = it._Vrep
189+
self._ambient_facets = it._facet_names
190+
self._n_ambient_facets = it._n_facets
191+
self._equations = it._equations
192+
self._n_equations = it._n_equations
193+
self._hash_index = it.structure._index
194+
self._ambient_bounded = it._bounded
195195

196196
self._initialized_from_face_lattice = False
197197

@@ -203,35 +203,35 @@ cdef class CombinatorialFace(SageObject):
203203
assert 0 <= index < all_faces.f_vector[dimension + 1], "index is out of range"
204204

205205
# Copy data from PolyhedronFaceLattice.
206-
self._dual = all_faces.dual
207-
self.atoms = all_faces.atoms
208-
self.coatoms = all_faces.coatoms
206+
self._dual = all_faces.dual
207+
self.atoms = all_faces.atoms
208+
self.coatoms = all_faces.coatoms
209209

210210
face_init(self.face, self.coatoms.n_atoms(), self.coatoms.n_coatoms())
211211
face_copy(self.face, all_faces.faces[dimension+1].faces[index])
212212

213-
self._dimension = dimension
213+
self._dimension = dimension
214214
self._ambient_dimension = all_faces.dimension
215-
self._ambient_Vrep = all_faces._Vrep
216-
self._ambient_facets = all_faces._facet_names
217-
self._equations = all_faces._equations
218-
self._n_equations = len(self._equations) if self._equations else 0
215+
self._ambient_Vrep = all_faces._Vrep
216+
self._ambient_facets = all_faces._facet_names
217+
self._equations = all_faces._equations
218+
self._n_equations = len(self._equations) if self._equations else 0
219219
if self._dual:
220220
self._n_ambient_facets = self.atoms.n_faces()
221221
else:
222222
self._n_ambient_facets = self.coatoms.n_faces()
223-
self._ambient_bounded = all_faces._bounded
223+
self._ambient_bounded = all_faces._bounded
224224

225225
self._initialized_from_face_lattice = True
226226

227227
self._hash_index = index
228-
for i in range(-1,dimension):
228+
for i in range(-1, dimension):
229229
self._hash_index += all_faces.f_vector[i+1]
230230

231231
# Add the complete ``f-vector`` to the hash index,
232232
# such that hash values obtained by an iterator or by the face lattice
233233
# do not collide.
234-
for i in range(-1,self._ambient_dimension+1):
234+
for i in range(-1, self._ambient_dimension+1):
235235
self._hash_index += all_faces.f_vector[i+1]
236236
else:
237237
raise ValueError("data must be face iterator or a list of all faces")
@@ -273,7 +273,7 @@ cdef class CombinatorialFace(SageObject):
273273
'A 3-dimensional face of a 5-dimensional combinatorial polyhedron'
274274
"""
275275
return "A {}-dimensional face of a {}-dimensional combinatorial polyhedron"\
276-
.format(self.dimension(), self.ambient_dimension())
276+
.format(self.dimension(), self.ambient_dimension())
277277

278278
def __reduce__(self):
279279
r"""

src/sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pyx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ AUTHOR:
5858
- Jonathan Kliem (2019-04)
5959
"""
6060

61-
#*****************************************************************************
61+
# ****************************************************************************
6262
# Copyright (C) 2019 Jonathan Kliem <[email protected]>
6363
#
6464
# This program is free software: you can redistribute it and/or modify
6565
# it under the terms of the GNU General Public License as published by
6666
# the Free Software Foundation, either version 2 of the License, or
6767
# (at your option) any later version.
68-
# http://www.gnu.org/licenses/
69-
#*****************************************************************************
68+
# https://www.gnu.org/licenses/
69+
# ****************************************************************************
7070

7171
from memory_allocator cimport MemoryAllocator
7272

@@ -94,6 +94,7 @@ def _Vrep_list_to_bit_rep_wrapper(tup):
9494
Vrep_list_to_bit_rep(tup, output.data.faces[0])
9595
return output
9696

97+
9798
cdef int Vrep_list_to_bit_rep(tuple Vrep_list, face_t output) except -1:
9899
r"""
99100
Convert a vertex list into Bit-representation. Store it in ``output``.
@@ -135,6 +136,7 @@ cdef int Vrep_list_to_bit_rep(tuple Vrep_list, face_t output) except -1:
135136
for entry in Vrep_list:
136137
face_add_atom_safe(output, entry)
137138

139+
138140
def _incidences_to_bit_rep_wrapper(tup):
139141
r"""
140142
A function to allow doctesting of :func:`incidences_to_bit_rep`.
@@ -150,6 +152,7 @@ def _incidences_to_bit_rep_wrapper(tup):
150152
incidences_to_bit_rep(tup, output.data.faces[0])
151153
return output
152154

155+
153156
cdef int incidences_to_bit_rep(tuple incidences, face_t output) except -1:
154157
r"""
155158
Convert a tuple of incidences into Bit-representation.
@@ -185,6 +188,7 @@ cdef int incidences_to_bit_rep(tuple incidences, face_t output) except -1:
185188
# Vrep ``entry`` is contained in the face, so set the corresponding bit
186189
face_add_atom_safe(output, entry)
187190

191+
188192
def incidence_matrix_to_bit_rep_of_facets(Matrix_dense matrix):
189193
r"""
190194
Initialize facets in Bit-representation as :class:`~sage.geometry.polyhedron.combinatorial_polyhedron.list_of_faces.ListOfFaces`.
@@ -249,6 +253,7 @@ def incidence_matrix_to_bit_rep_of_facets(Matrix_dense matrix):
249253
face_add_atom_safe(output, entry)
250254
return facets
251255

256+
252257
def incidence_matrix_to_bit_rep_of_Vrep(Matrix_dense matrix):
253258
r"""
254259
Initialize Vrepresentatives in Bit-representation as :class:`~sage.geometry.polyhedron.combinatorial_polyhedron.list_of_faces.ListOfFaces`.
@@ -307,6 +312,7 @@ def incidence_matrix_to_bit_rep_of_Vrep(Matrix_dense matrix):
307312
"""
308313
return incidence_matrix_to_bit_rep_of_facets(matrix.transpose())
309314

315+
310316
def facets_tuple_to_bit_rep_of_facets(tuple facets_input, size_t n_Vrep):
311317
r"""
312318
Initializes facets in Bit-representation as :class:`~sage.geometry.polyhedron.combinatorial_polyhedron.list_of_faces.ListOfFaces`.
@@ -348,6 +354,7 @@ def facets_tuple_to_bit_rep_of_facets(tuple facets_input, size_t n_Vrep):
348354
facet_set_coatom(facets.data.faces[i], i)
349355
return facets
350356

357+
351358
def facets_tuple_to_bit_rep_of_Vrep(tuple facets_input, size_t n_Vrep):
352359
r"""
353360
Initialize Vrepresentatives in Bit-representation as :class:`~sage.geometry.polyhedron.combinatorial_polyhedron.list_of_faces.ListOfFaces`.
@@ -408,6 +415,7 @@ def facets_tuple_to_bit_rep_of_Vrep(tuple facets_input, size_t n_Vrep):
408415
face_add_atom_safe(Vrep_data[input_Vrep], input_facet)
409416
return Vrep
410417

418+
411419
def _bit_rep_to_Vrep_list_wrapper(ListOfFaces faces, index=0):
412420
r"""
413421
A function to test :func:`bit_rep_to_Vrep_list`.
@@ -433,10 +441,10 @@ def _bit_rep_to_Vrep_list_wrapper(ListOfFaces faces, index=0):
433441
output = <size_t *> mem.allocarray(faces.n_atoms(),
434442
sizeof(size_t))
435443

436-
length = bit_rep_to_Vrep_list(
437-
faces.data.faces[index], output)
444+
length = bit_rep_to_Vrep_list(faces.data.faces[index], output)
438445
return tuple(output[i] for i in range(length))
439446

447+
440448
cdef inline size_t bit_rep_to_Vrep_list(face_t face, size_t *output) except -1:
441449
r"""
442450
Convert a bitrep-representation to a list of Vrep. Return length of representation.

src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ cdef class FaceIterator_base(SageObject):
8080
cdef int only_subsets(self) except -1
8181
cdef int find_face(self, face_t face) except -1
8282

83+
8384
@cython.final
8485
cdef class FaceIterator(FaceIterator_base):
8586
pass
8687

88+
8789
@cython.final
8890
cdef class FaceIterator_geom(FaceIterator_base):
8991
cdef int _trivial_faces # Whether to yield the trivial faces.

0 commit comments

Comments
 (0)