提交 461b4986 authored 作者: Frederic's avatar Frederic

Re add Elemwise.perform inplace.

It was making too much tests fail, but it still should keep the opt I wanted.
上级 f22b96d4
...@@ -861,6 +861,7 @@ class Elemwise(OpenMPOp): ...@@ -861,6 +861,7 @@ class Elemwise(OpenMPOp):
if nout == 1: if nout == 1:
variables = [variables] variables = [variables]
i = 0
for variable, storage, nout in izip(variables, output_storage, for variable, storage, nout in izip(variables, output_storage,
node.outputs): node.outputs):
if getattr(variable, "dtype", "") == 'object': if getattr(variable, "dtype", "") == 'object':
...@@ -868,15 +869,17 @@ class Elemwise(OpenMPOp): ...@@ -868,15 +869,17 @@ class Elemwise(OpenMPOp):
# always return an ndarray with dtype object # always return an ndarray with dtype object
variable = numpy.asarray(variable, dtype=nout.dtype) variable = numpy.asarray(variable, dtype=nout.dtype)
if i in self.inplace_pattern:
odat = inputs[self.inplace_pattern[i]]
odat[...] = variable
storage[0] = odat
# Sometimes NumPy return a Python type. # Sometimes NumPy return a Python type.
if not isinstance(variable, numpy.ndarray): elif not isinstance(variable, numpy.ndarray):
variable = numpy.asarray(variable, nout.dtype) variable = numpy.asarray(variable, nout.dtype)
storage[0] = variable storage[0] = variable
else:
# the following should be used instead of the previous loop, storage[0] = variable
# unfortunately it tends to segfault i += 1
# self.ufunc(*(ufunc_args+[s[0] for s in output_storage]))
def infer_shape(self, node, i_shapes): def infer_shape(self, node, i_shapes):
rval = [] rval = []
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论