Skip to content

Commit d05fae0

Browse files
committed
wip: run in process pool executor
1 parent 754785f commit d05fae0

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

nitransforms/resampling.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
99
"""Resampling utilities."""
1010

11+
from concurrent.futures import ProcessPoolExecutor
1112
from functools import partial
1213
from pathlib import Path
1314
import numpy as np
@@ -159,15 +160,12 @@ def _apply_volume(index, data, transform, targets=None):
159160
)
160161
return map_coordinates(data_t, targets)
161162

162-
# Order F ensures individual volumes are contiguous in memory
163-
# Also matches NIfTI, making final save more efficient
164-
resampled = np.zeros(
165-
(len(ref_ndcoords), len(transform)), dtype=input_dtype, order="F"
166-
)
167-
for t in range(n_resamplings):
168-
# Interpolate
169-
resampled[..., t] = _apply_volume(t, data, transform, targets=targets)
170-
163+
with ProcessPoolExecutor(max_workers=njobs) as executor:
164+
results = executor.map(
165+
_apply_volume,
166+
[(t, data, transform, targets) for t in range(n_resamplings)],
167+
)
168+
resampled = np.stack(list(results), -1)
171169
else:
172170
data = np.asanyarray(spatialimage.dataobj, dtype=input_dtype)
173171

0 commit comments

Comments
 (0)