diff --git a/src/sage/graphs/base/static_sparse_backend.pyx b/src/sage/graphs/base/static_sparse_backend.pyx index 35df74c0393..ad848c55943 100644 --- a/src/sage/graphs/base/static_sparse_backend.pyx +++ b/src/sage/graphs/base/static_sparse_backend.pyx @@ -676,7 +676,7 @@ class StaticSparseBackend(CGraphBackend): INPUT: - ``directed`` (boolean) -- whether to consider the graph as directed or - not ( + not. TEST:: @@ -684,15 +684,32 @@ class StaticSparseBackend(CGraphBackend): sage: g = StaticSparseBackend(graphs.PetersenGraph()) sage: g.num_edges(False) 15 + + Testing the exception:: + + sage: g = StaticSparseBackend(digraphs.Circuit(4)) + sage: g.num_edges(False) + Traceback (most recent call last): + ... + NotImplementedError: Sorry, I have no idea what is expected in this situation. I don't think that it is well-defined either, especially for multigraphs. + + :trac:`15491`:: + + sage: g=digraphs.RandomDirectedGNP(10,.3) + sage: gi=DiGraph(g,data_structure="static_sparse") + sage: gi.size() == len(gi.edges()) + True """ cdef StaticSparseCGraph cg = self._cg - cdef unsigned int m + if directed: if cg.directed: # Returns the real number of directed arcs - return int(cg.g.m+cg.g_rev.m) + return int(cg.g.m) else: - # Returns twice the number of edges, minus the number of loops + # Returns twice the number of edges, minus the number of + # loops. This is actually equal to the index of + # cg.g.neighbors[cg.g.n] in the array `cg.g.edges` return int(cg.g.neighbors[cg.g.n]-cg.g.edges) else: if cg.directed: