Skip to content

Commit fbe286d

Browse files
author
Release Manager
committed
gh-35453: partial cython-linting in graphs/ <!-- 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 Used cython-lint to find some issues in `graphs`. Then fix some of them manually. <!-- 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: #35453 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents 1af6f29 + 75bb6e3 commit fbe286d

20 files changed

+38
-71
lines changed

src/sage/graphs/base/boost_graph.pyx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,6 @@ cpdef johnson_shortest_paths(g, weight_function=None, distances=True, predecesso
11831183
cdef BoostVecWeightedGraph g_boost_und
11841184
cdef int N = g.num_verts()
11851185
cdef vector[vector[double]] result
1186-
cdef int u_int, v_int
11871186

11881187
if g.is_directed():
11891188
boost_weighted_graph_from_sage_graph(&g_boost_dir, g, v_to_int, weight_function)
@@ -1340,7 +1339,6 @@ cpdef floyd_warshall_shortest_paths(g, weight_function=None, distances=True, pre
13401339
cdef BoostVecWeightedGraph g_boost_und
13411340
cdef int N = g.num_verts()
13421341
cdef vector[vector[double]] result
1343-
cdef int u_int, v_int
13441342

13451343
if g.is_directed():
13461344
boost_weighted_graph_from_sage_graph(&g_boost_dir, g, v_to_int, weight_function)
@@ -2330,13 +2328,13 @@ cdef double diameter_DiFUB(BoostVecWeightedDiGraphU g_boost,
23302328
import sys
23312329
# These variables are automatically deleted when the function terminates.
23322330
cdef double LB, LB_1, LB_2, UB
2333-
cdef v_index s, m, d, v, tmp
2331+
cdef v_index m, v, tmp
23342332
cdef v_index i
23352333
cdef vector[double] distances
23362334
cdef vector[pair[double, v_index]] order_1, order_2
23372335

23382336
# We select a vertex with low eccentricity using 2Dsweep
2339-
LB, s, m, d = diameter_lower_bound_2Dsweep(g_boost, rev_g_boost,
2337+
LB, _, m, _ = diameter_lower_bound_2Dsweep(g_boost, rev_g_boost,
23402338
source, algorithm)
23412339

23422340
# If the lower bound is a very large number, it means that the digraph is
@@ -2969,7 +2967,6 @@ cpdef wiener_index(g, algorithm=None, weight_function=None, check_weight=True):
29692967

29702968
# These variables are automatically deleted when the function terminates.
29712969
cdef v_index vi, u, v
2972-
cdef dict int_to_v = dict(enumerate(g))
29732970
cdef dict v_to_int = {vv: vi for vi, vv in enumerate(g)}
29742971
cdef BoostVecWeightedDiGraphU g_boost_dir
29752972
cdef BoostVecWeightedGraph g_boost_und

src/sage/graphs/base/c_graph.pyx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ method :meth:`realloc <sage.graphs.base.c_graph.CGraph.realloc>`.
4444
# ****************************************************************************
4545

4646
from sage.data_structures.bitset_base cimport *
47-
from sage.rings.integer cimport Integer, smallInteger
47+
from sage.rings.integer cimport smallInteger
4848
from sage.arith.long cimport pyobject_to_long
4949
from libcpp.queue cimport priority_queue, queue
5050
from libcpp.stack cimport stack
@@ -3751,7 +3751,6 @@ cdef class CGraphBackend(GenericGraphBackend):
37513751
# studied.
37523752
cdef int x_int = self.get_vertex(x)
37533753
cdef int y_int = self.get_vertex(y)
3754-
cdef int u = 0
37553754
cdef int v = 0
37563755
cdef int w = 0
37573756
cdef int pred
@@ -3978,7 +3977,6 @@ cdef class CGraphBackend(GenericGraphBackend):
39783977
# studied.
39793978
cdef int x_int = self.get_vertex(x)
39803979
cdef int y_int = self.get_vertex(y)
3981-
cdef int u = 0
39823980
cdef int v = 0
39833981
cdef int w = 0
39843982
cdef int pred
@@ -4680,7 +4678,6 @@ cdef class CGraphBackend(GenericGraphBackend):
46804678
# // answer = [u]
46814679
cycle = [self.vertex_label(u)]
46824680

4683-
tmp = u
46844681
while u != uu:
46854682
u = parent.get(u, uu)
46864683
cycle.append(self.vertex_label(u))
@@ -4899,7 +4896,7 @@ cdef class Search_iterator:
48994896
sage: next(g.breadth_first_search(0))
49004897
0
49014898
"""
4902-
cdef int v_int, v_dist
4899+
cdef int v_int
49034900
cdef int w_int
49044901
cdef int l
49054902
cdef CGraph cg = self.graph.cg()

src/sage/graphs/base/dense_graph.pyx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,15 @@ cdef class DenseGraph(CGraph):
236236
sage: D.realloc(30)
237237
sage: D.current_allocation()
238238
30
239-
240239
"""
241-
cdef int i, j
240+
cdef int i
242241
if not total_verts:
243242
raise RuntimeError('dense graphs must allocate space for vertices')
244243

245244
cdef bitset_t bits
246-
cdef int min_verts, min_longs
245+
cdef int min_verts
247246
if <size_t>total_verts < self.active_vertices.size:
248247
min_verts = total_verts
249-
min_longs = -1
250248
bitset_init(bits, self.active_vertices.size)
251249
bitset_set_first_n(bits, total_verts)
252250
if not bitset_issubset(self.active_vertices, bits):
@@ -402,7 +400,7 @@ cdef class DenseGraph(CGraph):
402400
"""
403401
cdef int num_arcs_old = self.num_arcs
404402

405-
cdef size_t i, j
403+
cdef size_t i
406404
i = bitset_next(self.active_vertices, 0)
407405
while i != -1:
408406
self.add_arc_unsafe(i, i)

src/sage/graphs/base/graph_backends.pyx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ For an overview of graph data structures in sage, see
4747
Classes and methods
4848
-------------------
4949
"""
50-
5150
# ****************************************************************************
5251
# Copyright (C) 2008 Robert L. Miller <[email protected]>
5352
# 2018 Julian Rüth <[email protected]>
@@ -58,8 +57,7 @@ Classes and methods
5857
# (at your option) any later version.
5958
# https://www.gnu.org/licenses/
6059
# ****************************************************************************
61-
62-
from .c_graph cimport CGraphBackend, CGraph
60+
from .c_graph cimport CGraphBackend
6361

6462

6563
cdef class GenericGraphBackend(SageObject):

src/sage/graphs/base/sparse_graph.pxd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#*****************************************************************************
1+
# ****************************************************************************
22
# Copyright (C) 2008-2009 Robert L. Miller <[email protected]>
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by
66
# the Free Software Foundation, either version 2 of the License, or
77
# (at your option) any later version.
8-
# http://www.gnu.org/licenses/
9-
#*****************************************************************************
8+
# https://www.gnu.org/licenses/
9+
# ****************************************************************************
1010

1111
from .c_graph cimport CGraph, CGraphBackend
1212
cimport cython
@@ -23,6 +23,7 @@ cdef struct SparseGraphBTNode:
2323
SparseGraphBTNode *left
2424
SparseGraphBTNode *right
2525

26+
2627
@cython.final
2728
cdef class SparseGraph(CGraph):
2829
cdef int hash_length

src/sage/graphs/base/sparse_graph.pyx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,10 +1009,9 @@ cdef class SparseGraph(CGraph):
10091009
10101010
- a pointer to the first label or ``NULL`` if there are none
10111011
"""
1012-
cdef int i = (u * self.hash_length) + (v & self.hash_mask), j
1013-
cdef int compared, num_arcs
1012+
cdef int i = (u * self.hash_length) + (v & self.hash_mask)
1013+
cdef int compared
10141014
cdef SparseGraphBTNode *temp = self.vertices[i]
1015-
cdef SparseGraphLLNode *label
10161015
while temp:
10171016
compared = compare(temp.vertex, v)
10181017
if compared > 0:

src/sage/graphs/base/static_dense_graph.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def is_strongly_regular(g, parameters=False):
216216
cdef bitset_t b_tmp
217217
cdef int n = g.order()
218218
cdef int inter
219-
cdef int i, j, l, k
219+
cdef int i, j, k
220220

221221
if not g.order() or not g.size(): # no vertices or no edges
222222
return False

src/sage/graphs/base/static_sparse_backend.pyx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,6 @@ cdef class StaticSparseBackend(CGraphBackend):
684684
raise LookupError("one of the two vertices does not belong to the graph")
685685

686686
cdef StaticSparseCGraph cg = self._cg
687-
cdef list l
688687

689688
cdef uint32_t * edge = has_edge(cg.g, u, v)
690689
if not edge:
@@ -696,9 +695,7 @@ cdef class StaticSparseBackend(CGraphBackend):
696695
# all labels.
697696
if self.multiple_edges(None):
698697
return self._all_edge_labels(u, v, edge)
699-
700-
else:
701-
return edge_label(cg.g, edge)
698+
return edge_label(cg.g, edge)
702699

703700
cdef inline list _all_edge_labels(self, int u, int v, uint32_t* edge=NULL):
704701
"""
@@ -1079,7 +1076,7 @@ cdef class StaticSparseBackend(CGraphBackend):
10791076
- ``2`` -- as ``1`` but ignore the labels
10801077
"""
10811078
cdef object v, l
1082-
cdef int u_int, prev_u_int, v_int, l_int, l_int_other, tmp
1079+
cdef int u_int, prev_u_int, v_int, l_int_other, tmp
10831080
cdef StaticSparseCGraph cg = self._cg
10841081
cdef CGraph cg_other = other.cg()
10851082
cdef list b_vertices_2

src/sage/graphs/base/static_sparse_graph.pxd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ ctypedef unsigned int uint
88
cdef extern from "stdlib.h":
99
ctypedef void const_void "const void"
1010
void qsort(void *base, int nmemb, int size,
11-
int(*compar)(const_void *, const_void *)) nogil
11+
int(*compar)(const_void *, const_void *)) nogil
1212

1313
void *bsearch(const_void *key, const_void *base, size_t nmemb,
1414
size_t size, int(*compar)(const_void *, const_void *)) nogil
1515

1616
ctypedef struct short_digraph_s:
17-
uint32_t * edges
18-
uint32_t ** neighbors
19-
PyObject * edge_labels
20-
int m
21-
int n
17+
uint32_t * edges
18+
uint32_t ** neighbors
19+
PyObject * edge_labels
20+
int m
21+
int n
2222

2323
ctypedef short_digraph_s short_digraph[1]
2424

src/sage/graphs/base/static_sparse_graph.pyx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ with C arguments).
182182
# ****************************************************************************
183183

184184
cimport cpython
185-
from libc.string cimport memset
186185
from libc.limits cimport INT_MAX
187186
from libc.math cimport sqrt
188187
from libcpp.vector cimport vector
@@ -783,7 +782,6 @@ cdef void strongly_connected_components_digraph_C(short_digraph g, int nscc, int
783782
cdef MemoryAllocator mem = MemoryAllocator()
784783
cdef size_t v, w, i
785784
cdef size_t s_nscc = <size_t>nscc
786-
cdef int tmp = nscc + 1
787785
cdef vector[vector[int]] scc_list = vector[vector[int]](nscc, vector[int]())
788786
cdef vector[vector[int]] sons = vector[vector[int]](nscc + 1, vector[int]())
789787
cdef vector[int].iterator iter
@@ -827,7 +825,6 @@ cdef void strongly_connected_components_digraph_C(short_digraph g, int nscc, int
827825
output.neighbors[0] = output.edges
828826

829827
for v in range(1, s_nscc + 1):
830-
degv = sons[v].size()
831828
output.neighbors[v] = output.neighbors[v - 1] + sons[v - 1].size()
832829
for i in range(sons[v].size()):
833830
output.neighbors[v][i] = sons[v][i]

0 commit comments

Comments
 (0)