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

small upgrade following code review.

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