提交 ed20a5cb authored 作者: sebastien-j's avatar sebastien-j 提交者: Frederic

Partial Revert 5ed8d923

上级 7d6e0394
...@@ -55,9 +55,24 @@ def safe_new(x, tag='', dtype=None): ...@@ -55,9 +55,24 @@ def safe_new(x, tag='', dtype=None):
return nwx return nwx
else: else:
return x.clone() return x.clone()
# Note, as_tensor_variable will convert the Scalar into a
# at this point we should only have Variables # TensorScalar that will require a ScalarFromTensor op,
assert isinstance(x, theano.Variable) # making the pushout optimization fail
elif isinstance(x, scalar.ScalarVariable):
if dtype:
nw_x = scalar.get_scalar_type(dtype=dtype)()
else:
nw_x = x.type()
nw_x.name = nw_name
return nw_x
else:
try:
x = tensor.as_tensor_variable(x)
except TypeError:
# This could happen for example for random states, and I really
# want to avoid the convoluted logic that checks for cuda
# ndarrays
pass
nw_x = x.type() nw_x = x.type()
if dtype and nw_x.dtype != dtype: if dtype and nw_x.dtype != dtype:
nw_x = nw_x.astype(dtype).type() nw_x = nw_x.astype(dtype).type()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论