提交 e41ee606 authored 作者: James Bergstra's avatar James Bergstra

Merge pull request #75 from delallea/tensor_cast_error

Tensor cast error is clearer and has helpful hint.
...@@ -537,7 +537,8 @@ class Function(object): ...@@ -537,7 +537,8 @@ class Function(object):
if self.name: if self.name:
function_name += 'with name "'+self.name+'" ' function_name += 'with name "'+self.name+'" '
#end if #end if
e.args = tuple(list(e.args)+["Bad input argument to "+function_name+" at index %d" % i]) e.args = tuple(["Bad input argument to " + function_name +
" at index %d" % i] + list(e.args))
raise raise
#end except #end except
#end if #end if
......
...@@ -533,6 +533,13 @@ class TensorType(Type): ...@@ -533,6 +533,13 @@ class TensorType(Type):
This function is not meant to be called in user code. It is for This function is not meant to be called in user code. It is for
`Linker` instances to use when running a compiled graph. `Linker` instances to use when running a compiled graph.
""" """
# Explicit error message when one accidentally uses a Variable as
# input (typical mistake, especially with shared variables).
if isinstance(data, Variable):
raise TypeError(
'Expected an array-like object, but found a Variable: '
'maybe you are trying to call a function on a (possibly '
'shared) variable instead of a numeric array?')
if (type(data) is numpy.ndarray) and (data.dtype is self.numpy_dtype): if (type(data) is numpy.ndarray) and (data.dtype is self.numpy_dtype):
pass # fall through to ndim check pass # fall through to ndim check
elif strict: elif strict:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论