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

Python version of CAReduce now uses scalar_op.identity when reducing a 0-length array.

上级 89575768
...@@ -822,7 +822,14 @@ class CAReduce(Op): ...@@ -822,7 +822,14 @@ class CAReduce(Op):
to_reduce = reversed(sorted(axis)) to_reduce = reversed(sorted(axis))
if to_reduce: if to_reduce:
for dimension in to_reduce: for dimension in to_reduce:
variable = self.ufunc.reduce(variable, dimension) # If it's a zero-size array, use scalar_op.identity if available
if variable.shape[dimension] == 0:
if hasattr(self.scalar_op, 'identity'):
variable = self.scalar_op.identity
else:
raise ValueError("Input (%s) has zero-size on axis %s, but self.scalar_op (%s) has no attribute 'identity'" % (variable, dimension, self.scalar_op))
else:
variable = self.ufunc.reduce(variable, dimension)
output[0] = theano._asarray(variable, dtype = node.outputs[0].type.dtype) output[0] = theano._asarray(variable, dtype = node.outputs[0].type.dtype)
else: else:
output[0] = numpy.copy(variable) output[0] = numpy.copy(variable)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论