Skip to content

Address return value type for single-element access #125

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 3 commits into from
Feb 21, 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
18 changes: 17 additions & 1 deletion spec/API_specification/array_object.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,23 @@ Element-wise results must equal the results returned by the equivalent element-w
(method-__getitem__)=
### \_\_getitem\_\_(x, key, /)

_TODO: dependent on the indexing specification._
Returns `x[key]`.

#### Parameters

- **x**: _<array;>_

- array instance.

- **key**: _Union\[ int, slice, Tuple\[ Union\[ int, slice ], ... ], <array> ]_

- index key.

#### Returns

- **out**: _<array>_

- an array containing the accessed value(s). The returned array must have the same data type as `x`.

(method-__gt__)=
### \_\_gt\_\_(x1, x2, /)
Expand Down
11 changes: 8 additions & 3 deletions spec/API_specification/indexing.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ Multi-dimensional arrays must extend the concept of single-axis indexing to mult

- Providing [ellipsis](https://docs.python.org/3/library/constants.html#Ellipsis) must apply `:` to each dimension necessary to index all dimensions (e.g., if `A` has rank `4`, `A[1:, ..., 2:5] == A[1:, :, :, 2:5]`). Only a single ellipsis must be allowed. An `IndexError` exception must be raised if more than one ellipsis is provided.

- The result of multi-axis indexing must be an array of the same data type as the indexed array.

```{note}

This specification leaves unspecified the behavior of providing a slice which attempts to select elements along a particular axis, but whose starting index is out-of-bounds.
Expand All @@ -179,4 +177,11 @@ An array must support indexing via a **single** `M`-dimensional boolean array `B

- A zero-dimensional boolean index array (equivalent to `True` or `False`) must follow the same axis replacement rules stated above. Namely, a zero-dimensional boolean index array removes zero dimensions and adds a single dimension of length `1` if the index array's value is `True` and of length `0` if the index array's value is `False`. Accordingly, for a zero-dimensional boolean index array `B`, the result of `A[B]` has shape `S = (1, s1, ..., sN)` if the index array's value is `True` and has shape `S = (0, s1, ..., sN)` if the index array's value is `False`.

- The result of indexing into an array via a boolean index array must be an array of the same data type as the indexed array.
## Return Values

The result of an indexing operation (e.g., multi-axis indexing, boolean array indexing, etc) must be an array of the same data type as the indexed array.

```{note}

The specified return value behavior includes indexing operations which return a single value (e.g., accessing a single element within a one-dimensional array).
```