提交 c1bceb93 authored 作者: Ricardo Vieira's avatar Ricardo Vieira 提交者: Ricardo Vieira

Add more informative message for item assignment error

上级 573e0f78
...@@ -594,6 +594,11 @@ class _tensor_py_operators: ...@@ -594,6 +594,11 @@ class _tensor_py_operators:
), ),
) )
def __setitem__(self, key, value):
raise TypeError(
"TensorVariable does not support item assignment. Use the output of `set` or `add` instead."
)
def take(self, indices, axis=None, mode="raise"): def take(self, indices, axis=None, mode="raise"):
return at.subtensor.take(self, indices, axis, mode) return at.subtensor.take(self, indices, axis, mode)
......
...@@ -447,6 +447,15 @@ class TestTensorInstanceMethods: ...@@ -447,6 +447,15 @@ class TestTensorInstanceMethods:
with pytest.raises(TypeError, match=msg): with pytest.raises(TypeError, match=msg):
x.add(y) x.add(y)
def test_set_item_error(self):
x = matrix("x")
msg = "Use the output of `set` or `add` instead."
with pytest.raises(TypeError, match=msg):
x[0] = 5
with pytest.raises(TypeError, match=msg):
x[0] += 5
def test_deprecated_import(): def test_deprecated_import():
with pytest.warns( with pytest.warns(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论