Skip to content

Commit 94bca97

Browse files
author
Matthias Koeppe
committed
sage.graphs: Add # optional
1 parent 42363bf commit 94bca97

34 files changed

+735
-707
lines changed

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: 5 additions & 5 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
::

src/sage/graphs/bipartite_graph.py

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,16 @@ class BipartiteGraph(Graph):
198198
199199
#. From a reduced adjacency matrix::
200200
201-
sage: M = Matrix([(1,1,1,0,0,0,0), (1,0,0,1,1,0,0),
201+
sage: M = Matrix([(1,1,1,0,0,0,0), (1,0,0,1,1,0,0), # optional - sage.modules
202202
....: (0,1,0,1,0,1,0), (1,1,0,1,0,0,1)])
203-
sage: M
203+
sage: M # optional - sage.modules
204204
[1 1 1 0 0 0 0]
205205
[1 0 0 1 1 0 0]
206206
[0 1 0 1 0 1 0]
207207
[1 1 0 1 0 0 1]
208-
sage: H = BipartiteGraph(M); H
208+
sage: H = BipartiteGraph(M); H # optional - sage.modules
209209
Bipartite graph on 11 vertices
210-
sage: H.edges(sort=True)
210+
sage: H.edges(sort=True) # optional - sage.modules
211211
[(0, 7, None),
212212
(0, 8, None),
213213
(0, 10, None),
@@ -224,9 +224,9 @@ class BipartiteGraph(Graph):
224224
225225
::
226226
227-
sage: M = Matrix([(1, 1, 2, 0, 0), (0, 2, 1, 1, 1), (0, 1, 2, 1, 1)])
228-
sage: B = BipartiteGraph(M, multiedges=True, sparse=True)
229-
sage: B.edges(sort=True)
227+
sage: M = Matrix([(1, 1, 2, 0, 0), (0, 2, 1, 1, 1), (0, 1, 2, 1, 1)]) # optional - sage.modules
228+
sage: B = BipartiteGraph(M, multiedges=True, sparse=True) # optional - sage.modules
229+
sage: B.edges(sort=True) # optional - sage.modules
230230
[(0, 5, None),
231231
(1, 5, None),
232232
(1, 6, None),
@@ -244,13 +244,13 @@ class BipartiteGraph(Graph):
244244
245245
::
246246
247-
sage: F.<a> = GF(4)
248-
sage: MS = MatrixSpace(F, 2, 3)
249-
sage: M = MS.matrix([[0, 1, a + 1], [a, 1, 1]])
250-
sage: B = BipartiteGraph(M, weighted=True, sparse=True)
251-
sage: B.edges(sort=True)
247+
sage: F.<a> = GF(4) # optional - sage.modules sage.rings.finite_rings
248+
sage: MS = MatrixSpace(F, 2, 3) # optional - sage.modules sage.rings.finite_rings
249+
sage: M = MS.matrix([[0, 1, a + 1], [a, 1, 1]]) # optional - sage.modules sage.rings.finite_rings
250+
sage: B = BipartiteGraph(M, weighted=True, sparse=True) # optional - sage.modules sage.rings.finite_rings
251+
sage: B.edges(sort=True) # optional - sage.modules sage.rings.finite_rings
252252
[(0, 4, a), (1, 3, 1), (1, 4, 1), (2, 3, a + 1), (2, 4, 1)]
253-
sage: B.weighted()
253+
sage: B.weighted() # optional - sage.modules sage.rings.finite_rings
254254
True
255255
256256
#. From an alist file::
@@ -264,7 +264,7 @@ class BipartiteGraph(Graph):
264264
....: 1 2 4 7 \n")
265265
....: f.flush()
266266
....: B = BipartiteGraph(f.name)
267-
sage: B.is_isomorphic(H)
267+
sage: B.is_isomorphic(H) # optional - sage.modules
268268
True
269269
270270
#. From a ``graph6`` string::
@@ -328,15 +328,15 @@ class BipartiteGraph(Graph):
328328
Ensure that we can construct a ``BipartiteGraph`` with isolated vertices via
329329
the reduced adjacency matrix (:trac:`10356`)::
330330
331-
sage: a = BipartiteGraph(matrix(2, 2, [1, 0, 1, 0]))
332-
sage: a
331+
sage: a = BipartiteGraph(matrix(2, 2, [1, 0, 1, 0])) # optional - sage.modules
332+
sage: a # optional - sage.modules
333333
Bipartite graph on 4 vertices
334-
sage: a.vertices(sort=True)
334+
sage: a.vertices(sort=True) # optional - sage.modules
335335
[0, 1, 2, 3]
336-
sage: g = BipartiteGraph(matrix(4, 4, [1] * 4 + [0] * 12))
337-
sage: g.vertices(sort=True)
336+
sage: g = BipartiteGraph(matrix(4, 4, [1] * 4 + [0] * 12)) # optional - sage.modules
337+
sage: g.vertices(sort=True) # optional - sage.modules
338338
[0, 1, 2, 3, 4, 5, 6, 7]
339-
sage: sorted(g.left.union(g.right))
339+
sage: sorted(g.left.union(g.right)) # optional - sage.modules
340340
[0, 1, 2, 3, 4, 5, 6, 7]
341341
342342
Make sure that loops are not allowed (:trac:`23275`)::
@@ -1805,26 +1805,26 @@ def save_afile(self, fname):
18051805
18061806
EXAMPLES::
18071807
1808-
sage: M = Matrix([(1,1,1,0,0,0,0), (1,0,0,1,1,0,0),
1808+
sage: M = Matrix([(1,1,1,0,0,0,0), (1,0,0,1,1,0,0), # optional - sage.modules
18091809
....: (0,1,0,1,0,1,0), (1,1,0,1,0,0,1)])
1810-
sage: M
1810+
sage: M # optional - sage.modules
18111811
[1 1 1 0 0 0 0]
18121812
[1 0 0 1 1 0 0]
18131813
[0 1 0 1 0 1 0]
18141814
[1 1 0 1 0 0 1]
1815-
sage: b = BipartiteGraph(M)
1816-
sage: import tempfile
1817-
sage: with tempfile.NamedTemporaryFile() as f:
1815+
sage: b = BipartiteGraph(M) # optional - sage.modules
1816+
sage: import tempfile # optional - sage.modules
1817+
sage: with tempfile.NamedTemporaryFile() as f: # optional - sage.modules
18181818
....: b.save_afile(f.name)
18191819
....: b2 = BipartiteGraph(f.name)
1820-
sage: b.is_isomorphic(b2)
1820+
sage: b.is_isomorphic(b2) # optional - sage.modules
18211821
True
18221822
18231823
TESTS::
18241824
18251825
sage: import tempfile
18261826
sage: f = tempfile.NamedTemporaryFile()
1827-
sage: for order in range(3, 13, 3):
1827+
sage: for order in range(3, 13, 3): # optional - sage.combinat
18281828
....: num_chks = int(order / 3)
18291829
....: num_vars = order - num_chks
18301830
....: partition = (list(range(num_vars)), list(range(num_vars, num_vars+num_chks)))
@@ -1922,78 +1922,78 @@ def reduced_adjacency_matrix(self, sparse=True, *, base_ring=None, **kwds):
19221922
Bipartite graphs that are not weighted will return a matrix over ZZ,
19231923
unless a base ring is specified::
19241924
1925-
sage: M = Matrix([(1,1,1,0,0,0,0), (1,0,0,1,1,0,0),
1925+
sage: M = Matrix([(1,1,1,0,0,0,0), (1,0,0,1,1,0,0), # optional - sage.modules
19261926
....: (0,1,0,1,0,1,0), (1,1,0,1,0,0,1)])
1927-
sage: B = BipartiteGraph(M)
1928-
sage: N = B.reduced_adjacency_matrix()
1929-
sage: N
1927+
sage: B = BipartiteGraph(M) # optional - sage.modules
1928+
sage: N = B.reduced_adjacency_matrix() # optional - sage.modules
1929+
sage: N # optional - sage.modules
19301930
[1 1 1 0 0 0 0]
19311931
[1 0 0 1 1 0 0]
19321932
[0 1 0 1 0 1 0]
19331933
[1 1 0 1 0 0 1]
1934-
sage: N == M
1934+
sage: N == M # optional - sage.modules
19351935
True
1936-
sage: N[0,0].parent()
1936+
sage: N[0,0].parent() # optional - sage.modules
19371937
Integer Ring
1938-
sage: N2 = B.reduced_adjacency_matrix(base_ring=RDF); N2
1938+
sage: N2 = B.reduced_adjacency_matrix(base_ring=RDF); N2 # optional - sage.modules
19391939
[1.0 1.0 1.0 0.0 0.0 0.0 0.0]
19401940
[1.0 0.0 0.0 1.0 1.0 0.0 0.0]
19411941
[0.0 1.0 0.0 1.0 0.0 1.0 0.0]
19421942
[1.0 1.0 0.0 1.0 0.0 0.0 1.0]
1943-
sage: N2[0, 0].parent()
1943+
sage: N2[0, 0].parent() # optional - sage.modules
19441944
Real Double Field
19451945
19461946
Multi-edge graphs also return a matrix over ZZ,
19471947
unless a base ring is specified::
19481948
1949-
sage: M = Matrix([(1,1,2,0,0), (0,2,1,1,1), (0,1,2,1,1)])
1950-
sage: B = BipartiteGraph(M, multiedges=True, sparse=True)
1951-
sage: N = B.reduced_adjacency_matrix()
1952-
sage: N == M
1949+
sage: M = Matrix([(1,1,2,0,0), (0,2,1,1,1), (0,1,2,1,1)]) # optional - sage.modules
1950+
sage: B = BipartiteGraph(M, multiedges=True, sparse=True) # optional - sage.modules
1951+
sage: N = B.reduced_adjacency_matrix() # optional - sage.modules
1952+
sage: N == M # optional - sage.modules
19531953
True
1954-
sage: N[0,0].parent()
1954+
sage: N[0,0].parent() # optional - sage.modules
19551955
Integer Ring
1956-
sage: N2 = B.reduced_adjacency_matrix(base_ring=RDF)
1957-
sage: N2[0, 0].parent()
1956+
sage: N2 = B.reduced_adjacency_matrix(base_ring=RDF) # optional - sage.modules
1957+
sage: N2[0, 0].parent() # optional - sage.modules
19581958
Real Double Field
19591959
19601960
Weighted graphs will return a matrix over the ring given by their
19611961
(first) weights, unless a base ring is specified::
19621962
1963-
sage: F.<a> = GF(4)
1964-
sage: MS = MatrixSpace(F, 2, 3)
1965-
sage: M = MS.matrix([[0, 1, a+1], [a, 1, 1]])
1966-
sage: B = BipartiteGraph(M, weighted=True, sparse=True)
1967-
sage: N = B.reduced_adjacency_matrix(sparse=False)
1968-
sage: N == M
1963+
sage: F.<a> = GF(4) # optional - sage.modules sage.rings.finite_rings
1964+
sage: MS = MatrixSpace(F, 2, 3) # optional - sage.modules sage.rings.finite_rings
1965+
sage: M = MS.matrix([[0, 1, a+1], [a, 1, 1]]) # optional - sage.modules sage.rings.finite_rings
1966+
sage: B = BipartiteGraph(M, weighted=True, sparse=True) # optional - sage.modules sage.rings.finite_rings
1967+
sage: N = B.reduced_adjacency_matrix(sparse=False) # optional - sage.modules sage.rings.finite_rings
1968+
sage: N == M # optional - sage.modules sage.rings.finite_rings
19691969
True
1970-
sage: N[0,0].parent()
1970+
sage: N[0,0].parent() # optional - sage.modules sage.rings.finite_rings
19711971
Finite Field in a of size 2^2
1972-
sage: N2 = B.reduced_adjacency_matrix(base_ring=F)
1973-
sage: N2[0, 0].parent()
1972+
sage: N2 = B.reduced_adjacency_matrix(base_ring=F) # optional - sage.modules sage.rings.finite_rings
1973+
sage: N2[0, 0].parent() # optional - sage.modules sage.rings.finite_rings
19741974
Finite Field in a of size 2^2
19751975
19761976
TESTS::
19771977
19781978
sage: B = BipartiteGraph()
1979-
sage: B.reduced_adjacency_matrix()
1979+
sage: B.reduced_adjacency_matrix() # optional - sage.modules
19801980
[]
1981-
sage: M = Matrix([[0,0], [0,0]])
1982-
sage: BipartiteGraph(M).reduced_adjacency_matrix() == M
1981+
sage: M = Matrix([[0,0], [0,0]]) # optional - sage.modules
1982+
sage: BipartiteGraph(M).reduced_adjacency_matrix() == M # optional - sage.modules
19831983
True
1984-
sage: M = Matrix([[10,2/3], [0,0]])
1985-
sage: B = BipartiteGraph(M, weighted=True, sparse=True)
1986-
sage: M == B.reduced_adjacency_matrix()
1984+
sage: M = Matrix([[10,2/3], [0,0]]) # optional - sage.modules
1985+
sage: B = BipartiteGraph(M, weighted=True, sparse=True) # optional - sage.modules
1986+
sage: M == B.reduced_adjacency_matrix() # optional - sage.modules
19871987
True
19881988
19891989
An error is raised if the specified base ring is not compatible with the
19901990
type of the weights of the bipartite graph::
19911991
1992-
sage: F.<a> = GF(4)
1993-
sage: MS = MatrixSpace(F, 2, 3)
1994-
sage: M = MS.matrix([[0, 1, a+1], [a, 1, 1]])
1995-
sage: B = BipartiteGraph(M, weighted=True, sparse=True)
1996-
sage: B.reduced_adjacency_matrix(base_ring=RDF)
1992+
sage: F.<a> = GF(4) # optional - sage.modules sage.rings.finite_rings
1993+
sage: MS = MatrixSpace(F, 2, 3) # optional - sage.modules sage.rings.finite_rings
1994+
sage: M = MS.matrix([[0, 1, a+1], [a, 1, 1]]) # optional - sage.modules sage.rings.finite_rings
1995+
sage: B = BipartiteGraph(M, weighted=True, sparse=True) # optional - sage.modules sage.rings.finite_rings
1996+
sage: B.reduced_adjacency_matrix(base_ring=RDF) # optional - sage.modules sage.rings.finite_rings
19971997
Traceback (most recent call last):
19981998
...
19991999
TypeError: float() argument must be a string or a ...number, not 'sage.rings.finite_rings.element_givaro.FiniteField_givaroElement'

0 commit comments

Comments
 (0)