in models/src/wavenet_vocoder/tfcompat/hparam.py [0:0]
def _process_scalar_value(name, parse_fn, var_type, m_dict, values, results_dictionary):
"""Update results_dictionary with a scalar value.
Used to update the results_dictionary to be returned by parse_values when
encountering a clause with a scalar RHS (e.g. "s=5" or "arr[0]=5".)
Mutates results_dictionary.
Args:
name: Name of variable in assignment ("s" or "arr").
parse_fn: Function for parsing the actual value.
var_type: Type of named variable.
m_dict: Dictionary constructed from regex parsing.
m_dict['val']: RHS value (scalar)
m_dict['index']: List index value (or None)
values: Full expression being parsed
results_dictionary: The dictionary being updated for return by the parsing
function.
Raises:
ValueError: If the name has already been used.
"""
try:
parsed_value = parse_fn(m_dict["val"])
except ValueError:
_parse_fail(name, var_type, m_dict["val"], values)
# If no index is provided
if not m_dict["index"]:
if name in results_dictionary:
_reuse_fail(name, values)
results_dictionary[name] = parsed_value
else:
if name in results_dictionary:
# The name has already been used as a scalar, then it
# will be in this dictionary and map to a non-dictionary.
if not isinstance(results_dictionary.get(name), dict):
_reuse_fail(name, values)
else:
results_dictionary[name] = {}
index = int(m_dict["index"])
# Make sure the index position hasn't already been assigned a value.
if index in results_dictionary[name]:
_reuse_fail("{}[{}]".format(name, index), values)
results_dictionary[name][index] = parsed_value