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

allow numpy.ndarray to be accepted as theano.scalar constant when they have 0 dimension

上级 30856f64
...@@ -35,6 +35,10 @@ def as_scalar(x, name = None): ...@@ -35,6 +35,10 @@ def as_scalar(x, name = None):
raise TypeError("Cannot convert %s to Scalar" % x, type(x)) raise TypeError("Cannot convert %s to Scalar" % x, type(x))
def constant(x): def constant(x):
# pass through numpy scalars, since they are already typed on purpose typically.
if hasattr(x,'dtype'):
assert x.ndim==0
return ScalarConstant(Scalar(str(x.dtype)), x)
if isinstance(x, builtin_float): if isinstance(x, builtin_float):
for dtype in ['float32', 'float64']: for dtype in ['float32', 'float64']:
x_ = theano._asarray(x, dtype=dtype) x_ = theano._asarray(x, dtype=dtype)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论