pyRTX.core.parallel_utils
Functions
|
Returns the number of cores for parallel computations. |
|
Returns the unwrapped version of a class method. |
|
Checks if the wrapped object is a method of a class. |
|
A decorator for parallel computations. |
- pyRTX.core.parallel_utils.get_ncores(lst, **kwargs)[source]
Returns the number of cores for parallel computations.
If not specified, the number of cores is set to the number available on your machine minus one.
- Parameters:
lst (
listornumpy.ndarray) – The list of items to be processed in parallel.**kwargs (
dict) – Additional keyword arguments. If ‘n_cores’ is present, it will be used as the number of cores.
- Returns:
The number of cores to use for parallel computation.
- Return type:
- pyRTX.core.parallel_utils.is_method(func, cls_inst)[source]
Checks if the wrapped object is a method of a class.
- pyRTX.core.parallel_utils.get_unwrapped(*args, **kwargs)[source]
Returns the unwrapped version of a class method.
- pyRTX.core.parallel_utils.parallel(func)[source]
A decorator for parallel computations.
The decorated object can be a class method or a regular function. It applies the function to every item of an iterable, performing the computations in parallel. The output will be an iterator which contains the return value of every function call.
The decorated object can accept multiple arguments, but the last positional argument must be an item of the input iterable (e.g., an item of a list, numpy array, or range object).
If the keyword argument ‘n_cores’ is specified, the decorated object will run on n_cores processes. Otherwise, the number of cores is set to the number available on your machine.
- Parameters:
func (
function) – The function to be decorated.- Returns:
The decorated function.
- Return type:
function
Examples
>>> iterable = [2, 5, 6, 7, 3, 4, 1] >>> @parallel ... def target_func(some_input, item): ... return some_input * item >>> results = target_func(10, iterable, n_cores=5)