Skip to content

Commit 0941067

Browse files
authored
Add __array_namespace__ as a required method on the array object (#140)
1 parent dcdfbde commit 0941067

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

spec/API_specification/array_object.md

+23
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,29 @@ Evaluates `x1_i & x2_i` for each element `x1_i` of an array instance `x1` with t
377377
Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_and(x1, x2)`](elementwise_functions.md#logical_andx1-x2-).
378378
```
379379

380+
381+
(method-__array_namespace__)=
382+
### \_\_array_namespace\_\_(self, /, *, api_version=None)
383+
384+
Returns an object that has all the array API functions on it.
385+
386+
#### Parameters
387+
388+
- **self**: _<array>_
389+
390+
- array instance.
391+
392+
- **api_version**: _<Optional\[str\]>_
393+
394+
- string representing the version of the array API specification to be returned, in `'YYYY.MM'` form, for example, `'2020.10'`. If it is `None`, it should return the namespace corresponding to latest version of the array API specification. If the given version is invalid or not implemented for the given module, an error should be raised. Default: `None`.
395+
396+
#### Returns
397+
398+
- **out**: _<object>_
399+
400+
- an object representing the array API namespace. It should have every top-level function defined in the specification as an attribute. It may contain other public names as well, but it is recommended to only include those names that are part of the specification.
401+
402+
380403
(method-__bool__)=
381404
### \_\_bool\_\_(x, /)
382405

spec/purpose_and_scope.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ namespace (e.g. `import package_name.array_api`). This has two issues though:
335335
{ref}`api-versioning`).
336336

337337
To address both issues, a uniform way must be provided by a conforming
338-
implementation to access the API namespace, namely a method on the array object:
338+
implementation to access the API namespace, namely a [method on the array
339+
object](method-__array_namespace__):
339340

340341
```
341342
xp = x.__array_namespace__()
@@ -362,11 +363,10 @@ standard can become final. We prefer to delay this decision, to see how
362363
NEP 37 adoption will work out.
363364
```
364365

365-
The `xp` namespace must contain the array object and all functionality
366-
specified in {ref}`api-specification`. It may contain other functionality,
367-
however it is recommended not to add other functions or objects, because that
368-
may make it harder for users to write code that will work with multiple array
369-
libraries.
366+
The `xp` namespace must contain all functionality specified in
367+
{ref}`api-specification`. It may contain other functionality, however it is
368+
recommended not to add other functions or objects, because that may make it
369+
harder for users to write code that will work with multiple array libraries.
370370

371371

372372
* * *

0 commit comments

Comments
 (0)