@@ -10,7 +10,8 @@ contributors.md
10
10
```
11
11
12
12
This is a library housing "array-agnostic" implementations of functions built on
13
- top of [ the Python array API standard] ( https://data-apis.org/array-api/ ) .
13
+ top of [ the Python array API standard] ( https://data-apis.org/array-api/ ) , as
14
+ well as delegation to existing implementations for known array library backends.
14
15
15
16
The intended users of this library are "array-consuming" libraries which are
16
17
using [ array-api-compat] ( https://data-apis.org/array-api-compat/ ) to make their
@@ -23,7 +24,7 @@ It is currently used by:
23
24
24
25
- [ SciPy] ( https://github.com/scipy/scipy ) - Fundamental algorithms for
25
26
scientific computing.
26
- - ...
27
+ - _ your library? Let us know! _
27
28
28
29
(installation)=
29
30
@@ -33,16 +34,18 @@ It is currently used by:
33
34
[ on PyPI] ( https://pypi.org/project/array-api-extra/ ) :
34
35
35
36
``` shell
37
+ uv add array-api-extra
38
+ # or
36
39
python -m pip install array-api-extra
37
40
```
38
41
39
42
And
40
43
[ on conda-forge] ( https://prefix.dev/channels/conda-forge/packages/array-api-extra ) :
41
44
42
45
``` shell
43
- mamba install array-api-extra
44
- # or
45
46
pixi add array-api-extra
47
+ # or
48
+ mamba install array-api-extra
46
49
```
47
50
48
51
``` {warning}
@@ -52,7 +55,7 @@ a specific version, or vendor the library inside your own.
52
55
```
53
56
54
57
``` {note}
55
- This library depends on array-api-compat. We aim for compatibility with
58
+ This library depends on ` array-api-compat` . We aim for compatibility with
56
59
the latest released version of array-api-compat, and your mileage may vary
57
60
with older or dev versions.
58
61
```
@@ -69,8 +72,8 @@ and copy it into the appropriate place in your library, like:
69
72
cp -a array-api-extra/src/array_api_extra mylib/vendored/
70
73
```
71
74
72
- ` array-api-extra ` depends on ` array-api-compat ` . You may either add a dependency
73
- in your own project to ` array-api-compat ` or vendor it too:
75
+ You may either add a dependency to array-api-compat in your own project, or
76
+ vendor it too:
74
77
75
78
1 . Clone
76
79
[ the array-api-compat repository] ( https://github.com/data-apis/array-api-compat )
@@ -81,14 +84,14 @@ in your own project to `array-api-compat` or vendor it too:
81
84
```
82
85
83
86
2 . Create a new hook file which array-api-extra will use instead of the
84
- top-level ` array-api-compat ` if present:
87
+ top-level array-api-compat if present:
85
88
86
89
```
87
90
echo 'from mylib.vendored.array_api_compat import *' > mylib/vendored/_array_api_compat_vendor.py
88
91
```
89
92
90
- This also allows overriding ` array-api-compat ` functions if you so wish. E.g.
91
- your ` mylib/vendored/_array_api_compat_vendor.py ` could look like this:
93
+ This also allows overriding array-api-compat functions if you so wish. E.g. your
94
+ ` mylib/vendored/_array_api_compat_vendor.py ` could look like this:
92
95
93
96
``` python
94
97
from mylib.vendored.array_api_compat import *
@@ -104,6 +107,13 @@ def array_namespace(*xs, **kwargs):
104
107
return _array_namespace_orig(* xs, ** kwargs)
105
108
```
106
109
110
+ ``` {tip}
111
+ See [an example of this in SciPy][scipy-vendor-example].
112
+ ```
113
+
114
+ [ scipy-vendor-example] :
115
+ https://github.com/scipy/scipy/blob/main/scipy/_lib/_array_api_compat_vendor.py
116
+
107
117
(usage)=
108
118
109
119
## Usage
@@ -115,9 +125,9 @@ import array_api_extra as xpx
115
125
116
126
...
117
127
xp = array_namespace(x)
118
- y = xp.sum(x)
128
+ y = xp.sum(x) # use functions from `xp` as normal
119
129
...
120
- return xpx.atleast_nd(y, ndim = 2 , xp = xp)
130
+ return xpx.atleast_nd(y, ndim = 2 , xp = xp) # use functions from `xpx`, passing `xp=xp`
121
131
```
122
132
123
133
``` {note}
@@ -131,13 +141,13 @@ is called internally to determine the namespace.
131
141
```
132
142
133
143
In the examples shown in the docstrings of functions from this library,
134
- [ ` array-api-strict ` ] ( https://data-apis.org/array-api-strict/ ) is used as the
135
- array namespace ` xp ` . In reality, code using this library will be written to
136
- work with any compatible array namespace as ` xp ` , not any particular
137
- implementation.
144
+ [ array-api-strict] ( https://data-apis.org/array-api-strict/ ) is used as the array
145
+ namespace ` xp ` . In reality, code using this library will be written to work with
146
+ any compatible array namespace as ` xp ` , not any particular implementation.
138
147
139
- Some functions may only work with array libraries supported by array-api-compat.
140
- This will be clearly indicated in the docs.
148
+ Some functions may only work with specific array libraries supported by
149
+ array-api-compat. This should be clearly indicated in the docs - please open an
150
+ issue if this is not the case!
141
151
142
152
(scope)=
143
153
@@ -151,13 +161,17 @@ Functions that are in-scope for this library will:
151
161
libraries.
152
162
- Be implemented with type annotations and
153
163
[ numpydoc-style docstrings] ( https://numpydoc.readthedocs.io/en/latest/format.html ) .
154
- - Be tested against ` array-api-strict ` .
164
+ - Be tested against array-api-strict and various existing backends .
155
165
156
166
Functions are implemented purely in terms of the array API standard where
157
167
possible. Where functions must use library-specific helpers for libraries
158
168
supported by array-api-compat, this will be clearly marked in their API
159
169
reference page.
160
170
171
+ Delegation is added for some functions to use native implementations for the
172
+ given array type, instead of the array-agnostic implementations, as this may
173
+ increase performance.
174
+
161
175
In particular, the following kinds of function are also in-scope:
162
176
163
177
- Functions which implement
@@ -168,15 +182,12 @@ In particular, the following kinds of function are also in-scope:
168
182
169
183
The following features are currently out-of-scope for this library:
170
184
171
- - Delegation to known, existing array libraries (unless necessary).
172
- - It is quite simple to wrap functions in this library to also use existing
173
- implementations. Such delegation will not live in this library for now, but
174
- the array-agnostic functions in this library could form an array-agnostic
175
- backend for such delegating functions in the future, here or elsewhere.
176
185
- Functions which accept "array-like" input, or standard-incompatible
177
186
namespaces.
178
187
- It is possible to prepare input arrays and a standard-compatible namespace
179
- via ` array-api-compat ` downstream in consumer libraries.
188
+ via array-api-compat downstream in consumer libraries. The ` xp ` argument can
189
+ also be omitted to infer the standard-compatible namespace using
190
+ ` array_namespace ` internally.
180
191
- Functions which are specific to a particular domain.
181
192
- These functions may belong better in an array-consuming library which is
182
193
specific to that domain.
0 commit comments