MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / multi_apply

Function multi_apply

detrsmpl/utils/misc.py:6–25  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

4
5
6def 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
28def torch_to_numpy(x):

Callers 9

forward_trainMethod · 0.90
compute_lossesMethod · 0.90
forwardMethod · 0.90
compute_lossesMethod · 0.90
forwardMethod · 0.90
lossMethod · 0.90
get_targetsMethod · 0.90
forward_onnxMethod · 0.90
lossMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected