@@ -114,7 +114,8 @@ Proposals
114
114
~~~~~~~~~
115
115
116
116
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
118
119
repository/package (which we propose to vendor to avoid a hard dependency, and
119
120
use the separate ``unumpy `` package only if it is installed, rather than depend
120
121
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
164
165
allow us to avoid designing entire protocols, e.g., a protocol for stacking
165
166
and concatenating would be replaced by simply implementing ``stack `` and/or
166
167
``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.
169
171
170
172
It also allows one to override functions in a manner which
171
173
``__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:
238
240
* There is the ability of locally switching the backend.
239
241
* It has been `suggested <http://numpy-discussion.10968.n7.nabble.com/NEP-31-Context-local-and-global-overrides-of-the-NumPy-API-tp47452p47472.html >`_
240
242
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.
242
248
243
249
All this isn't possible at all with ``__array_function__ `` or
244
250
``__array_ufunc__ ``.
@@ -249,8 +255,8 @@ needed for this, in the `NumPy roadmap <https://numpy.org/neps/roadmap.html#othe
249
255
For ``numpy.random ``, it's still necessary to make the C-API fit the one
250
256
proposed in `NEP-19 <https://numpy.org/neps/nep-0019-rng-policy.html >`_.
251
257
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
254
260
``numpy.random `` set, we make no guarantees about stream compatibility, and it
255
261
is up to the backend author to provide their own guarantees.
256
262
@@ -267,10 +273,12 @@ As a concrete example, consider the following:
267
273
with unumpy.determine_backend(array_like, np.ndarray):
268
274
unumpy.arange(len (array_like))
269
275
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.
274
282
275
283
The need for an opt-in module
276
284
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -280,7 +288,8 @@ The need for an opt-in module is realised because of a few reasons:
280
288
* There are parts of the API (like `numpy.asarray `) that simply cannot be
281
289
overridden due to incompatibility concerns with C/Cython extensions, however,
282
290
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.
284
293
285
294
NEP 18 notes that this may require maintenance of two separate APIs. However,
286
295
this burden may be lessened by, for example, parametrizing all tests over
0 commit comments