提交 cec00641 authored 作者: James Bergstra's avatar James Bergstra

Merge

...@@ -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)
......
...@@ -764,10 +764,12 @@ def local_subtensor_make_vector(node): ...@@ -764,10 +764,12 @@ def local_subtensor_make_vector(node):
@gof.local_optimizer([T.Elemwise]) @gof.local_optimizer([T.Elemwise])
def local_useless_elemwise(node): def local_useless_elemwise(node):
""" """
eq(x,x) -> 1
neq(x,x) -> 0 eq(x,x) -> 1
mul(x) -> x neq(x,x) -> 0
add(x) -> x mul(x) -> x
add(x) -> x
identity(x) -> x
""" """
if isinstance(node.op, T.Elemwise): if isinstance(node.op, T.Elemwise):
...@@ -783,6 +785,8 @@ add(x) -> x ...@@ -783,6 +785,8 @@ add(x) -> x
return [node.inputs[0]] return [node.inputs[0]]
if node.op.scalar_op == theano.scalar.add and len(node.inputs)==1: if node.op.scalar_op == theano.scalar.add and len(node.inputs)==1:
return [node.inputs[0]] return [node.inputs[0]]
if node.op.scalar_op == theano.scalar.identity and len(node.inputs)==1:
return [node.inputs[0]]
@register_specialize @register_specialize
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论