diff --git a/doc/library/tensor/basic.rst b/doc/library/tensor/basic.rst index 4d3a5736a7..fe9750bd2c 100644 --- a/doc/library/tensor/basic.rst +++ b/doc/library/tensor/basic.rst @@ -1144,9 +1144,9 @@ Indexing Like NumPy, PyTensor distinguishes between *basic* and *advanced* indexing. PyTensor fully supports basic indexing -(see `NumPy's indexing `_) +(see `NumPy's indexing `_) and `integer advanced indexing -`_. +`_. Index-assignment is *not* supported. If you want to do something like ``a[5] = b`` or ``a[5]+=b``, see :func:`pytensor.tensor.subtensor.set_subtensor` and diff --git a/pytensor/tensor/subtensor.py b/pytensor/tensor/subtensor.py index 99ae67af9b..6c881a0312 100644 --- a/pytensor/tensor/subtensor.py +++ b/pytensor/tensor/subtensor.py @@ -1453,10 +1453,16 @@ def set_subtensor(x, y, inplace=False, tolerate_inplace_aliasing=False): Examples -------- - To replicate the numpy expression "r[10:] = 5", type - >>> from pytensor.tensor import vector - >>> r = vector("r") - >>> new_r = set_subtensor(r[10:], 5) + To replicate the numpy expression ``r[10:] = 5``, type + + .. code-block:: python + + from pytensor.tensor import set_subtensor, vector + + r = vector("r") + new_r = set_subtensor(r[10:], 5) + + Consider using :meth:`pytensor.tensor.variable.TensorVariable.set` instead. """ return inc_subtensor( @@ -1504,17 +1510,21 @@ def inc_subtensor( -------- To replicate the expression ``r[10:] += 5``: - ..code-block:: python + .. code-block:: python + + from pytensor.tensor import ivector, inc_subtensor - r = ivector() + r = ivector("r") new_r = inc_subtensor(r[10:], 5) To replicate the expression ``r[[0, 1, 0]] += 5``: - ..code-block:: python + .. code-block:: python + + r = ivector("r") + new_r = inc_subtensor(r[[0, 1, 0]], 5, ignore_duplicates=True) - r = ivector() - new_r = inc_subtensor(r[10:], 5, ignore_duplicates=True) + Consider using :meth:`pytensor.tensor.variable.TensorVariable.inc` instead. """ # First of all, y cannot have a higher dimension than x,