提交 72a2ad6a authored 作者: James Bergstra's avatar James Bergstra

modified CAReduce.perform() to prevent BadViewMap

The modification ensures that that even if numpy is clever enough to not make a copy on unit-length reductions, the perform() returns a copy.
上级 ac136c79
...@@ -941,12 +941,16 @@ class CAReduce(Op): ...@@ -941,12 +941,16 @@ class CAReduce(Op):
# If it's a zero-size array, use scalar_op.identity if available # If it's a zero-size array, use scalar_op.identity if available
if variable.shape[dimension] == 0: if variable.shape[dimension] == 0:
if hasattr(self.scalar_op, 'identity'): if hasattr(self.scalar_op, 'identity'):
variable = self.scalar_op.identity variable = numpy.array(self.scalar_op.identity)
break break
else: 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)) 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: else:
variable = self.ufunc.reduce(variable, dimension) variable = self.ufunc.reduce(variable, dimension)
variable = numpy.asarray(variable)
if numpy.may_share_memory(variable, input):
# perhaps numpy is clever for reductions of size 1? We don't want this.
variable = variable.copy()
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论