From d2488d23bfc72d8c60afd4b9b8ad7cd7f14a34f1 Mon Sep 17 00:00:00 2001 From: Will Dean Date: Tue, 10 Jun 2025 11:26:07 -0400 Subject: [PATCH 1/5] update the links --- doc/library/tensor/basic.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 81d4f6766d9243a0bca318a53873b9b446a4cca7 Mon Sep 17 00:00:00 2001 From: Will Dean Date: Tue, 10 Jun 2025 11:28:15 -0400 Subject: [PATCH 2/5] correc the code blokc --- pytensor/tensor/subtensor.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pytensor/tensor/subtensor.py b/pytensor/tensor/subtensor.py index 99ae67af9b..baf64675c2 100644 --- a/pytensor/tensor/subtensor.py +++ b/pytensor/tensor/subtensor.py @@ -1453,10 +1453,14 @@ 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) """ return inc_subtensor( @@ -1504,16 +1508,18 @@ 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 = ivector("r") new_r = inc_subtensor(r[10:], 5, ignore_duplicates=True) """ From 511956620c05771766167626fac851e06c840a96 Mon Sep 17 00:00:00 2001 From: Will Dean Date: Thu, 12 Jun 2025 14:04:53 -0400 Subject: [PATCH 3/5] add feedback to docstrings --- pytensor/tensor/subtensor.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pytensor/tensor/subtensor.py b/pytensor/tensor/subtensor.py index baf64675c2..7f7085e054 100644 --- a/pytensor/tensor/subtensor.py +++ b/pytensor/tensor/subtensor.py @@ -1462,6 +1462,8 @@ def set_subtensor(x, y, inplace=False, tolerate_inplace_aliasing=False): r = vector("r") new_r = set_subtensor(r[10:], 5) + Consider using :func:`pytensor.tensor.variable.TensorVariable.set` instead. + """ return inc_subtensor( x, @@ -1520,7 +1522,9 @@ def inc_subtensor( .. code-block:: python r = ivector("r") - new_r = inc_subtensor(r[10:], 5, ignore_duplicates=True) + new_r = inc_subtensor(r[[0, 1, 0]], 5, ignore_duplicates=True) + + Consider using :func:`pytensor.tensor.variable.TensorVariable.inc` instead. """ # First of all, y cannot have a higher dimension than x, From 2b9c6e0617d663444c305481402b3de2d2f38da2 Mon Sep 17 00:00:00 2001 From: Will Dean <57733339+williambdean@users.noreply.github.com> Date: Thu, 12 Jun 2025 16:19:25 -0400 Subject: [PATCH 4/5] Update pytensor/tensor/subtensor.py Co-authored-by: Ricardo Vieira <28983449+ricardoV94@users.noreply.github.com> --- pytensor/tensor/subtensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytensor/tensor/subtensor.py b/pytensor/tensor/subtensor.py index 7f7085e054..171fbffb00 100644 --- a/pytensor/tensor/subtensor.py +++ b/pytensor/tensor/subtensor.py @@ -1462,7 +1462,7 @@ def set_subtensor(x, y, inplace=False, tolerate_inplace_aliasing=False): r = vector("r") new_r = set_subtensor(r[10:], 5) - Consider using :func:`pytensor.tensor.variable.TensorVariable.set` instead. + Consider using :meth:`pytensor.tensor.variable.TensorVariable.set` instead. """ return inc_subtensor( From ce350660d0f1ac9d3dd893f2d6c0703e133b5811 Mon Sep 17 00:00:00 2001 From: Will Dean Date: Thu, 12 Jun 2025 16:20:49 -0400 Subject: [PATCH 5/5] change func to meth --- pytensor/tensor/subtensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytensor/tensor/subtensor.py b/pytensor/tensor/subtensor.py index 171fbffb00..6c881a0312 100644 --- a/pytensor/tensor/subtensor.py +++ b/pytensor/tensor/subtensor.py @@ -1524,7 +1524,7 @@ def inc_subtensor( r = ivector("r") new_r = inc_subtensor(r[[0, 1, 0]], 5, ignore_duplicates=True) - Consider using :func:`pytensor.tensor.variable.TensorVariable.inc` instead. + Consider using :meth:`pytensor.tensor.variable.TensorVariable.inc` instead. """ # First of all, y cannot have a higher dimension than x,