Skip to content

Fixes an error when nodes were removed from the networkx graph#12

Open
jernsting wants to merge 1 commit into
fanchangjun:masterfrom
jernsting:master
Open

Fixes an error when nodes were removed from the networkx graph#12
jernsting wants to merge 1 commit into
fanchangjun:masterfrom
jernsting:master

Conversation

@jernsting

Copy link
Copy Markdown

If you create a networkx graph from an edge list where a component is disconnected, FINDER will fail and raise a std::bad_alloc.

This happened because the GenNetwork function created an array of length g.nodes(), but indexed it with the original names of the node.

Example:

>>> test = np.array([0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1], [1, 1, 1, 0]])
>>> g = nx.from_numpy_array(test)
>>> g.remove_node(2)
>>> 
>>> # some more detail:
>>> a, b = zip(*g.edges())
>>> a
(0, 1)
>>> b    # <<< Here is the error!
(3, 3)
>>> len(g.nodes())
3

The resulting graph can not be processed with finder.

This patch resolves this and makes handling of such graphs possible.

@jernsting

Copy link
Copy Markdown
Author

fixes #13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant