Skip to content

Commit 6d1cb7e

Browse files
author
Release Manager
committed
gh-35718: `sage.graphs`: More modularization <!-- 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 <!-- Describe your changes here in detail. --> Mostly using `lazy_import` and adding `# optional` annotations to doctests. <!-- 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". --> - Part of: #29705 - Cherry-picked from: #35095 <!-- 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. - [x] 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: #35718 Reported by: Matthias Köppe Reviewer(s): David Coudert, Matthias Köppe
2 parents a2e4cab + 2891cd8 commit 6d1cb7e

40 files changed

+1505
-1409
lines changed

src/sage/graphs/all.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
lazy_import("sage.graphs.graph_generators", "graphs")
55
lazy_import("sage.graphs.digraph_generators", "digraphs")
66
lazy_import("sage.graphs.hypergraph_generators", "hypergraphs")
7-
from .graph_database import GraphDatabase, GenericGraphQuery, GraphQuery
7+
lazy_import("sage.graphs.graph_database", ["GraphDatabase", "GenericGraphQuery", "GraphQuery"])
88
from .graph import Graph
99
from .digraph import DiGraph
1010
from .bipartite_graph import BipartiteGraph
@@ -13,7 +13,7 @@
1313
import sage.graphs.partial_cube
1414
from . import graph_list as graphs_list
1515
lazy_import("sage.graphs", "graph_coloring")
16-
from .graph_database import graph_db_info
16+
lazy_import("sage.graphs.graph_database", "graph_db_info")
1717
lazy_import("sage.graphs.graph_editor", "graph_editor")
1818

1919
from sage.graphs.isgci import graph_classes

