Skip to content

Backport type fixes to __getitem__ to previous specification revisions #687

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
Nov 6, 2023
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
3 changes: 3 additions & 0 deletions spec/draft/API_specification/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ Multi-dimensional arrays must extend the concept of single-axis indexing to mult
.. note::
Expanding dimensions can be equivalently achieved via repeated invocation of :func:`~array_api.expand_dims`.

.. note::
The constant ``newaxis`` is an alias of ``None`` and can thus be used in a similar manner as ``None``.

- Except in the case of providing a single ellipsis (e.g., ``A[2:10, ...]`` or ``A[1:, ..., 2:5]``), the number of provided single-axis indexing expressions (excluding ``None``) should equal ``N``. For example, if ``A`` has rank ``2``, a single-axis indexing expression should be explicitly provided for both axes (e.g., ``A[2:10, :]``). An ``IndexError`` exception should be raised if the number of provided single-axis indexing expressions (excluding ``None``) is less than ``N``.

.. note::
Expand Down
9 changes: 7 additions & 2 deletions src/array_api_stubs/_2021_12/array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,12 @@ def __ge__(self: array, other: Union[int, float, array], /) -> array:
def __getitem__(
self: array,
key: Union[
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array
int,
slice,
ellipsis,
None,
Tuple[Union[int, slice, ellipsis, None], ...],
array,
],
/,
) -> array:
Expand All @@ -464,7 +469,7 @@ def __getitem__(
----------
self: array
array instance.
key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array]
key: Union[int, slice, ellipsis, None, Tuple[Union[int, slice, ellipsis, None], ...], array]
index key.

Returns
Expand Down
9 changes: 7 additions & 2 deletions src/array_api_stubs/_2022_12/array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,12 @@ def __ge__(self: array, other: Union[int, float, array], /) -> array:
def __getitem__(
self: array,
key: Union[
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array
int,
slice,
ellipsis,
None,
Tuple[Union[int, slice, ellipsis, None], ...],
array,
],
/,
) -> array:
Expand All @@ -488,7 +493,7 @@ def __getitem__(
----------
self: array
array instance.
key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array]
key: Union[int, slice, ellipsis, None, Tuple[Union[int, slice, ellipsis, None], ...], array]
index key.

Returns
Expand Down
9 changes: 7 additions & 2 deletions src/array_api_stubs/_draft/array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,12 @@ def __ge__(self: array, other: Union[int, float, array], /) -> array:
def __getitem__(
self: array,
key: Union[
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis, None], ...], array
int,
slice,
ellipsis,
None,
Tuple[Union[int, slice, ellipsis, None], ...],
array,
],
/,
) -> array:
Expand All @@ -490,7 +495,7 @@ def __getitem__(
----------
self: array
array instance.
key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis, None], ...], array]
key: Union[int, slice, ellipsis, None, Tuple[Union[int, slice, ellipsis, None], ...], array]
index key.

Returns
Expand Down