Skip to content

Commit a74b550

Browse files
committed
Respond to review by @peterbell10.
1 parent f522cbf commit a74b550

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

doc/neps/nep-0031-uarray.rst

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ Proposals
114114
~~~~~~~~~
115115

116116
The only change this NEP proposes at its acceptance, is to make ``unumpy`` the
117-
officially recommended way to override NumPy. ``unumpy`` will remain a separate
117+
officially recommended way to override NumPy, along with making some submodules
118+
overridable by default via ``uarray``. ``unumpy`` will remain a separate
118119
repository/package (which we propose to vendor to avoid a hard dependency, and
119120
use the separate ``unumpy`` package only if it is installed, rather than depend
120121
on for the time being). In concrete terms, ``numpy.overridable`` becomes an
@@ -164,8 +165,9 @@ implementation of duck-arrays that most duck-arrays would require. This would
164165
allow us to avoid designing entire protocols, e.g., a protocol for stacking
165166
and concatenating would be replaced by simply implementing ``stack`` and/or
166167
``concatenate`` and then providing default implementations for everything else
167-
in that class. The same applies for transposing, and many other functions
168-
which cannot even be concretely covered by protocols.
168+
in that class. The same applies for transposing, and many other functions for
169+
which protocols haven't been proposed, such as ``isin`` in terms of ``in1d``,
170+
``setdiff1d`` in terms of ``unique``, and so on.
169171

170172
It also allows one to override functions in a manner which
171173
``__array_function__`` simply cannot, such as overriding ``np.einsum`` with the
@@ -238,7 +240,11 @@ This is different from monkeypatching in a few different ways:
238240
* There is the ability of locally switching the backend.
239241
* It has been `suggested <http://numpy-discussion.10968.n7.nabble.com/NEP-31-Context-local-and-global-overrides-of-the-NumPy-API-tp47452p47472.html>`_
240242
that the reason that 1.17 hasn't landed in the Anaconda defaults channel is
241-
due to the incompatibility between monkeypatching and `__array_function__`.
243+
due to the incompatibility between monkeypatching and ``__array_function__``,
244+
as monkeypatching would bypass the protocol completely.
245+
* Statements of the form ``from numpy import x; x`` and ``np.x`` would have
246+
different results depending on whether the import was made before or
247+
after monkeypatching happened.
242248

243249
All this isn't possible at all with ``__array_function__`` or
244250
``__array_ufunc__``.
@@ -249,8 +255,8 @@ needed for this, in the `NumPy roadmap <https://numpy.org/neps/roadmap.html#othe
249255
For ``numpy.random``, it's still necessary to make the C-API fit the one
250256
proposed in `NEP-19 <https://numpy.org/neps/nep-0019-rng-policy.html>`_.
251257
This is impossible for `mkl-random`, because then it would need to be
252-
rewritten to fit that framework. The general guarantees on stream
253-
compatibility will be the same as before: If there's a backend that affects
258+
rewritten to fit that framework. The guarantees on stream
259+
compatibility will be the same as before, but if there's a backend that affects
254260
``numpy.random`` set, we make no guarantees about stream compatibility, and it
255261
is up to the backend author to provide their own guarantees.
256262

@@ -267,10 +273,12 @@ As a concrete example, consider the following:
267273
with unumpy.determine_backend(array_like, np.ndarray):
268274
unumpy.arange(len(array_like))
269275
270-
While this does not exist yet in ``uarray``, it is trivial to add it. The
271-
answer is to simply call ``__ua_convert__`` on the passed-in array with
272-
``coerce=False`` for each backend, and comparing the result to
273-
``NotImplemented``.
276+
While this does not exist yet in ``uarray``, it is trivial to add it. The need for
277+
this kind of code exists because one might want to have an alternative for the
278+
proposed ``*_like`` functions, or the ``like=`` keyword argument. The need for these
279+
exists because there are functions in the NumPy API that do not take a dispatchable
280+
argument, but there is still the need to select a backend based on a different
281+
dispatchable.
274282

275283
The need for an opt-in module
276284
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -280,7 +288,8 @@ The need for an opt-in module is realised because of a few reasons:
280288
* There are parts of the API (like `numpy.asarray`) that simply cannot be
281289
overridden due to incompatibility concerns with C/Cython extensions, however,
282290
one may want to coerce to a duck-array using ``asarray`` with a backend set.
283-
* There are possible issues around an implicit option and monkeypatching.
291+
* There are possible issues around an implicit option and monkeypatching, such
292+
as those mentioned above.
284293

285294
NEP 18 notes that this may require maintenance of two separate APIs. However,
286295
this burden may be lessened by, for example, parametrizing all tests over

0 commit comments

Comments
 (0)