Apply function to a list of arguments. Note: This function applies the ``func`` to multiple inputs and map the multiple outputs of the ``func`` into different list. Each list contains the same type of outputs corresponding to different inputs. Args:
(func, *args, **kwargs)
| 4 | |
| 5 | |
| 6 | def multi_apply(func, *args, **kwargs): |
| 7 | """Apply function to a list of arguments. |
| 8 | |
| 9 | Note: |
| 10 | This function applies the ``func`` to multiple inputs and |
| 11 | map the multiple outputs of the ``func`` into different |
| 12 | list. Each list contains the same type of outputs corresponding |
| 13 | to different inputs. |
| 14 | |
| 15 | Args: |
| 16 | func (Function): A function that will be applied to a list of |
| 17 | arguments |
| 18 | |
| 19 | Returns: |
| 20 | tuple(list): A tuple containing multiple list, each list contains \ |
| 21 | a kind of returned results by the function |
| 22 | """ |
| 23 | pfunc = partial(func, **kwargs) if kwargs else func |
| 24 | map_results = map(pfunc, *args) |
| 25 | return tuple(map(list, zip(*map_results))) |
| 26 | |
| 27 | |
| 28 | def torch_to_numpy(x): |
no outgoing calls
no test coverage detected