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

Function _build_input_sets

dali/python/nvidia/dali/ops/_operator_utils.py:48–131  ·  view source on GitHub ↗

Detect if the list of positional inputs [Inp_0, Inp_1, Inp_2, ...], represents Multiple Input Sets (MIS) to operator and prepare lists of regular DataNode-only positional inputs to individual operator instances. If all Inp_i are DataNodes there are no MIS involved. If any of Inp_i i

(inputs, op_name)

Source from the content-addressed store, hash-verified

46
47
48def _build_input_sets(inputs, op_name):
49 """Detect if the list of positional inputs [Inp_0, Inp_1, Inp_2, ...], represents Multiple
50 Input Sets (MIS) to operator and prepare lists of regular DataNode-only positional inputs to
51 individual operator instances.
52
53 If all Inp_i are DataNodes there are no MIS involved.
54 If any of Inp_i is a list of DataNodes, this is considered a MIS. In that case, non-list
55 Inp_i is repeated to match the length of the one that is a list, and those lists are regrouped,
56 for example:
57
58 inputs = [a, b, [x, y, z], [u, v, w]]
59
60 # "a" and "b" are repeated to match the length of [x, y, z]:
61 -> [[a, a, a], [b, b, b], [x, y, z], [u, v, w]]
62
63 # input sets are rearranged, so they form a regular tuples of DataNodes suitable to being passed
64 # to one Operator Instance.
65 -> [(a, b, x, u), (a, b, y, v), (a, b, z, w)]
66
67 This allows to create 3 operator instances, each with 4 positional inputs.
68
69 Parameters
70 ----------
71 inputs : List of positional inputs
72 The inputs are either DataNodes or lists of DataNodes indicating MIS.
73 op_name : str
74 Name of the invoked operator, for error reporting purposes.
75 """
76
77 def _detect_multiple_input_sets(inputs):
78 """Check if any of inputs is a list, indicating a usage of MIS."""
79 return any(isinstance(input, list) for input in inputs)
80
81 def _safe_len(input):
82 if isinstance(input, list):
83 return len(input)
84 else:
85 return 1
86
87 def _check_common_length(inputs):
88 """Check if all list representing multiple input sets have the same length and return it"""
89 arg_list_len = max(_safe_len(input) for input in inputs)
90 for input in inputs:
91 if isinstance(input, list):
92 if len(input) != arg_list_len:
93 raise ValueError(
94 f"All argument lists for Multiple Input Sets used "
95 f"with operator `{op_name}` must have "
96 f"the same length"
97 )
98 return arg_list_len
99
100 def _unify_lists(inputs, arg_list_len):
101 """Pack single _DataNodes into lists, so they are treated as Multiple Input Sets
102 consistently with the ones already present
103
104 Parameters
105 ----------

Callers 2

_prep_input_setsMethod · 0.90
__call__Method · 0.90

Calls 4

_check_common_lengthFunction · 0.85
_unify_listsFunction · 0.85
_repack_input_setsFunction · 0.85

Tested by

no test coverage detected