提交 07f12948 authored 作者: Razvan Pascanu's avatar Razvan Pascanu

better naming convention

上级 b86abee4
...@@ -183,20 +183,19 @@ def canonical_arguments(sequences, ...@@ -183,20 +183,19 @@ def canonical_arguments(sequences,
and that the different fields of of a dictionary are set to default and that the different fields of of a dictionary are set to default
value if the user has not provided any. value if the user has not provided any.
""" """
us = to_list(sequences) states_info = to_list(outputs_info)
xys_info = to_list(outputs_info) parameters = [tensor.as_tensor_variable(x) for x in to_list(non_sequences)]
ws = [tensor.as_tensor_variable(x) for x in to_list(non_sequences)]
us = [] inputs = []
for u in to_list(sequences): for input in to_list(sequences):
if not isinstance(u, dict): if not isinstance(u, dict):
us.append(u) inputs.append(input)
elif u.get('taps', True) is None: elif input.get('taps', True) is None:
us.append(u) inputs.append(input)
elif u.get('taps', None): elif input.get('taps', None):
mintap = numpy.min(u['taps']) mintap = numpy.min(input['taps'])
maxtap = numpy.max(u['taps']) maxtap = numpy.max(input['taps'])
for k in u['taps']: for k in input['taps']:
# We cut the sequence such that seq[i] to correspond to # We cut the sequence such that seq[i] to correspond to
# seq[i-k] # seq[i-k]
if maxtap < 0: if maxtap < 0:
...@@ -204,57 +203,57 @@ def canonical_arguments(sequences, ...@@ -204,57 +203,57 @@ def canonical_arguments(sequences,
else: else:
offset = 0 offset = 0
if maxtap == mintap and maxtap != 0: if maxtap == mintap and maxtap != 0:
nw_u = u['input'][:abs(maxtap)] nw_input = input['input'][:abs(maxtap)]
elif maxtap - k != 0: elif maxtap - k != 0:
nw_u = u['input'][offset + k - mintap: -(maxtap - k)] nw_input = input['input'][offset + k - mintap: -(maxtap - k)]
else: else:
nw_u = u['input'][offset + k - mintap:] nw_input = input['input'][offset + k - mintap:]
if go_backwards: if go_backwards:
nw_u = nw_u[::-1] nw_input = nw_input[::-1]
us.append(nw_u) inputs.append(nw_input)
else: else:
raise ValueError('Provided sequence makes no sense', str(u)) raise ValueError('Provided sequence makes no sense', str(input))
# Since we've added all sequences now we need to level them up based on # Since we've added all sequences now we need to level them up based on
# n_steps or their different shapes # n_steps or their different shapes
if n_steps is None: if n_steps is None:
if len(us) == 0: if len(inputs) == 0:
# No information about the number of steps # No information about the number of steps
raise ValueError('You need to provide either at least ' raise ValueError('You need to provide either at least '
'one sequence over which scan should loop ' 'one sequence over which scan should loop '
'or a number of steps for scan to loop. ' 'or a number of steps for scan to loop. '
'Neither of the two had been provided !') 'Neither of the two had been provided !')
T = us[0].shape[0] T = inputs[0].shape[0]
for u in us[1:]: for input in inputs[1:]:
T = tensor.minimum(T, u.shape[0]) T = tensor.minimum(T, input.shape[0])
else: else:
T = tensor.as_tensor(n_steps) T = tensor.as_tensor(n_steps)
# Level up sequences # Level up sequences
us = [u[:T] for u in us] inputs = [input[:T] for input in inputs]
# wrap outputs info in a dictionary if they are not already in one # wrap outputs info in a dictionary if they are not already in one
for i, xy in enumerate(xys_info): for i, state in enumerate(states_info):
if xy is not None and not isinstance(xy, dict): if state is not None and not isinstance(state, dict):
xys_info[i] = dict(initial=xy, taps=[-1]) states_info[i] = dict(initial=state, taps=[-1])
elif isinstance(xy, dict): elif isinstance(state, dict):
if not xy.get('initial', None) and xy.get('taps', None): if not state.get('initial', None) and state.get('taps', None):
raise ValueError(('If you are using slices of an output ' raise ValueError(('If you are using slices of an output '
'you need to provide a initial state ' 'you need to provide a initial state '
'for it'), xy) 'for it'), state)
elif xy.get('initial', None) and not xy.get('taps', None): elif state.get('initial', None) and not state.get('taps', None):
# ^ initial state but taps not provided # ^ initial state but taps not provided
if 'taps' in xy: if 'taps' in state:
# ^ explicitly provided a None for taps # ^ explicitly provided a None for taps
_logger.warning('Output %s ( index %d) has a initial ' _logger.warning('Output %s ( index %d) has a initial '
'state but taps is explicitly set to None ', 'state but taps is explicitly set to None ',
getattr(outs_info[i]['initial'], 'name', 'None'), getattr(states_info[i]['initial'], 'name', 'None'),
i) i)
xys_info[i]['taps'] = [-1] states_info[i]['taps'] = [-1]
else: else:
# if a None is provided as the output info we replace it # if a None is provided as the output info we replace it
# with an empty dict() to simplify handling # with an empty dict() to simplify handling
xys_info[i] = dict() states_info[i] = dict()
return seqs, outs_info, non_seqs, actual_n_steps return inputs, staess_info, parameters, T
def infer_shape(outs, inputs, input_shapes): def infer_shape(outs, inputs, input_shapes):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论