Skip to content
Open
Changes from 1 commit
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
21 changes: 16 additions & 5 deletions src/array_api_stubs/_draft/array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

__all__ = ["array"]

from typing import SupportsIndex
from ._types import (
array,
dtype as Dtype,
Expand Down Expand Up @@ -604,11 +605,11 @@ def __ge__(self: array, other: Union[int, float, array], /) -> array:
def __getitem__(
self: array,
key: Union[
int,
SupportsIndex,
slice,
ellipsis,
None,
Tuple[Union[int, slice, ellipsis, None], ...],
Tuple[Union[SupportsIndex, slice, ellipsis, None], ...],
array,
],
/,
Expand All @@ -620,9 +621,13 @@ def __getitem__(
----------
self: array
array instance.
key: Union[int, slice, ellipsis, None, Tuple[Union[int, slice, ellipsis, None], ...], array]
key: Union[SupportsIndex, slice, ellipsis, None, Tuple[Union[SupportsIndex, slice, ellipsis, None], ...], array]
index key.


.. note::
``key`` can only be an array if it is valid for boolean array indexing, or supports ``__index__()``.
Copy link
Member

Choose a reason for hiding this comment

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

Presumably somewhere else we say it should support __index__ if and only if it is a 0-D integer array. Maybe it would be clearer to just say that directly here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep that'd help, let me know on the wording from my latest commit.


Returns
-------
out: array
Expand Down Expand Up @@ -1077,7 +1082,11 @@ def __rshift__(self: array, other: Union[int, array], /) -> array:
def __setitem__(
self: array,
key: Union[
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array
SupportsIndex,
slice,
ellipsis,
Tuple[Union[SupportsIndex, slice, ellipsis], ...],
array,
],
value: Union[int, float, bool, array],
/,
Expand All @@ -1089,11 +1098,13 @@ def __setitem__(
----------
self: array
array instance.
key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array]
key: Union[SupportsIndex, slice, ellipsis, Tuple[Union[SupportsIndex, slice, ellipsis], ...], array]
index key.
value: Union[int, float, bool, array]
value(s) to set. Must be compatible with ``self[key]`` (see :ref:`broadcasting`).

.. note::
``key`` can only be an array if it is valid for boolean array indexing, or supports ``__index__()``.

.. note::

Expand Down