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

Function _separate_kwargs

dali/python/nvidia/dali/ops/__init__.py:122–162  ·  view source on GitHub ↗

Separates arguments into scalar arguments and argument inputs (data nodes or tensor lists), that were historically specified in __init__ and __call__ of operator class. Returns a pair of dictionaries of kwargs - the first for arguments (__init__), the second for argument inputs (__call_

(kwargs, arg_input_type=_DataNode)

Source from the content-addressed store, hash-verified

120
121
122def _separate_kwargs(kwargs, arg_input_type=_DataNode):
123 """Separates arguments into scalar arguments and argument inputs (data nodes or tensor lists),
124 that were historically specified in __init__ and __call__ of operator class.
125
126 Returns a pair of dictionaries of kwargs - the first for arguments (__init__), the second for
127 argument inputs (__call__).
128
129 Args:
130 kwargs: Keyword arguments.
131 arg_input_type: operator's argument input type, DataNode for pipeline mode, TensorListCPU
132 for eager mode.
133 """
134
135 def is_arg_input_type(x):
136 return isinstance(x, arg_input_type)
137
138 def is_arg_input(name, value):
139 if name == "device":
140 return False
141 if name == "ndim":
142 return False
143 if is_arg_input_type(value):
144 return True
145 if isinstance(value, (str, list, tuple, nvidia.dali.types.ScalarConstant)):
146 return False
147 return not nvidia.dali.types._is_scalar_value(value)
148
149 def to_scalar(scalar):
150 return scalar.value if isinstance(scalar, nvidia.dali.types.ScalarConstant) else scalar
151
152 init_args = {}
153 call_args = {}
154 for name, value in kwargs.items():
155 if value is None:
156 continue
157 if is_arg_input(name, value):
158 call_args[name] = value
159 else:
160 init_args[name] = to_scalar(value)
161
162 return init_args, call_args
163
164
165def _handle_arg_deprecations(schema, kwargs, op_name):

Callers 3

__call__Method · 0.90
__init__Method · 0.85
__call__Method · 0.85

Calls 2

is_arg_inputFunction · 0.85
to_scalarFunction · 0.85

Tested by

no test coverage detected