@@ -76,9 +76,10 @@ class at: # pylint: disable=invalid-name # numpydoc ignore=PR02
7676
7777 You may use two alternate syntaxes::
7878
79- >>> import array_api_extra as xpx
80- >>> xpx.at(x, idx).set(value) # or add(value), etc.
81- >>> xpx.at(x)[idx].set(value)
79+ import array_api_extra as xpx
80+
81+ xpx.at(x, idx).set(value) # or add(value), etc.
82+ xpx.at(x)[idx].set(value)
8283
8384 copy : bool, optional
8485 None (default)
@@ -103,8 +104,9 @@ class at: # pylint: disable=invalid-name # numpydoc ignore=PR02
103104 (a) When you omit the ``copy`` parameter, you should never reuse the parameter
104105 array later on; ideally, you should reassign it immediately::
105106
106- >>> import array_api_extra as xpx
107- >>> x = xpx.at(x, 0).set(2)
107+ import array_api_extra as xpx
108+
109+ x = xpx.at(x, 0).set(2)
108110
109111 The above best practice pattern ensures that the behaviour won't change depending
110112 on whether ``x`` is writeable or not, as the original ``x`` object is dereferenced
@@ -114,9 +116,9 @@ class at: # pylint: disable=invalid-name # numpydoc ignore=PR02
114116 On the reverse, the anti-pattern below must be avoided, as it will result in
115117 different behaviour on read-only versus writeable arrays::
116118
117- >>> x = xp.asarray([0, 0, 0])
118- >>> y = xpx.at(x, 0).set(2)
119- >>> z = xpx.at(x, 1).set(3)
119+ x = xp.asarray([0, 0, 0])
120+ y = xpx.at(x, 0).set(2)
121+ z = xpx.at(x, 1).set(3)
120122
121123 In the above example, both calls to ``xpx.at`` update ``x`` in place *if possible*.
122124 This causes the behaviour to diverge depending on whether ``x`` is writeable or not:
@@ -129,22 +131,23 @@ class at: # pylint: disable=invalid-name # numpydoc ignore=PR02
129131 The correct pattern to use if you want diverging outputs from the same input is
130132 to enforce copies::
131133
132- >>> x = xp.asarray([0, 0, 0])
133- >>> y = xpx.at(x, 0).set(2, copy=True) # Never updates x
134- >>> z = xpx.at(x, 1).set(3) # May or may not update x in place
135- >>> del x # avoid accidental reuse of x as we don't know its state anymore
134+ x = xp.asarray([0, 0, 0])
135+ y = xpx.at(x, 0).set(2, copy=True) # Never updates x
136+ z = xpx.at(x, 1).set(3) # May or may not update x in place
137+ del x # avoid accidental reuse of x as we don't know its state anymore
136138
137139 (b) The array API standard does not support integer array indices.
138140 The behaviour of update methods when the index is an array of integers is
139141 undefined and will vary between backends; this is particularly true when the
140142 index contains multiple occurrences of the same index, e.g.::
141143
142- >>> import numpy as np
143- >>> import jax.numpy as jnp
144- >>> import array_api_extra as xpx
145- >>> xpx.at(np.asarray([123]), np.asarray([0, 0])).add(1)
144+ import numpy as np
145+ import jax.numpy as jnp
146+ import array_api_extra as xpx
147+
148+ xpx.at(np.asarray([123]), np.asarray([0, 0])).add(1)
146149 array([124])
147- >>> xpx.at(jnp.asarray([123]), jnp.asarray([0, 0])).add(1)
150+ xpx.at(jnp.asarray([123]), jnp.asarray([0, 0])).add(1)
148151 Array([125], dtype=int32)
149152
150153 See Also
@@ -164,38 +167,39 @@ class at: # pylint: disable=invalid-name # numpydoc ignore=PR02
164167
165168 This pattern::
166169
167- >>> mask = m(x)
168- >>> x[mask] = f(x[mask])
170+ mask = m(x)
171+ x[mask] = f(x[mask])
169172
170173 Can't be replaced by `at`, as it won't work on Dask and JAX inside jax.jit::
171174
172- >>> mask = m(x)
173- >>> x = xpx.at(x, mask).set(f(x[mask]) # Crash on Dask and jax.jit
175+ mask = m(x)
176+ x = xpx.at(x, mask).set(f(x[mask]) ) # Crash on Dask and jax.jit
174177
175178 You should instead use::
176179
177- >>> x = xp.where(m(x), f(x), x)
180+ x = xp.where(m(x), f(x), x)
178181
179182 Examples
180183 --------
181184 Given either of these equivalent expressions::
182185
183- >>> import array_api_extra as xpx
184- >>> x = xpx.at(x)[1].add(2)
185- >>> x = xpx.at(x, 1).add(2)
186+ import array_api_extra as xpx
187+
188+ x = xpx.at(x)[1].add(2)
189+ x = xpx.at(x, 1).add(2)
186190
187191 If x is a JAX array, they are the same as::
188192
189- >>> x = x.at[1].add(2)
193+ x = x.at[1].add(2)
190194
191195 If x is a read-only NumPy array, they are the same as::
192196
193- >>> x = x.copy()
194- >>> x[1] += 2
197+ x = x.copy()
198+ x[1] += 2
195199
196200 For other known backends, they are the same as::
197201
198- >>> x[1] += 2
202+ x[1] += 2
199203 """
200204
201205 _x : Array
0 commit comments