Skip to content

Commit

Permalink
don't coerce to dense on to_igraph
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgigante committed Oct 15, 2019
1 parent 5209f13 commit 209076a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions graphtools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,12 +730,12 @@ def to_pygsp(self, **kwargs):
def to_igraph(self, attribute="weight", **kwargs):
"""Convert to an igraph Graph
Uses the igraph.Graph.Weighted_Adjacency constructor
Uses the igraph.Graph constructor
Parameters
----------
attribute : str, optional (default: "weight")
kwargs : additional arguments for igraph.Graph.Weighted_Adjacency
kwargs : additional arguments for igraph.Graph
"""
try:
import igraph as ig
Expand All @@ -748,8 +748,13 @@ def to_igraph(self, attribute="weight", **kwargs):
# not a pygsp graph
W = self.K.copy()
W = utils.set_diagonal(W, 0)
return ig.Graph.Weighted_Adjacency(utils.to_array(W).tolist(),
attr=attribute, **kwargs)
sources, targets = W.nonzero()
edgelist = list(zip(sources, targets))
g = ig.Graph(W.shape[0], edgelist, **kwargs)
weights = W[W.nonzero()]
weights = utils.to_array(weights)
g.es[attribute] = weights.flatten().tolist()
return g

def to_pickle(self, path):
"""Save the current Graph to a pickle.
Expand Down
2 changes: 1 addition & 1 deletion graphtools/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.3.0"
__version__ = "1.3.1"

0 comments on commit 209076a

Please sign in to comment.