MCPcopy Create free account
hub / github.com/NVIDIA/DALI / python_function

Function python_function

dali/test/python/test_utils.py:867–890  ·  view source on GitHub ↗

Convenience wrapper around fn.python_function. If you need to pass to the fn.python_function mix of datanodes and parameters that are not produced by the pipeline, you probably need to proceed along the lines of: `dali.fn.python_function(data_node, function=lambda data:my_fun(data,

(*inputs, function, **kwargs)

Source from the content-addressed store, hash-verified

865
866
867def python_function(*inputs, function, **kwargs):
868 """
869 Convenience wrapper around fn.python_function.
870 If you need to pass to the fn.python_function mix of datanodes and parameters
871 that are not produced by the pipeline, you probably need to proceed along the lines of:
872 `dali.fn.python_function(data_node, function=lambda data:my_fun(data, non_pipeline_data))`.
873 This utility separates the data nodes from non data nodes automatically,
874 so that you can simply call `python_function(data_node, non_pipeline_data, function=my_fun)`.
875 """
876 node_inputs = [inp for inp in inputs if isinstance(inp, dali.data_node.DataNode)]
877 const_inputs = [inp for inp in inputs if not isinstance(inp, dali.data_node.DataNode)]
878
879 def is_data_node(input):
880 return isinstance(input, dali.data_node.DataNode)
881
882 def wrapper(*exec_inputs):
883 iter_exec_inputs = (inp for inp in exec_inputs)
884 iter_const_inputs = (inp for inp in const_inputs)
885 iteration_inputs = [
886 next(iter_exec_inputs if is_data_node(inp) else iter_const_inputs) for inp in inputs
887 ]
888 return function(*iteration_inputs)
889
890 return dali.fn.python_function(*node_inputs, function=wrapper, **kwargs)
891
892
893def has_operator(operator):

Callers 2

bricon_ref_pipeFunction · 0.90
RunImplMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected