Ticket #11182: trac_11182-review.patch

File trac_11182-review.patch, 4.6 KB (added by ncohen, 10 years ago)
  • sage/graphs/digraph.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1302788234 -7200
    # Node ID 0ea746afe79e1bc496f3a7a054561e98a7d5e7ce
    # Parent  0fd28743cd399b25b0324ffd8a91088497a518fb
    trac 11182 -- replace NetworkX empty dictionaries as edge labels with Sage default None (reviewer's patch)
    
    diff -r 0fd28743cd39 -r 0ea746afe79e sage/graphs/digraph.py
    a b  
    8383
    8484    INPUT:
    8585
    86     -  ``data`` -  can be any of the following:
     86    -  ``data`` -  can be any of the following (see the ``format`` keyword):
    8787
    8888       #.  A dictionary of dictionaries
    8989
     
    9393
    9494       #.  A Sage adjacency matrix or incidence matrix
    9595
    96        #.  A pygraphviz agraph
     96       #.  A pygraphviz graph
    9797
    9898       #.  A SciPy sparse matrix
    9999
     
    133133       -  ``'weighted_adjacency_matrix'`` - a square Sage
    134134          matrix M, with M[i,j] equal to the weight of the single edge {i,j}.
    135135          Given this format, weighted is ignored (assumed True).
     136
     137       -  ``NX`` - data must be a NetworkX DiGraph.
     138           
     139           .. NOTE::
     140
     141               As Sage's default edge labels is ``None`` while NetworkX uses
     142               ``{}``, the ``{}`` labels of a NetworkX digraph are automatically
     143               set to ``None`` when it is converted to a Sage graph. This
     144               behaviour can be overruled by setting the keyword
     145               ``convert_empty_dict_labels_to_None`` to ``False`` (it is
     146               ``True`` by default).
    136147   
    137148    -  ``boundary`` - a list of boundary vertices, if none,
    138149       digraph is considered as a 'digraph without boundary'
  • sage/graphs/graph.py

    diff -r 0fd28743cd39 -r 0ea746afe79e sage/graphs/graph.py
    a b  
    7575Graph Format
    7676------------
    7777
    78 The Sage Graph Class: NetworkX plus
    79 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    80 
    81 Sage graphs are actually NetworkX graphs, wrapped in a Sage class.
    82 In fact, any graph can produce its underlying NetworkX graph. For
    83 example,
    84 
    85 ::
    86 
    87     sage: import networkx
    88     sage: G = graphs.PetersenGraph()
    89     sage: N = G.networkx_graph()
    90     sage: isinstance(N, networkx.graph.Graph)
    91     True
    92 
    93 The NetworkX graph is essentially a dictionary of dictionaries of dictionaries::
    94 
    95     sage: N.adj
    96     {0: {1: {}, 4: {}, 5: {}}, 1: {0: {}, 2: {}, 6: {}}, 2: {1: {}, 3: {}, 7: {}}, 3: {8: {}, 2: {}, 4: {}}, 4: {0: {}, 9: {}, 3: {}}, 5: {0: {}, 8: {}, 7: {}}, 6: {8: {}, 1: {}, 9: {}}, 7: {9: {}, 2: {}, 5: {}}, 8: {3: {}, 5: {}, 6: {}}, 9: {4: {}, 6: {}, 7: {}}}
    97 
    98 Each dictionary key is a vertex label, and each key in the
    99 following dictionary is a neighbor of that vertex. In undirected
    100 graphs, there is redundancy: for example, the dictionary containing
    101 the entry ``1: {2: {}}`` implies it must contain
    102 ``{2: {1: {}}``. The innermost entry of ``{}`` is
    103 related to edge labeling (see section :ref:`Graph:labels`).
    104 
    10578Supported formats
    10679~~~~~~~~~~~~~~~~~
    10780
     
    12396
    12497   ::
    12598
     99       sage: import networkx
    126100       sage: K = networkx.complete_bipartite_graph(12,7)
    127101       sage: G = Graph(K)
    128102       sage: G.degree()
     
    460434
    461435    INPUT:
    462436   
    463     -  ``data`` -- can be any of the following:
     437    -  ``data`` -- can be any of the following (see the ``format`` argument):
    464438
    465439      #.  A dictionary of dictionaries
    466440
     
    470444
    471445      #.  A Sage adjacency matrix or incidence matrix
    472446
    473       #.  A pygraphviz agraph
     447      #.  A pygraphviz graph
    474448
    475449      #.  A SciPy sparse matrix
    476450
    477       #.  A NetworkX digraph
     451      #.  A NetworkX graph
    478452
    479453    -  ``pos`` -  a positioning dictionary: for example, the
    480454       spring layout from NetworkX for the 5-cycle is::
     
    523497          iterable container of elliptic curves, and the graph produced has
    524498          each curve as a vertex (it's Cremona label) and an edge E-F
    525499          labelled p if and only if E is congruent to F mod p
     500
     501       -  ``NX`` - data must be a NetworkX Graph.
     502           
     503           .. NOTE::
     504
     505               As Sage's default edge labels is ``None`` while NetworkX uses
     506               ``{}``, the ``{}`` labels of a NetworkX graph are automatically
     507               set to ``None`` when it is converted to a Sage graph. This
     508               behaviour can be overruled by setting the keyword
     509               ``convert_empty_dict_labels_to_None`` to ``False`` (it is
     510               ``True`` by default).
    526511   
    527512    -  ``boundary`` - a list of boundary vertices, if
    528513       empty, graph is considered as a 'graph without boundary'