MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / update_kwargs

Function update_kwargs

monai/bundle/scripts.py:74–108  ·  view source on GitHub ↗

Update the `args` dictionary with the input `kwargs`. For dict data, recursively update the content based on the keys. Example:: from monai.bundle import update_kwargs update_kwargs({'exist': 1}, exist=2, new_arg=3) # return {'exist': 2, 'new_arg': 3} Args

(args: str | dict | None = None, ignore_none: bool = True, **kwargs: Any)

Source from the content-addressed store, hash-verified

72
73
74def update_kwargs(args: str | dict | None = None, ignore_none: bool = True, **kwargs: Any) -> dict:
75 """
76 Update the `args` dictionary with the input `kwargs`.
77 For dict data, recursively update the content based on the keys.
78
79 Example::
80
81 from monai.bundle import update_kwargs
82 update_kwargs({'exist': 1}, exist=2, new_arg=3)
83 # return {'exist': 2, 'new_arg': 3}
84
85 Args:
86 args: source `args` dictionary (or a json/yaml filename to read as dictionary) to update.
87 ignore_none: whether to ignore input args with None value, default to `True`.
88 kwargs: key=value pairs to be merged into `args`.
89
90 """
91 args_: dict = args if isinstance(args, dict) else {}
92 if isinstance(args, str):
93 # args are defined in a structured file
94 args_ = ConfigParser.load_config_file(args)
95 if isinstance(args, (tuple, list)) and all(isinstance(x, str) for x in args):
96 primary, overrides = args
97 args_ = update_kwargs(primary, ignore_none, **update_kwargs(overrides, ignore_none, **kwargs))
98 if not isinstance(args_, dict):
99 return args_
100 # recursively update the default args with new args
101 for k, v in kwargs.items():
102 if ignore_none and v is None:
103 continue
104 if isinstance(v, dict) and isinstance(args_.get(k), dict):
105 args_[k] = update_kwargs(args_[k], ignore_none, **v)
106 else:
107 merge_kv(args_, k, v)
108 return args_
109
110
111_update_args = update_kwargs # backward compatibility

Callers 8

test_strMethod · 0.90
downloadFunction · 0.85
verify_metadataFunction · 0.85
verify_net_in_outFunction · 0.85
onnx_exportFunction · 0.85
ckpt_exportFunction · 0.85
trt_exportFunction · 0.85
create_workflowFunction · 0.85

Calls 3

merge_kvFunction · 0.90
load_config_fileMethod · 0.80
getMethod · 0.80

Tested by 1

test_strMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…