@@ -820,35 +820,36 @@ def compress(self, a, axis=None):
820
820
"""Return selected slices only."""
821
821
return at .extra_ops .compress (self , a , axis = axis )
822
822
823
- def set (self , y , ** kwargs ):
824
- """Return a copy of a tensor with the indexed values set to y.
823
+ def set (self , idx , y , ** kwargs ):
824
+ """Return a copy of self with the indexed values set to y.
825
825
826
- Self must be the output of an indexing operation.
827
-
828
- Equivalent to set_subtensor(self, y). See docstrings for kwargs.
826
+ Equivalent to set_subtensor(self[idx], y). See docstrings for kwargs.
829
827
830
828
Examples
831
829
--------
832
-
833
- >>> x = matrix()
834
- >>> out = x[0].set(5)
830
+ >>> import pytensor.tensor as pt
831
+ >>>
832
+ >>> x = pt.ones((3,))
833
+ >>> out = x.set(1, 2)
834
+ >>> out.eval() # array([1., 2., 1.])
835
835
"""
836
- return at .subtensor .set_subtensor (self , y , ** kwargs )
837
-
838
- def add (self , y , ** kwargs ):
839
- """Return a copy of a tensor with the indexed values incremented by y.
836
+ return at .subtensor .set_subtensor (self [idx ], y , ** kwargs )
840
837
841
- Self must be the output of an indexing operation.
838
+ def add (self , idx , y , ** kwargs ):
839
+ """Return a copy of self with the indexed values incremented by y.
842
840
843
- Equivalent to inc_subtensor(self, y). See docstrings for kwargs.
841
+ Equivalent to inc_subtensor(self[idx] , y). See docstrings for kwargs.
844
842
845
843
Examples
846
844
--------
847
845
848
- >>> x = matrix()
849
- >>> out = x[0].add(5)
846
+ >>> import pytensor.tensor as pt
847
+ >>>
848
+ >>> x = pt.ones((3,))
849
+ >>> out = x.add(1, 2)
850
+ >>> out.eval() # array([1., 3., 1.])
850
851
"""
851
- return at .inc_subtensor (self , y , ** kwargs )
852
+ return at .inc_subtensor (self [ idx ] , y , ** kwargs )
852
853
853
854
854
855
class TensorVariable (
0 commit comments