提交 3ead1a85 authored 作者: Razvan Pascanu's avatar Razvan Pascanu

made the safe_new function to play nice with scalars

We don't want scalars to be converted into TensorScalars ( the pushout optimization will fail if that happens)
上级 b1aabfca
...@@ -43,8 +43,16 @@ def safe_new(x, tag = ''): ...@@ -43,8 +43,16 @@ def safe_new(x, tag = ''):
nw_name = x.name + tag nw_name = x.name + tag
else: else:
nw_name = None nw_name = None
if isinstance(x.type, tensor.Constant): # Should it be theano.Constant? What is the difference between the two?
if isinstance(x, tensor.Constant):
return x.clone() return x.clone()
# Note, as_tensor_variable will convert the Scalar into a
# TensorScalar that will require a ScalarFromTensor op,
# making the pushout optimization fail
elif isinstance(x, scalar.ScalarVariable):
nw_x = x.type()
nw_x.name = nw_name
return nw_x
else: else:
try: try:
x = tensor.as_tensor_variable(x) x = tensor.as_tensor_variable(x)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论