|
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( |
| 34 | + to_scipy_sparse_array(graph, nodelist=nodelist, format="lil") |
| 35 | + ) |
| 36 | + |
| 37 | + |
24 | 38 | class PluginBase(object):
|
25 | 39 | """Base class for plugins."""
|
26 | 40 |
|
@@ -431,12 +445,8 @@ def _task_finished_cb(self, jobid, cached=False):
|
431 | 445 |
|
432 | 446 | def _generate_dependency_list(self, graph):
|
433 | 447 | """Generates a dependency list for a list of graphs."""
|
434 |
| - import networkx as nx |
435 |
| - |
436 | 448 | 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) |
440 | 450 | self.refidx = self.depidx.astype(int)
|
441 | 451 | self.proc_done = np.zeros(len(self.procs), dtype=bool)
|
442 | 452 | self.proc_pending = np.zeros(len(self.procs), dtype=bool)
|
|
0 commit comments