MCPcopy
hub / github.com/hanzhanggit/StackGAN / _merge_a_into_b

Function _merge_a_into_b

misc/config.py:62–92  ·  view source on GitHub ↗

Merge config dictionary a into config dictionary b, clobbering the options in b whenever they are also specified in a.

(a, b)

Source from the content-addressed store, hash-verified

60
61
62def _merge_a_into_b(a, b):
63 """Merge config dictionary a into config dictionary b, clobbering the
64 options in b whenever they are also specified in a.
65 """
66 if type(a) is not edict:
67 return
68
69 for k, v in a.iteritems():
70 # a must specify keys that are in b
71 if not b.has_key(k):
72 raise KeyError('{} is not a valid config key'.format(k))
73
74 # the types must match, too
75 old_type = type(b[k])
76 if old_type is not type(v):
77 if isinstance(b[k], np.ndarray):
78 v = np.array(v, dtype=b[k].dtype)
79 else:
80 raise ValueError(('Type mismatch ({} vs. {}) '
81 'for config key: {}').format(type(b[k]),
82 type(v), k))
83
84 # recursively merge dicts
85 if type(v) is edict:
86 try:
87 _merge_a_into_b(a[k], b[k])
88 except:
89 print('Error under config key: {}'.format(k))
90 raise
91 else:
92 b[k] = v
93
94
95def cfg_from_file(filename):

Callers 1

cfg_from_fileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected