Skip to content

Commit

Permalink
Trac #15491: directed immutable graphs report twice too many edges
Browse files Browse the repository at this point in the history
As reported on #15278 :

{{{
sage: g=digraphs.RandomDirectedGNP(10,.3)
sage: gi=DiGraph(g,data_structure="static_sparse")
sage: print gi.size(), len(gi.edges())
68 34
}}}

Simplest bug eve : Sage was taught to return the wrong thing. The sum of
all arcs in the digraph, plus the sum of all arcs in the reversed
digraph. That's clearly more than necessary `:-P`

Sorryyyyyyyyyyyyyyyyyyyy !!

Nathann

URL: http://trac.sagemath.org/15491
Reported by: ncohen
Ticket author(s): Nathann Cohen
Reviewer(s): Simon King
  • Loading branch information
Release Manager authored and vbraun committed Dec 18, 2013
2 parents 85a23f3 + 020cc82 commit 4d1aaef
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/sage/graphs/base/static_sparse_backend.pyx
Expand Up @@ -676,23 +676,40 @@ class StaticSparseBackend(CGraphBackend):
INPUT:
- ``directed`` (boolean) -- whether to consider the graph as directed or
not (
not.
TEST::
sage: from sage.graphs.base.static_sparse_backend import StaticSparseBackend
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 = <StaticSparseCGraph> 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:
Expand Down

0 comments on commit 4d1aaef

Please sign in to comment.