Skip to content

Correct indexing links in docs #1463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/library/tensor/basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1144,9 +1144,9 @@ Indexing

Like NumPy, PyTensor distinguishes between *basic* and *advanced* indexing.
PyTensor fully supports basic indexing
(see `NumPy's indexing <http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html>`_)
(see `NumPy's indexing <https://numpy.org/doc/stable/user/basics.indexing.html>`_)
and `integer advanced indexing
<http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#integer>`_.
<https://numpy.org/doc/stable/user/basics.indexing.html#integer-array-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
Expand Down
28 changes: 19 additions & 9 deletions pytensor/tensor/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down