diff options
author | aric <none@none> | 2007-02-15 20:58:36 +0000 |
---|---|---|
committer | aric <none@none> | 2007-02-15 20:58:36 +0000 |
commit | 6aab9b313aa1d8ab56bcf18fa3d25b554443d283 (patch) | |
tree | 6ba89fa8456e5cb39e4409cb378e70ff5634ba68 /networkx/convert.py | |
parent | cd72ffcc89b3c8637edf9f01e7b6a7c2fb3bd566 (diff) | |
download | networkx-6aab9b313aa1d8ab56bcf18fa3d25b554443d283.tar.gz |
Further changes to convert.py to address multiedges case.
Cleanup of documentation and comments.
Mark _prep_create_using as private.
Closes #87.
--HG--
extra : convert_revision : svn%3A3ed01bd8-26fb-0310-9e4c-ca1a4053419f/networkx/trunk%40528
Diffstat (limited to 'networkx/convert.py')
-rw-r--r-- | networkx/convert.py | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/networkx/convert.py b/networkx/convert.py index 7edd2aef..fa2c7dd3 100644 --- a/networkx/convert.py +++ b/networkx/convert.py @@ -8,8 +8,7 @@ Create a 10 node random digraph >>> from networkx import * >>> import numpy >>> a=numpy.reshape(numpy.random.random_integers(0,1,size=100),(10,10)) ->>> D=from_whatever(D,create_using=DiGraph()) # or D=DiGraph(a) - +>>> D=from_whatever(a,create_using=DiGraph()) # or D=DiGraph(a) For graphviz formats see networkx.drawing.nx_pygraphviz or networkx.drawing.nx_pydot. @@ -26,7 +25,7 @@ __author__ = """Aric Hagberg (hagberg@lanl.gov)""" import networkx -def prep_create_using(create_using): +def _prep_create_using(create_using): """ Returns a graph object ready to be populated. @@ -139,7 +138,7 @@ def from_dict_of_lists(d,create_using=None): """Return a NetworkX graph G from a Python dict of lists. """ - G=prep_create_using(create_using) + G=_prep_create_using(create_using) for node in d: for nbr in d[node]: @@ -183,17 +182,21 @@ def from_dict_of_dicts(d,create_using=None): should be a list, though this routine does not check for that. """ - G=prep_create_using(create_using) + G=_prep_create_using(create_using) G.add_nodes_from(d) # is this a XGraph or XDiGraph? - # FIXME This is a bad way to check for whether edge data exists... - # If someone ever creates WeightedGraph without multiedges, it won't work. - if hasattr(G,'allow_multiedges'): + # FIXME + # This is a bad way to check for whether edge data exists... + # If someone ever creates a graph class with edge data and + # without an allow_multiedges method, it won't work. + if hasattr(G,'allow_multiedges'): # assume edge data if G.multiedges: + # this is a NetworkX graph with multiedges=True + # make a copy of the list of edge data (but not the edge data) for u in d: for v in d[u]: - G.adj[u][v]=d[u][v][:] # make a copy of the list of edge_data + G.adj[u][v]=d[u][v][:] # copy of the edge_data list else: for u in d: for v in d[u]: @@ -268,7 +271,7 @@ def from_numpy_matrix(A,create_using=None): raise ImportError, \ "Import Error: not able to import numpy: http://numpy.scipy.org " - G=prep_create_using(create_using) + G=_prep_create_using(create_using) nx,ny=A.shape @@ -281,8 +284,10 @@ def from_numpy_matrix(A,create_using=None): # get a list of edges x,y=numpy.asarray(A).nonzero() # is this a XGraph or XDiGraph? - # FIXME This is a bad way to check for whether edge data exists... - # If someone ever creates WeightedGraph without multiedges, it won't work. + # FIXME + # This is a bad way to check for whether edge data exists... + # If someone ever creates a graph class with edge data and + # without an allow_multiedges method, it won't work. if hasattr(G,'allow_multiedges'): for (u,v) in zip(x,y): G.add_edge(u,v,A[u,v]) @@ -355,17 +360,19 @@ def from_scipy_sparse_matrix(A,create_using=None): >>> G=from_scipy_sparse_matrix(A) """ - G=prep_create_using(create_using) + G=_prep_create_using(create_using) # is this a XGraph or XDiGraph? - # FIXME This is a bad way to check for whether edge data exists... - # If someone ever creates WeightedGraph without multiedges, it won't work. + # FIXME + # This is a bad way to check for whether edge data exists... + # If someone ever creates a graph class with edge data and + # without an allow_multiedges method, it won't work. if hasattr(G,'allow_multiedges'): xgraph=True else: xgraph=False - # convert everythin to coo - not the most efficient + # convert everything to coo - not the most efficient AA=A.tocoo() nx,ny=AA.shape |