提交 fd28e0a0 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Use make_vector instead of join(unbroadcast(dimshuffle(...))) when stacking scalars

上级 129f1d57
......@@ -2796,6 +2796,13 @@ def stack(*tensors):
"""Insert the arguments as slices into a tensor of 1 rank greater.
EXAMPLE
"""
# If all tensors are scalars of the same type, call make_vector.
# It makes the graph simpler, by not adding DimShuffles and Rebroadcasts
if numpy.all([isinstance(t, Variable) and\
isinstance(t.type, TensorType) and\
t.ndim==0 and t.type==tensors[0].type\
for t in tensors]):
return theano.tensor.opt.make_vector(*tensors)
return join(0, *[shape_padleft(t, 1) for t in tensors])
@constructor
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论