Ticket #7733: trac_7733.patch

File trac_7733.patch, 2.5 KB (added by ncohen, 11 years ago)
  • sage/graphs/digraph.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1266862582 -3600
    # Node ID 63c0a8169571194db5606bcd0358fcc863071f64
    # Parent  75e9e97a1e60a9acb16300d9f25b065d415019fa
    Ticket #7733 : Graph(g) and DiGraph(g) did not keep the embedding
    
    diff -r 75e9e97a1e60 -r 63c0a8169571 sage/graphs/digraph.py
    a b  
    293293            sage: a = matrix(2,2,[3,2,0,1])
    294294            sage: DiGraph(a,sparse=True).adjacency_matrix() == a
    295295            True
     296
     297        The positions are copied when the DiGraph is built from
     298        another DiGraph or from a Graph ::
     299
     300            sage: g = DiGraph(graphs.PetersenGraph())
     301            sage: h = DiGraph(g)
     302            sage: g.get_pos() == h.get_pos()
     303            True
     304            sage: g.get_pos() == graphs.PetersenGraph().get_pos()
     305            True
    296306        """
    297307        from sage.all import walltime
    298308        msg = ''
     
    435445            if weighted is None: weighted = data.weighted()
    436446            num_verts = data.num_verts()
    437447            verts = data.vertex_iterator()
     448            if data.get_pos() is not None:
     449                pos = data.get_pos().copy()
    438450        elif format == 'rule':
    439451            f = data[1]
    440452            if loops is None: loops = any(f(v,v) for v in data[0])
  • sage/graphs/graph.py

    diff -r 75e9e97a1e60 -r 63c0a8169571 sage/graphs/graph.py
    a b  
    771771            sage: a = matrix(2,2,[2,0,0,1])
    772772            sage: Graph(a,sparse=True).adjacency_matrix() == a
    773773            True
     774
     775        The positions are copied when the graph is built from
     776        another graph ::
     777
     778            sage: g = graphs.PetersenGraph()
     779            sage: h = Graph(g)
     780            sage: g.get_pos() == h.get_pos()
     781            True
     782
     783        Or from a DiGraph ::
     784
     785            sage: d = DiGraph(g)
     786            sage: h = Graph(d)
     787            sage: g.get_pos() == h.get_pos()
     788            True
     789           
    774790        """
    775791        GenericGraph.__init__(self)
    776792        msg = ''
     
    953969            if weighted is None: weighted = data.weighted()
    954970            num_verts = data.num_verts()
    955971            verts = data.vertex_iterator()
     972            if data.get_pos() is not None:
     973                pos = data.get_pos().copy()
     974
    956975        elif format == 'rule':
    957976            f = data[1]
    958977            if loops is None: loops = any(f(v,v) for v in data[0])