src/sage/graphs/base/boost_graph.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ cpdef bandwidth_heuristics(g, algorithm='cuthill_mckee'):
572572
from sage.graphs.base.boost_graph import bandwidth_heuristics
573573
sage: bandwidth_heuristics(Graph())
574574
(0, [])
575-
sage: bandwidth_heuristics(graphs.RandomGNM(10,0))
575+
sage: bandwidth_heuristics(graphs.RandomGNM(10,0)) # optional - networkx
576576
(0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
577577
578578
"""
@@ -1964,8 +1964,8 @@ cpdef diameter_DHV(g, weight_function=None, check_weight=True):
19641964
19651965
TESTS::
19661966
1967-
sage: G = graphs.RandomBarabasiAlbert(17,6)
1968-
sage: diameter_DHV(G) == G.diameter(algorithm = 'Dijkstra_Boost')
1967+
sage: G = graphs.RandomBarabasiAlbert(17,6) # optional - networkx
1968+
sage: diameter_DHV(G) == G.diameter(algorithm = 'Dijkstra_Boost') # optional - networkx
19691969
True
19701970
sage: G = Graph([(0,1,-1)], weighted=True)
19711971
sage: diameter_DHV(G)

src/sage/graphs/base/c_graph.pyx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,11 +1577,11 @@ cdef class CGraphBackend(GenericGraphBackend):
15771577
We check that the bug described in :trac:`8406` is gone::
15781578
15791579
sage: G = Graph()
1580-
sage: R.<a> = GF(3**3)
1581-
sage: S.<x> = R[]
1582-
sage: G.add_vertex(a**2)
1583-
sage: G.add_vertex(x)
1584-
sage: G.vertices(sort=True)
1580+
sage: R.<a> = GF(3**3) # optional - sage.rings.finite_rings
1581+
sage: S.<x> = R[] # optional - sage.rings.finite_rings
1582+
sage: G.add_vertex(a**2) # optional - sage.rings.finite_rings
1583+
sage: G.add_vertex(x) # optional - sage.rings.finite_rings
1584+
sage: G.vertices(sort=True) # optional - sage.rings.finite_rings
15851585
[a^2, x]
15861586
15871587
And that the bug described in :trac:`9610` is gone::
@@ -2107,9 +2107,9 @@ cdef class CGraphBackend(GenericGraphBackend):
21072107
21082108
Ensure that :trac:`13664` is fixed ::
21092109
2110-
sage: W = WeylGroup(["A",1])
2111-
sage: G = W.cayley_graph()
2112-
sage: Graph(G).degree()
2110+
sage: W = WeylGroup(["A",1]) # optional - sage.combinat sage.groups
2111+
sage: G = W.cayley_graph() # optional - sage.combinat sage.groups
2112+
sage: Graph(G).degree() # optional - sage.combinat sage.groups
21132113
[1, 1]
21142114
sage: h = Graph()
21152115
sage: h.add_edge(1,2,"a")
@@ -4406,9 +4406,9 @@ cdef class CGraphBackend(GenericGraphBackend):
44064406
44074407
TESTS::
44084408
4409-
sage: P = posets.PentagonPoset()
4410-
sage: H = P._hasse_diagram
4411-
sage: H._backend.is_connected()
4409+
sage: P = posets.PentagonPoset() # optional - sage.modules
4410+
sage: H = P._hasse_diagram # optional - sage.modules
4411+
sage: H._backend.is_connected() # optional - sage.modules
44124412
True
44134413
"""
44144414
cdef int v_int
@@ -4589,9 +4589,9 @@ cdef class CGraphBackend(GenericGraphBackend):
45894589
45904590
TESTS::
45914591
4592-
sage: m = Matrix(3,[0, 1, 1, 0, 0, 0, 0, 1, 0])
4593-
sage: g = DiGraph(m)
4594-
sage: g.is_directed_acyclic(certificate=True)
4592+
sage: m = Matrix(3,[0, 1, 1, 0, 0, 0, 0, 1, 0]) # optional - sage.modules
4593+
sage: g = DiGraph(m) # optional - sage.modules
4594+
sage: g.is_directed_acyclic(certificate=True) # optional - sage.modules
45954595
(True, [0, 2, 1])
45964596
"""
45974597
if not self._directed:

src/sage/graphs/base/static_sparse_backend.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,17 +446,17 @@ cdef class StaticSparseBackend(CGraphBackend):
446446
447447
::
448448
449-
sage: g = DiGraph(digraphs.DeBruijn(4, 3), data_structure="static_sparse")
450-
sage: gi = DiGraph(g, data_structure="static_sparse")
451-
sage: gi.edges(sort=True)[0]
449+
sage: g = DiGraph(digraphs.DeBruijn(4, 3), data_structure="static_sparse") # optional - sage.combinat
450+
sage: gi = DiGraph(g, data_structure="static_sparse") # optional - sage.combinat
451+
sage: gi.edges(sort=True)[0] # optional - sage.combinat
452452
('000', '000', '0')
453-
sage: sorted(gi.edges_incident('111'))
453+
sage: sorted(gi.edges_incident('111')) # optional - sage.combinat
454454
[('111', '110', '0'),
455455
('111', '111', '1'),
456456
('111', '112', '2'),
457457
('111', '113', '3')]
458458
459-
sage: set(g.edges(sort=False)) == set(gi.edges(sort=False))
459+
sage: set(g.edges(sort=False)) == set(gi.edges(sort=False)) # optional - sage.combinat
460460
True
461461
462462
::
@@ -671,10 +671,10 @@ cdef class StaticSparseBackend(CGraphBackend):
671671
::
672672
673673
sage: from sage.graphs.base.static_sparse_backend import StaticSparseBackend
674-
sage: g = StaticSparseBackend(digraphs.DeBruijn(3, 2))
675-
sage: g.has_edge('00', '01', '1')
674+
sage: g = StaticSparseBackend(digraphs.DeBruijn(3, 2)) # optional - sage.combinat
675+
sage: g.has_edge('00', '01', '1') # optional - sage.combinat
676676
True
677-
sage: g.has_edge('00', '01', '0')
677+
sage: g.has_edge('00', '01', '0') # optional - sage.combinat
678678
False
679679
"""
680680
try:

0 commit comments

Comments
 (0)