提交 e4ee1833 authored 作者: Frederic Bastien's avatar Frederic Bastien

Add cast to the real dtype needed by change to numpy.frompyfunc.

numpy.frompyfunc function now always return an dtype object.
上级 641a03bb
...@@ -727,13 +727,19 @@ class Elemwise(Op): ...@@ -727,13 +727,19 @@ class Elemwise(Op):
raise raise
if nout == 1: if nout == 1:
variables = [variables] variables = [variables]
for variable, storage in zip(variables, output_storage): for variable, storage, nout in zip(variables, output_storage, node.outputs):
if str(getattr(variable, "dtype", "")) == 'object':
# Since numpy 1.6, function created with numpy.frompyfunc
# always return an ndarray with dtype object
variable = numpy.asarray(variable, dtype=nout.dtype)
if hasattr(variable,'shape') and storage[0].shape != variable.shape: if hasattr(variable,'shape') and storage[0].shape != variable.shape:
storage[0].resize(variable.shape) storage[0].resize(variable.shape)
if storage[0].shape: if storage[0].shape:
storage[0][:] = variable storage[0][:] = variable
else: else:
storage[0].itemset(variable) storage[0].itemset(variable)
assert str(storage[0].dtype) != 'object'
# the following should be used instead of the previous loop, unfortunately it tends to segfault # the following should be used instead of the previous loop, unfortunately it tends to segfault
# self.ufunc(*(ufunc_args+[s[0] for s in output_storage])) # self.ufunc(*(ufunc_args+[s[0] for s in output_storage]))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论