Module Contents


parfor(func, in_list, out_shape=None, n_jobs=-1, engine='joblib', backend='threading', func_args=[], func_kwargs={}, **kwargs)

Parallel for loop for numpy arrays

AFQ.utils.parallel.parfor(func, in_list, out_shape=None, n_jobs=- 1, engine='joblib', backend='threading', func_args=[], func_kwargs={}, **kwargs)[source]

Parallel for loop for numpy arrays


The function to apply to each item in the array. Must have the form: func(arr, idx, *args, *kwargs) where arr is an ndarray and idx is an index into that array (a tuple). The Return of func needs to be one item (e.g. float, int) per input item.


All legitimate inputs to the function to operate over.

n_jobsinteger, optional

The number of jobs to perform in parallel. -1 to use all cpus. Default: 1


{“dask”, “joblib”, “serial”} The last one is useful for debugging – runs the code without any parallelization.


What joblib or dask backend to use. Irrelevant for other engines.

func_argslist, optional

Positional arguments to func.

func_kwargslist, optional

Keyword arguments to func.

kwargsdict, optional

Additional arguments to pass to either joblib.Parallel or dask.compute depending on the engine used. Default: {}

ndarray of identical shape to arr