提交 94349257 authored 作者: Frederic's avatar Frederic 提交者: Olivier Delalleau

small upgrade following code review.

上级 0ab95847
......@@ -1221,12 +1221,13 @@ class _tensor_py_operators:
T = property(lambda self: transpose(self))
shape = property(lambda self: shape(self))
size = property(lambda self: prod(self.shape))
def __len__(self):
# We can't implement __len__ as python request that this
# function return an integer >=0
raise RuntimeError("Theano Variable can't work with len(Theano"
" Variable) due to python restriction. You can use"
" TheanoVariable.shape[0] instead.")
# We can't implement __len__ as Python requests that this
# function returns an integer >=0
raise TypeError("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):
"""Return a reshaped view/copy of this variable.
......
......@@ -5191,13 +5191,12 @@ class test_broadcast(unittest.TestCase):
def test_len():
for shape in [(5,), (3, 4), (7, 4, 6), (3, 4, 5)]:
val = numpy.random.rand(*shape).astype(config.floatX)
for shape in [(5,), (3, 4), (7, 4, 6)]:
x = tensor.tensor(dtype='floatX', broadcastable=(False,)*len(shape))
try:
len(x)
assert False, "Expected an error"
except RuntimeError:
except TypeError:
pass
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论