Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

partial cython-linting in graphs/ #35453

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/sage/graphs/base/boost_graph.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,6 @@ cpdef johnson_shortest_paths(g, weight_function=None, distances=True, predecesso
cdef BoostVecWeightedGraph g_boost_und
cdef int N = g.num_verts()
cdef vector[vector[double]] result
cdef int u_int, v_int

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

if g.is_directed():
boost_weighted_graph_from_sage_graph(&g_boost_dir, g, v_to_int, weight_function)
Expand Down Expand Up @@ -2330,13 +2328,13 @@ cdef double diameter_DiFUB(BoostVecWeightedDiGraphU g_boost,
import sys
# These variables are automatically deleted when the function terminates.
cdef double LB, LB_1, LB_2, UB
cdef v_index s, m, d, v, tmp
cdef v_index m, v, tmp
cdef v_index i
cdef vector[double] distances
cdef vector[pair[double, v_index]] order_1, order_2

# We select a vertex with low eccentricity using 2Dsweep
LB, s, m, d = diameter_lower_bound_2Dsweep(g_boost, rev_g_boost,
LB, _, m, _ = diameter_lower_bound_2Dsweep(g_boost, rev_g_boost,
source, algorithm)

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

# These variables are automatically deleted when the function terminates.
cdef v_index vi, u, v
cdef dict int_to_v = dict(enumerate(g))
cdef dict v_to_int = {vv: vi for vi, vv in enumerate(g)}
cdef BoostVecWeightedDiGraphU g_boost_dir
cdef BoostVecWeightedGraph g_boost_und
Expand Down
7 changes: 2 additions & 5 deletions src/sage/graphs/base/c_graph.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ method :meth:`realloc <sage.graphs.base.c_graph.CGraph.realloc>`.
# ****************************************************************************

from sage.data_structures.bitset_base cimport *
from sage.rings.integer cimport Integer, smallInteger
from sage.rings.integer cimport smallInteger
from sage.arith.long cimport pyobject_to_long
from libcpp.queue cimport priority_queue, queue
from libcpp.stack cimport stack
Expand Down Expand Up @@ -3751,7 +3751,6 @@ cdef class CGraphBackend(GenericGraphBackend):
# studied.
cdef int x_int = self.get_vertex(x)
cdef int y_int = self.get_vertex(y)
cdef int u = 0
cdef int v = 0
cdef int w = 0
cdef int pred
Expand Down Expand Up @@ -3978,7 +3977,6 @@ cdef class CGraphBackend(GenericGraphBackend):
# studied.
cdef int x_int = self.get_vertex(x)
cdef int y_int = self.get_vertex(y)
cdef int u = 0
cdef int v = 0
cdef int w = 0
cdef int pred
Expand Down Expand Up @@ -4680,7 +4678,6 @@ cdef class CGraphBackend(GenericGraphBackend):
# // answer = [u]
cycle = [self.vertex_label(u)]

tmp = u
while u != uu:
u = parent.get(u, uu)
cycle.append(self.vertex_label(u))
Expand Down Expand Up @@ -4899,7 +4896,7 @@ cdef class Search_iterator:
sage: next(g.breadth_first_search(0))
0
"""
cdef int v_int, v_dist
cdef int v_int
cdef int w_int
cdef int l
cdef CGraph cg = self.graph.cg()
Expand Down
8 changes: 3 additions & 5 deletions src/sage/graphs/base/dense_graph.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,15 @@ cdef class DenseGraph(CGraph):
sage: D.realloc(30)
sage: D.current_allocation()
30

"""
cdef int i, j
cdef int i
if not total_verts:
raise RuntimeError('dense graphs must allocate space for vertices')

cdef bitset_t bits
cdef int min_verts, min_longs
cdef int min_verts
if <size_t>total_verts < self.active_vertices.size:
min_verts = total_verts
min_longs = -1
bitset_init(bits, self.active_vertices.size)
bitset_set_first_n(bits, total_verts)
if not bitset_issubset(self.active_vertices, bits):
Expand Down Expand Up @@ -402,7 +400,7 @@ cdef class DenseGraph(CGraph):
"""
cdef int num_arcs_old = self.num_arcs

cdef size_t i, j
cdef size_t i
i = bitset_next(self.active_vertices, 0)
while i != -1:
self.add_arc_unsafe(i, i)
Expand Down
4 changes: 1 addition & 3 deletions src/sage/graphs/base/graph_backends.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ For an overview of graph data structures in sage, see
Classes and methods
-------------------
"""

# ****************************************************************************
# Copyright (C) 2008 Robert L. Miller <rlmillster@gmail.com>
# 2018 Julian RΓΌth <julian.rueth@fsfe.org>
Expand All @@ -58,8 +57,7 @@ Classes and methods
# (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************

from .c_graph cimport CGraphBackend, CGraph
from .c_graph cimport CGraphBackend


cdef class GenericGraphBackend(SageObject):
Expand Down
7 changes: 4 additions & 3 deletions src/sage/graphs/base/sparse_graph.pxd
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2008-2009 Robert L. Miller <rlmillster@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

from .c_graph cimport CGraph, CGraphBackend
cimport cython
Expand All @@ -23,6 +23,7 @@ cdef struct SparseGraphBTNode:
SparseGraphBTNode *left
SparseGraphBTNode *right


@cython.final
cdef class SparseGraph(CGraph):
cdef int hash_length
Expand Down
5 changes: 2 additions & 3 deletions src/sage/graphs/base/sparse_graph.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1009,10 +1009,9 @@ cdef class SparseGraph(CGraph):

- a pointer to the first label or ``NULL`` if there are none
"""
cdef int i = (u * self.hash_length) + (v & self.hash_mask), j
cdef int compared, num_arcs
cdef int i = (u * self.hash_length) + (v & self.hash_mask)
cdef int compared
cdef SparseGraphBTNode *temp = self.vertices[i]
cdef SparseGraphLLNode *label
while temp:
compared = compare(temp.vertex, v)
if compared > 0:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/base/static_dense_graph.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def is_strongly_regular(g, parameters=False):
cdef bitset_t b_tmp
cdef int n = g.order()
cdef int inter
cdef int i, j, l, k
cdef int i, j, k

if not g.order() or not g.size(): # no vertices or no edges
return False
Expand Down
7 changes: 2 additions & 5 deletions src/sage/graphs/base/static_sparse_backend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,6 @@ cdef class StaticSparseBackend(CGraphBackend):
raise LookupError("one of the two vertices does not belong to the graph")

cdef StaticSparseCGraph cg = self._cg
cdef list l

cdef uint32_t * edge = has_edge(cg.g, u, v)
if not edge:
Expand All @@ -696,9 +695,7 @@ cdef class StaticSparseBackend(CGraphBackend):
# all labels.
if self.multiple_edges(None):
return self._all_edge_labels(u, v, edge)

else:
return edge_label(cg.g, edge)
return edge_label(cg.g, edge)

cdef inline list _all_edge_labels(self, int u, int v, uint32_t* edge=NULL):
"""
Expand Down Expand Up @@ -1079,7 +1076,7 @@ cdef class StaticSparseBackend(CGraphBackend):
- ``2`` -- as ``1`` but ignore the labels
"""
cdef object v, l
cdef int u_int, prev_u_int, v_int, l_int, l_int_other, tmp
cdef int u_int, prev_u_int, v_int, l_int_other, tmp
cdef StaticSparseCGraph cg = self._cg
cdef CGraph cg_other = other.cg()
cdef list b_vertices_2
Expand Down
12 changes: 6 additions & 6 deletions src/sage/graphs/base/static_sparse_graph.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ ctypedef unsigned int uint
cdef extern from "stdlib.h":
ctypedef void const_void "const void"
void qsort(void *base, int nmemb, int size,
int(*compar)(const_void *, const_void *)) nogil
int(*compar)(const_void *, const_void *)) nogil

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

ctypedef struct short_digraph_s:
uint32_t * edges
uint32_t ** neighbors
PyObject * edge_labels
int m
int n
uint32_t * edges
uint32_t ** neighbors
PyObject * edge_labels
int m
int n

ctypedef short_digraph_s short_digraph[1]

Expand Down
3 changes: 0 additions & 3 deletions src/sage/graphs/base/static_sparse_graph.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ with C arguments).
# ****************************************************************************

cimport cpython
from libc.string cimport memset
from libc.limits cimport INT_MAX
from libc.math cimport sqrt
from libcpp.vector cimport vector
Expand Down Expand Up @@ -783,7 +782,6 @@ cdef void strongly_connected_components_digraph_C(short_digraph g, int nscc, int
cdef MemoryAllocator mem = MemoryAllocator()
cdef size_t v, w, i
cdef size_t s_nscc = <size_t>nscc
cdef int tmp = nscc + 1
cdef vector[vector[int]] scc_list = vector[vector[int]](nscc, vector[int]())
cdef vector[vector[int]] sons = vector[vector[int]](nscc + 1, vector[int]())
cdef vector[int].iterator iter
Expand Down Expand Up @@ -827,7 +825,6 @@ cdef void strongly_connected_components_digraph_C(short_digraph g, int nscc, int
output.neighbors[0] = output.edges

for v in range(1, s_nscc + 1):
degv = sons[v].size()
output.neighbors[v] = output.neighbors[v - 1] + sons[v - 1].size()
for i in range(sons[v].size()):
output.neighbors[v][i] = sons[v][i]
Expand Down
9 changes: 2 additions & 7 deletions src/sage/graphs/generators/distance_regular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,6 @@ def graph_from_GQ_spread(const int s, const int t):

(GQ, S) = designs.generalised_quadrangle_with_spread(s, t, check=False)

k = len(GQ.blocks()[0])
edges = []
for b in GQ.blocks():
if b in S: # skip blocks in spread
Expand All @@ -1286,8 +1285,7 @@ def graph_from_GQ_spread(const int s, const int t):
sig_check()
edges.append((p1, p2))

G = Graph(edges, format="list_of_edges")
return G
return Graph(edges, format="list_of_edges")


def GeneralisedDodecagonGraph(const int s, const int t):
Expand Down Expand Up @@ -1763,17 +1761,14 @@ def _line_graph_generalised_polygon(H):
sig_check()
vToLines[p].append(l)

k = len(vToLines[lines[0][0]])

edges = []
for v in vToLines:
lines = vToLines[v]
for l1, l2 in itertools.combinations(lines, 2):
sig_check()
edges.append((l1, l2))

G = Graph(edges, format="list_of_edges")
return G
return Graph(edges, format="list_of_edges")


def _intersection_array_from_graph(G):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/graph_decompositions/bandwidth.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def bandwidth(G, k=None):
cdef range_t ** ith_range_array = <range_t **> mem.allocarray(n, sizeof(range_t *))
cdef range_t * range_array_tmp = <range_t *> mem.allocarray(n, sizeof(range_t))

cdef int i, j, kk
cdef int i, kk
# compute the distance matrix
all_pairs_shortest_path_BFS(G, NULL, distances, NULL, vertex_list=int_to_vertex)

Expand Down
3 changes: 0 additions & 3 deletions src/sage/graphs/graph_decompositions/clique_separators.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Methods
# https://www.gnu.org/licenses/
# ****************************************************************************

from libcpp.pair cimport pair
from libcpp.vector cimport vector
from libc.stdint cimport uint32_t
from cysignals.signals cimport sig_on, sig_off, sig_check
Expand Down Expand Up @@ -523,8 +522,6 @@ def atoms_and_clique_separators(G, tree=False, rooted_tree=False, separators=Fal
cdef vector[int] Sint_min
cdef vector[int] Cint
cdef vector[int] Hx
cdef size_t ui, vi
cdef bint stop

for i in range(N):
sig_check()
Expand Down
4 changes: 2 additions & 2 deletions src/sage/graphs/graph_decompositions/cutwidth.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ def cutwidth_dyn(G, lower_bound=0):
finally:
sig_free(neighborhoods)


cdef inline int exists(FastDigraph g, uint8_t* neighborhoods, int S, int cost_S, int v, int k):
r"""
Check whether an ordering with the given cost `k` exists, and updates data
Expand Down Expand Up @@ -571,7 +572,6 @@ cdef inline int exists(FastDigraph g, uint8_t* neighborhoods, int S, int cost_S,
cdef int mini = (<uint8_t> -1)

cdef int i
cdef int next_set

# For each possible extension of the current set with a vertex, check whether
# there exists a cheap path toward {1..n}, and update the cost.
Expand Down Expand Up @@ -735,7 +735,7 @@ def cutwidth_MILP(G, lower_bound=0, solver=None, verbose=0,

p.set_objective(z['z'])

obj = p.solve(log=verbose)
_ = p.solve(log=verbose)

# We now extract the ordering and the cost of the solution
val_x = p.get_values(x, convert=bool, tolerance=integrality_tolerance)
Expand Down
2 changes: 0 additions & 2 deletions src/sage/graphs/graph_decompositions/fast_digraph.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ cdef int compute_out_neighborhood_cardinality(FastDigraph, int)

cdef int popcount32(int)
cdef int slow_popcount32(int)


5 changes: 2 additions & 3 deletions src/sage/graphs/graph_decompositions/fast_digraph.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ cardinality).
In the following code, sets are represented as integers, where the `i`-th bit is
set if element `i` belongs to the set.
"""

from libc.stdint cimport uint8_t
from cysignals.memory cimport check_allocarray, check_calloc, sig_free


cdef class FastDigraph:

def __cinit__(self, D, vertex_list=None):
Expand Down Expand Up @@ -53,7 +52,7 @@ cdef class FastDigraph:
self.n = D.order()
self.graph = <int *>check_calloc(self.n, sizeof(int))

cdef int i, j
cdef int i
cdef int tmp

# When the vertices are not consecutive integers
Expand Down
2 changes: 0 additions & 2 deletions src/sage/graphs/graph_decompositions/graph_products.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ Methods
# https://www.gnu.org/licenses/
# ****************************************************************************

from copy import copy


def is_cartesian_product(g, certificate=False, relabeling=False):
r"""
Expand Down
3 changes: 0 additions & 3 deletions src/sage/graphs/graph_decompositions/rankwidth.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ cdef extern from "rw.h":
subset_t *adjacency_matrix

cdef void print_rank_dec(subset_t s, int l)



Loading