@@ -6,7 +6,7 @@ NEP 31 — Context-local and global overrides of the NumPy API
6
6
:Author: Ralf Gommers <rgommers@quansight.com>
7
7
:Status: Draft
8
8
:Type: Standards Track
9
- :Created: 2019-07-31
9
+ :Created: 2019-08-22
10
10
11
11
12
12
Abstract
@@ -16,19 +16,27 @@ This NEP proposes to make all of NumPy's public API overridable via a backend
16
16
mechanism, using a library called ``uarray `` `[1] `_
17
17
18
18
``uarray `` provides global and context-local overrides, as well as a dispatch
19
- mechanism similar to NEP-18 `[2] `_. This NEP proposes to supercede NEP-18,
20
- and is intended as a comprehensive resolution to NEP-22 `[3] `_.
19
+ mechanism similar to NEP-18 `[2] `_. First experiences with ``__array_function__ ``
20
+ show that it is necessary to be able to override NumPy functions that
21
+ *do not take an array-like argument *, and hence aren't overridable via
22
+ ``__array_function__ ``. The most pressing need is array creation and coercion
23
+ functions - see e.g. NEP-30 `[9] `_.
24
+
25
+ This NEP proposes to allow, in an opt-in fashion, overriding any part of the NumPy API.
26
+ It is intended as a comprehensive resolution to NEP-22 `[3] `_, and obviates the need to
27
+ add an ever-growing list of new protocols for each new type of function or object that needs
28
+ to become overridable.
21
29
22
30
Motivation and Scope
23
31
--------------------
24
32
25
- The motivation behind this library is manifold : First, there have been several attempts to allow
33
+ The motivation behind `` uarray `` is manyfold : First, there have been several attempts to allow
26
34
dispatch of parts of the NumPy API, including (most prominently), the ``__array_ufunc__ `` protocol
27
35
in NEP-13 `[4] `_, and the ``__array_function__ `` protocol in NEP-18 `[2] `_, but this has shown the
28
- need for further protocols to be developed, including a protocol for coercion. `[5] `_. The reasons
36
+ need for further protocols to be developed, including a protocol for coercion (see `[5] `_) . The reasons
29
37
these overrides are needed have been extensively discussed in the references, and this NEP will not
30
38
attempt to go into the details of why these are needed. Another pain point requiring yet another
31
- protocol is the duck-array protocol. `[9] `_
39
+ protocol is the duck-array protocol (see `[9] `_).
32
40
33
41
This NEP takes a more holistic approach: It assumes that there are parts of the API that need to be
34
42
overridable, and that these will grow over time. It provides a general framework and a mechanism to
@@ -39,41 +47,51 @@ functions that can be easily expressed in terms of others, as well as a reposito
39
47
that help in the implementation of duck-arrays that most duck-arrays would require.
40
48
41
49
The third is the existence of actual, third party dtype packages, and
42
- their desire to blend into the NumPy ecosystem. `[6] `_. This is a separate
50
+ their desire to blend into the NumPy ecosystem (see `[6] `_) . This is a separate
43
51
issue compared to the C-level dtype redesign proposed in `[7] `_, it's about
44
52
allowing third-party dtype implementations to work with NumPy, much like third-party array
45
53
implementations.
46
54
47
55
This NEP proposes the following: That ``unumpy `` `[8] `_ becomes the recommended override mechanism
48
- for the NumPy API.
56
+ for the parts of the NumPy API not yet covered by ``__array_function__ `` or ``__array_ufunc__ ``,
57
+ and that ``uarray `` is vendored into a new namespace within NumPy to give users and downstream dependencies
58
+ access to these overrides. This vendoring mechanism is similar to what SciPy decided to do for
59
+ making ``scipy.fft `` overridable (see `[10] `_).
49
60
50
61
51
62
Detailed description
52
63
--------------------
53
64
54
- This section will not attempt to explain the specifics or the mechanism of ``uarray ``,
55
- that is explained in the ``uarray `` documentation. `[1] `_ However, the NumPy community
56
- will have input into the design of ``uarray ``, and any backward-incompatible changes
57
- will be discussed on the mailing list.
65
+ _Note that this section will not attempt to explain the specifics or the mechanism of ``uarray ``,_
66
+ _that is explained in the ``uarray `` documentation. `[1] `_ However, the NumPy community _
67
+ _will have input into the design of ``uarray ``, and any backward-incompatible changes _
68
+ _will be discussed on the mailing list._
69
+
70
+ The way we propose the overrides will be used by end users is::
71
+
72
+ from numpy import unumpy
73
+ TODO
58
74
59
- The first goal of this NEP is as follows: To complete an overridable version of NumPy,
60
- called `` unumpy `` ` [8] `_, the implementation of which is already underway. Again, `` unumpy ``
61
- will not be explained here, the reader should refer to its documentation for this purpose.
75
+ And a library that implements a NumPy-like API will use it like::
76
+
77
+ TODO: example corresponding to NEP 30 `duckarray`
62
78
63
79
The only change this NEP proposes at its acceptance, is to make ``unumpy `` the officially recommended
64
- way to override NumPy. ``unumpy `` will remain a separate repository/package, and will be developed
80
+ way to override NumPy. ``unumpy `` will remain a separate repository/package (which we propose to vendor
81
+ to avoid a hard dependency, and use the separate ``unumpy `` package only if it is installed)
82
+ rather than depend on for the time being), and will be developed
65
83
primarily with the input of duck-array authors and secondarily, custom dtype authors, via the usual
66
84
GitHub workflow. There are a few reasons for this:
67
85
68
86
* Faster iteration in the case of bugs or issues.
69
87
* Faster design changes, in the case of needed functionality.
70
- * Lower likelihood to be stuck with a bad design decision .
88
+ * `` unumpy `` will work with older versions of NumPy as well .
71
89
* The user and library author opt-in to the override process,
72
90
rather than breakages happening when it is least expected.
73
91
In simple terms, bugs in ``unumpy `` mean that ``numpy `` remains
74
92
unaffected.
75
- * The upgrade pathway to NumPy 2.0 becomes simpler, requiring just
76
- a backend change, and allowing both to exist side-by-side.
93
+
94
+ ** FIXME: this section doesn't match the proposal. in the abstract and motivation anymore. **
77
95
78
96
Once maturity is achieved, ``unumpy `` be moved into the NumPy organization,
79
97
and NumPy will become the reference implementation for ``unumpy ``.
@@ -150,8 +168,13 @@ There are no backward incompatible changes proposed in this NEP.
150
168
Alternatives
151
169
------------
152
170
153
- The current alternative to this problem, already implemented, is a
154
- combination of NEP-18 and NEP-13.
171
+ The current alternative to this problem is NEP-30 plus adding more protocols
172
+ (not yet specified) in addition to it. Even then, some parts of the NumPy
173
+ API will remain non-overridable, so it's a partial alternative.
174
+
175
+ The main alternative to vendoring ``unumpy `` is to simply move it into NumPy
176
+ completely and not distribute it as a separate package. This would also achieve
177
+ the proposed goals, however we prefer to keep it a separate package for now.
155
178
156
179
157
180
Discussion
@@ -204,6 +227,11 @@ References and Footnotes
204
227
205
228
[9] NEP 30 — Duck Typing for NumPy Arrays - Implementation: https://www.numpy.org/neps/nep-0030-duck-array-protocol.html
206
229
230
+ .. _[10] :
231
+
232
+ [10] http://scipy.github.io/devdocs/fft.html#backend-control
233
+
234
+
207
235
Copyright
208
236
---------
209
237
0 commit comments