Skip to content

Commit 8977011

Browse files
committed
FIX: Coerce depidx to lil_matrix
1 parent a31870d commit 8977011

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

nipype/pipeline/plugins/base.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121
logger = logging.getLogger("nipype.workflow")
2222

2323

24+
def _graph_to_lil_matrix(graph, nodelist):
25+
"""Provide a sparse linked list matrix across various NetworkX versions"""
26+
import scipy.sparse as ssp
27+
28+
try:
29+
from networkx import to_scipy_sparse_array
30+
except ImportError: # NetworkX < 2.7
31+
from networkx import to_scipy_sparse_matrix as to_scipy_sparse_array
32+
33+
return ssp.lil_matrix(
34+
to_scipy_sparse_array(graph, nodelist=nodelist, format="lil")
35+
)
36+
37+
2438
class PluginBase(object):
2539
"""Base class for plugins."""
2640

@@ -431,12 +445,8 @@ def _task_finished_cb(self, jobid, cached=False):
431445

432446
def _generate_dependency_list(self, graph):
433447
"""Generates a dependency list for a list of graphs."""
434-
import networkx as nx
435-
436448
self.procs, _ = topological_sort(graph)
437-
self.depidx = nx.to_scipy_sparse_matrix(
438-
graph, nodelist=self.procs, format="lil"
439-
)
449+
self.depidx = _graph_to_lil_matrix(graph, nodelist=self.procs)
440450
self.refidx = self.depidx.astype(int)
441451
self.proc_done = np.zeros(len(self.procs), dtype=bool)
442452
self.proc_pending = np.zeros(len(self.procs), dtype=bool)

0 commit comments

Comments
 (0)