DeepUpdateDict#
- class sionna.phy.utils.DeepUpdateDict[source]#
Bases:
dictDictionary class inheriting from dict enabling nested merging of the dictionary with a new one.
Methods
- deep_update(delta: dict, stop_at_keys: Tuple = ()) None[source]#
Merges
selfwith the inputdeltain nested fashion.In case of conflict, the values of the new dictionary prevail. The two dictionaries are merged at intermediate keys
stop_at_keys, if provided.- Parameters:
Examples
from sionna.phy.utils import DeepUpdateDict # Merge without conflicts dict1 = DeepUpdateDict( {'a': 1, 'b': {'b1': 10, 'b2': 20}}) dict_delta1 = {'c': -2, 'b': {'b3': 30}} dict1.deep_update(dict_delta1) print(dict1) # {'a': 1, 'b': {'b1': 10, 'b2': 20, 'b3': 30}, 'c': -2} # Compare against the classic "update" method, which is not nested dict1 = DeepUpdateDict( {'a': 1, 'b': {'b1': 10, 'b2': 20}}) dict1.update(dict_delta1) print(dict1) # {'a': 1, 'b': {'b3': 30}, 'c': -2} # Handle key conflicts dict2 = DeepUpdateDict( {'a': 1, 'b': {'b1': 10, 'b2': 20}}) dict_delta2 = {'a': -2, 'b': {'b1': {'f': 3, 'g': 4}}} dict2.deep_update(dict_delta2) print(dict2) # {'a': -2, 'b': {'b1': {'f': 3, 'g': 4}, 'b2': 20}} # Merge at intermediate keys dict2 = DeepUpdateDict( {'a': 1, 'b': {'b1': 10, 'b2': 20}}) dict2.deep_update(dict_delta2, stop_at_keys='b') print(dict2) # {'a': -2, 'b': {'b1': {'f': 3, 'g': 4}}}