Skip to content

Add __array_namespace__ as a required method on the array object #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions spec/API_specification/array_object.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,29 @@ Evaluates `x1_i & x2_i` for each element `x1_i` of an array instance `x1` with t
Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_and(x1, x2)`](elementwise_functions.md#logical_andx1-x2-).
```


(method-__array_namespace__)=
### \_\_array_namespace\_\_(self, /, *, api_version=None)

Returns an object that has all the array API functions on it.

#### Parameters

- **self**: _<array>_

- array instance.

- **api_version**: _<Optional\[str\]>_

- 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`.

#### Returns

- **out**: _<object>_

- 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.


(method-__bool__)=
### \_\_bool\_\_(x, /)

Expand Down
12 changes: 6 additions & 6 deletions spec/purpose_and_scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ namespace (e.g. `import package_name.array_api`). This has two issues though:
{ref}`api-versioning`).

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

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

The `xp` namespace must contain the array object and all functionality
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed "array object" here, because the array class is not itself required to be a name in the namespace.

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


* * *
Expand Down