@@ -670,27 +670,27 @@ class at: # pylint: disable=invalid-name
670670 <https://data-apis.org/array-api/latest/API_specification/indexing.html>`_
671671 """
672672
673- x : Array
674- idx : Index
675- __slots__ : ClassVar [tuple [str , str ]] = ("idx " , "x " )
673+ _x : Array
674+ _idx : Index
675+ __slots__ : ClassVar [tuple [str , str ]] = ("_idx " , "_x " )
676676
677677 def __init__ (self , x : Array , idx : Index = _undef , / ) -> None :
678- self .x = x
679- self .idx = idx
678+ self ._x = x
679+ self ._idx = idx
680680
681681 def __getitem__ (self , idx : Index , / ) -> at :
682682 """Allow for the alternate syntax ``at(x)[start:stop:step]``,
683683 which looks prettier than ``at(x, slice(start, stop, step))``
684684 and feels more intuitive coming from the JAX documentation.
685685 """
686- if self .idx is not _undef :
686+ if self ._idx is not _undef :
687687 msg = "Index has already been set"
688688 raise ValueError (msg )
689- self .idx = idx
689+ self ._idx = idx
690690 return self
691691
692692 def _check_args (self , / , copy : bool | None ) -> None :
693- if self .idx is _undef :
693+ if self ._idx is _undef :
694694 msg = (
695695 "Index has not been set.\n "
696696 "Usage: either\n "
@@ -715,10 +715,10 @@ def get(
715715 this allows ensuring that the output is either a copy or a view
716716 """
717717 self ._check_args (copy = copy )
718- x = self .x
718+ x = self ._x
719719
720720 if copy is False :
721- if is_array_api_obj (self .idx ):
721+ if is_array_api_obj (self ._idx ):
722722 # Boolean index. Note that the array API spec
723723 # https://data-apis.org/array-api/latest/API_specification/indexing.html
724724 # does not allow for list, tuple, and tuples of slices plus one or more
@@ -731,7 +731,7 @@ def get(
731731 # Prevent scalar indices together with copy=False.
732732 # Even if some backends may return a scalar view of the original, we chose to be
733733 # strict here beceause some other backends, such as numpy, definitely don't.
734- tup_idx = self .idx if isinstance (self .idx , tuple ) else (self .idx ,)
734+ tup_idx = self ._idx if isinstance (self ._idx , tuple ) else (self ._idx ,)
735735 if any (
736736 i is not None and i is not Ellipsis and not isinstance (i , slice )
737737 for i in tup_idx
@@ -746,15 +746,15 @@ def get(
746746
747747 if is_jax_array (x ):
748748 # Use JAX's at[] or other library that with the same duck-type API
749- return x .at [self .idx ].get ()
749+ return x .at [self ._idx ].get ()
750750
751751 if xp is None :
752752 xp = array_namespace (x )
753- # Note: when self. idx is a boolean mask, numpy always returns a deep copy.
753+ # Note: when idx is a boolean mask, numpy always returns a deep copy.
754754 # However, some backends may legitimately return a view when the mask can
755755 # be downgraded to a slice, e.g. a[[True, True, False]] -> a[:2].
756756 # Err on the side of caution and perform a double-copy in numpy.
757- return xp .asarray (x [self .idx ], copy = copy )
757+ return xp .asarray (x [self ._idx ], copy = copy )
758758
759759 def _update_common (
760760 self ,
@@ -771,7 +771,7 @@ def _update_common(
771771 If the operation can be resolved by at[], (return value, None)
772772 Otherwise, (None, preprocessed x)
773773 """
774- x = self .x
774+ x = self ._x
775775 if copy is None :
776776 writeable = is_writeable_array (x )
777777 copy = not writeable
@@ -783,7 +783,7 @@ def _update_common(
783783 if copy :
784784 if is_jax_array (x ):
785785 # Use JAX's at[] or other library that with the same duck-type API
786- func = getattr (x .at [self .idx ], at_op )
786+ func = getattr (x .at [self ._idx ], at_op )
787787 return func (y ) if y is not _undef else func (), None
788788 # Emulate at[] behaviour for non-JAX arrays
789789 # with a copy followed by an update
@@ -817,7 +817,7 @@ def set(
817817 if res is not None :
818818 return res
819819 assert x is not None
820- x [self .idx ] = y
820+ x [self ._idx ] = y
821821 return x
822822
823823 def _iop (
@@ -845,7 +845,7 @@ def _iop(
845845 if res is not None :
846846 return res
847847 assert x is not None
848- x [self .idx ] = elwise_op (x [self .idx ], y )
848+ x [self ._idx ] = elwise_op (x [self ._idx ], y )
849849 return x
850850
851851 def add (
@@ -907,7 +907,7 @@ def min(
907907 ) -> Array :
908908 """Apply ``x[idx] = minimum(x[idx], y)`` and return the updated array"""
909909 if xp is None :
910- xp = array_namespace (self .x )
910+ xp = array_namespace (self ._x )
911911 y = xp .asarray (y )
912912 return self ._iop ("min" , xp .minimum , y , copy = copy , xp = xp )
913913
@@ -920,6 +920,6 @@ def max(
920920 ) -> Array :
921921 """Apply ``x[idx] = maximum(x[idx], y)`` and return the updated array"""
922922 if xp is None :
923- xp = array_namespace (self .x )
923+ xp = array_namespace (self ._x )
924924 y = xp .asarray (y )
925925 return self ._iop ("max" , xp .maximum , y , copy = copy , xp = xp )
0 commit comments