提交 74777739 authored 作者: Razvan Pascanu's avatar Razvan Pascanu

Changed reduce, foldl, foldr to not use the depricated flag return_steps.

上级 ed32a7d8
...@@ -102,31 +102,18 @@ def reduce( fn ...@@ -102,31 +102,18 @@ def reduce( fn
:param name: See ``scan``. :param name: See ``scan``.
""" """
# Makes sure the outputs_info is a list. # Makes sure the outputs_info is a list.
if not isinstance(outputs_info, (list,tuple)): rval = scan.scan( fn = fn
outs_info = [outputs_info]
else:
outs_info = list(outputs_info)
for i,out_info in enumerate(outs_info):
if out_info:
if not isinstance(out_info, dict):
# Specifies that it should return only the last step.
outs_info[i] = dict(
initial = out_info, return_steps = 1)
else:
# Specifies that it should return only the last step.
outs_info[i]['return_steps'] = 1
# NOTE : If the user asks for more then the last step,
# it means he does not understand ``reduce``. We could
# issue a warning in that case
return scan.scan( fn = fn
, sequences = sequences , sequences = sequences
, outputs_info = outs_info , outputs_info = outputs_info
, non_sequences = non_sequences , non_sequences = non_sequences
, go_backwards = go_backwards , go_backwards = go_backwards
, truncate_gradient = -1 , truncate_gradient = -1
, mode = mode , mode = mode
, name = name ) , name = name )
if isinstance(rval[0], (list,tuple)):
return [ x[-1] for x in rval[0]], rval[1]
else:
return rval[0][-1], rval[1]
# The ``foldl`` view of Scan Op. # The ``foldl`` view of Scan Op.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论