提交 d42c2634 authored 作者: Cesar Laurent's avatar Cesar Laurent

Added kwargs support.

上级 3c90efc9
...@@ -3981,7 +3981,7 @@ def shape_padaxis(t, axis): ...@@ -3981,7 +3981,7 @@ def shape_padaxis(t, axis):
@constructor @constructor
def stack(*tensors): def stack(*tensors, **kwargs):
"""Insert the arguments as slices into a tensor of 1 rank greater. """Insert the arguments as slices into a tensor of 1 rank greater.
The size in dimension 0 of the result will be equal to the number The size in dimension 0 of the result will be equal to the number
...@@ -3998,23 +3998,30 @@ def stack(*tensors): ...@@ -3998,23 +3998,30 @@ def stack(*tensors):
The index of the new axis. The index of the new axis.
""" """
# ---> Remove this when moving to the new interface:
if 'tensors' in kwargs:
tensors = kwargs['tensors']
# <--- until here.
if len(tensors) == 0: if len(tensors) == 0:
raise Exception('theano.tensor.stack(*tensors) must have at least' raise Exception('theano.tensor.stack(*tensors) must have at least'
' one parameter') ' one parameter')
# Remove this when moving to the new interface: stack(tensors, axis=0) # ---> Remove this when moving to the new interface:
# New numpy-like interface:
if isinstance(tensors[0], (list, tuple)): if isinstance(tensors[0], (list, tuple)):
if len(tensors) == 1: if len(tensors) == 1:
axis = 0 if 'axis' in kwargs:
axis = kwargs['axis']
else:
axis = 0
else: else:
axis = tensors[1] axis = tensors[1]
tensors = tensors[0] tensors = tensors[0]
# Deprecated interface:
else: else:
warnings.warn('stack(*tensors) interface is deprecated, use' warnings.warn('stack(*tensors) interface is deprecated, use'
' stack(tensors, axis=0) instead.', stacklevel=3) ' stack(tensors, axis=0) instead.', stacklevel=3)
axis = 0 axis = 0
# <--- Until here.
# If all tensors are scalars of the same type, call make_vector. # If all tensors are scalars of the same type, call make_vector.
# It makes the graph simpler, by not adding DimShuffles and Rebroadcasts # It makes the graph simpler, by not adding DimShuffles and Rebroadcasts
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论