Skip to content

Commit dde04ac

Browse files
authored
Address return value type for single-element access (#125)
1 parent e1870ff commit dde04ac

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

spec/API_specification/array_object.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,23 @@ Element-wise results must equal the results returned by the equivalent element-w
558558
(method-__getitem__)=
559559
### \_\_getitem\_\_(x, key, /)
560560

561-
_TODO: dependent on the indexing specification._
561+
Returns `x[key]`.
562+
563+
#### Parameters
564+
565+
- **x**: _<array;>_
566+
567+
- array instance.
568+
569+
- **key**: _Union\[ int, slice, Tuple\[ Union\[ int, slice ], ... ], <array> ]_
570+
571+
- index key.
572+
573+
#### Returns
574+
575+
- **out**: _<array>_
576+
577+
- an array containing the accessed value(s). The returned array must have the same data type as `x`.
562578

563579
(method-__gt__)=
564580
### \_\_gt\_\_(x1, x2, /)

spec/API_specification/indexing.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ Multi-dimensional arrays must extend the concept of single-axis indexing to mult
151151
152152
- 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.
153153
154-
- The result of multi-axis indexing must be an array of the same data type as the indexed array.
155-
156154
```{note}
157155
158156
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.
@@ -179,4 +177,11 @@ An array must support indexing via a **single** `M`-dimensional boolean array `B
179177
180178
- 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`.
181179
182-
- 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.
180+
## Return Values
181+
182+
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.
183+
184+
```{note}
185+
186+
The specified return value behavior includes indexing operations which return a single value (e.g., accessing a single element within a one-dimensional array).
187+
```

0 commit comments

Comments
 (0)