提交 4219e91d authored 作者: Frederic's avatar Frederic

Don't implement TensorVariable.__len__ to give better error message as this cause other bug.

上级 05aaa81b
...@@ -1222,12 +1222,16 @@ class _tensor_py_operators: ...@@ -1222,12 +1222,16 @@ class _tensor_py_operators:
shape = property(lambda self: shape(self)) shape = property(lambda self: shape(self))
size = property(lambda self: prod(self.shape)) size = property(lambda self: prod(self.shape))
def __len__(self): # We can't implement __len__ to provide a better error message.
# We can't implement __len__ as Python requests that this # Otherwise TensorVariable[:-1] don't work as Python 2.5.1 call
# function returns an integer >=0 # __len__ before calling __getitem__. It also don't catch the raised
raise TypeError("Theano Variables can't work with len(Theano " # Exception!
"Variable) due to Python restriction. You can use " # def __len__(self):
"TheanoVariable.shape[0] instead.") # # We can't implement __len__ as Python requests that this
# # function returns an integer >=0
# raise Exception("Theano Variables can't work with len(Theano "
# "Variable) due to Python restriction. You can use "
# "TheanoVariable.shape[0] instead.")
def reshape(self, shape, ndim=None): def reshape(self, shape, ndim=None):
"""Return a reshaped view/copy of this variable. """Return a reshaped view/copy of this variable.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论