|
21 | 21 | logger = logging.getLogger("nipype.workflow")
|
22 | 22 |
|
23 | 23 |
|
| 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(to_scipy_sparse_array(graph, nodelist=nodelist, format="lil")) |
| 34 | + |
| 35 | + |
24 | 36 | class PluginBase(object):
|
25 | 37 | """Base class for plugins."""
|
26 | 38 |
|
@@ -431,12 +443,8 @@ def _task_finished_cb(self, jobid, cached=False):
|
431 | 443 |
|
432 | 444 | def _generate_dependency_list(self, graph):
|
433 | 445 | """Generates a dependency list for a list of graphs."""
|
434 |
| - import networkx as nx |
435 |
| - |
436 | 446 | self.procs, _ = topological_sort(graph)
|
437 |
| - self.depidx = nx.to_scipy_sparse_matrix( |
438 |
| - graph, nodelist=self.procs, format="lil" |
439 |
| - ) |
| 447 | + self.depidx = _graph_to_lil_matrix(graph, nodelist=self.procs) |
440 | 448 | self.refidx = self.depidx.astype(int)
|
441 | 449 | self.proc_done = np.zeros(len(self.procs), dtype=bool)
|
442 | 450 | self.proc_pending = np.zeros(len(self.procs), dtype=bool)
|
|
0 commit comments