From 122c99a42d5a2412356b0d17cd8dfb985fc8a8c5 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 15 Jul 2024 15:47:41 -0600 Subject: [PATCH 1/6] Add a cross-reference to the indexing page in __getitem__ and __setitem__ --- src/array_api_stubs/_2021_12/array_object.py | 4 ++++ src/array_api_stubs/_2022_12/array_object.py | 4 ++++ src/array_api_stubs/_2023_12/array_object.py | 4 ++++ src/array_api_stubs/_draft/array_object.py | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/src/array_api_stubs/_2021_12/array_object.py b/src/array_api_stubs/_2021_12/array_object.py index 528e0a286..07bd2c3e3 100644 --- a/src/array_api_stubs/_2021_12/array_object.py +++ b/src/array_api_stubs/_2021_12/array_object.py @@ -465,6 +465,8 @@ def __getitem__( """ Returns ``self[key]``. + See :ref:`indexing` for details on supported indexing semantics. + Parameters ---------- self: array @@ -914,6 +916,8 @@ def __setitem__( """ Sets ``self[key]`` to ``value``. + See :ref:`indexing` for details on supported indexing semantics. + Parameters ---------- self: array diff --git a/src/array_api_stubs/_2022_12/array_object.py b/src/array_api_stubs/_2022_12/array_object.py index f00df850b..83abc9310 100644 --- a/src/array_api_stubs/_2022_12/array_object.py +++ b/src/array_api_stubs/_2022_12/array_object.py @@ -489,6 +489,8 @@ def __getitem__( """ Returns ``self[key]``. + See :ref:`indexing` for details on supported indexing semantics. + Parameters ---------- self: array @@ -937,6 +939,8 @@ def __setitem__( """ Sets ``self[key]`` to ``value``. + See :ref:`indexing` for details on supported indexing semantics. + Parameters ---------- self: array diff --git a/src/array_api_stubs/_2023_12/array_object.py b/src/array_api_stubs/_2023_12/array_object.py index d71a26293..5c0b10dd9 100644 --- a/src/array_api_stubs/_2023_12/array_object.py +++ b/src/array_api_stubs/_2023_12/array_object.py @@ -616,6 +616,8 @@ def __getitem__( """ Returns ``self[key]``. + See :ref:`indexing` for details on supported indexing semantics. + Parameters ---------- self: array @@ -1085,6 +1087,8 @@ def __setitem__( """ Sets ``self[key]`` to ``value``. + See :ref:`indexing` for details on supported indexing semantics. + Parameters ---------- self: array diff --git a/src/array_api_stubs/_draft/array_object.py b/src/array_api_stubs/_draft/array_object.py index d71a26293..5c0b10dd9 100644 --- a/src/array_api_stubs/_draft/array_object.py +++ b/src/array_api_stubs/_draft/array_object.py @@ -616,6 +616,8 @@ def __getitem__( """ Returns ``self[key]``. + See :ref:`indexing` for details on supported indexing semantics. + Parameters ---------- self: array @@ -1085,6 +1087,8 @@ def __setitem__( """ Sets ``self[key]`` to ``value``. + See :ref:`indexing` for details on supported indexing semantics. + Parameters ---------- self: array From e4f2b1d813d7c1fcea1335b6138e5a2b5b5a47c8 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 15 Jul 2024 15:47:57 -0600 Subject: [PATCH 2/6] Add a note stating that iteration is defined for 1-D arrays not other arrays Fixes #818. --- src/array_api_stubs/_draft/array_object.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/array_api_stubs/_draft/array_object.py b/src/array_api_stubs/_draft/array_object.py index 5c0b10dd9..e27d05c7e 100644 --- a/src/array_api_stubs/_draft/array_object.py +++ b/src/array_api_stubs/_draft/array_object.py @@ -629,6 +629,10 @@ def __getitem__( ------- out: array an array containing the accessed value(s). The returned array must have the same data type as ``self``. + + .. note:: + When ``__getitem__`` is defined on an object, Python will automatically define iteration (i.e., the behavior from ``iter(x)``) as ``x[0]``, ``x[1]``, .... This can also be implemented directly by defining ``__iter__``. Therefore, for 1-D arrays, iteration should produce the sequence ``x[0]``, ``x[1]``, ... of 0-D arrays. Iteration behavior for arrays with more than one dimension is unspecified and thus implementation-defined. + """ def __gt__(self: array, other: Union[int, float, array], /) -> array: From e56f56ab42bf4552ca9a6ba5f7b3e2b0e41d8762 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 18 Sep 2024 22:45:58 -0700 Subject: [PATCH 3/6] Apply suggestions from code review --- src/array_api_stubs/_draft/array_object.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_api_stubs/_draft/array_object.py b/src/array_api_stubs/_draft/array_object.py index e27d05c7e..a317270c7 100644 --- a/src/array_api_stubs/_draft/array_object.py +++ b/src/array_api_stubs/_draft/array_object.py @@ -631,7 +631,7 @@ def __getitem__( an array containing the accessed value(s). The returned array must have the same data type as ``self``. .. note:: - When ``__getitem__`` is defined on an object, Python will automatically define iteration (i.e., the behavior from ``iter(x)``) as ``x[0]``, ``x[1]``, .... This can also be implemented directly by defining ``__iter__``. Therefore, for 1-D arrays, iteration should produce the sequence ``x[0]``, ``x[1]``, ... of 0-D arrays. Iteration behavior for arrays with more than one dimension is unspecified and thus implementation-defined. + When ``__getitem__`` is defined on an object, Python will automatically define iteration (i.e., the behavior from ``iter(x)``) as ``x[0]``, ``x[1]``, and so forth. This can also be implemented directly by defining ``__iter__``. Therefore, for one-dimensional arrays, iteration should produce the sequence ``x[0]``, ``x[1]``, ... of zero-dimensional arrays. Iteration behavior for arrays having more than one dimension is unspecified and thus implementation-defined. """ From ee793629999b9075621ae8d4d097e07f680f7951 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 18 Sep 2024 22:47:56 -0700 Subject: [PATCH 4/6] Apply suggestions from code review --- src/array_api_stubs/_draft/array_object.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_api_stubs/_draft/array_object.py b/src/array_api_stubs/_draft/array_object.py index a317270c7..807fbebb6 100644 --- a/src/array_api_stubs/_draft/array_object.py +++ b/src/array_api_stubs/_draft/array_object.py @@ -631,7 +631,7 @@ def __getitem__( an array containing the accessed value(s). The returned array must have the same data type as ``self``. .. note:: - When ``__getitem__`` is defined on an object, Python will automatically define iteration (i.e., the behavior from ``iter(x)``) as ``x[0]``, ``x[1]``, and so forth. This can also be implemented directly by defining ``__iter__``. Therefore, for one-dimensional arrays, iteration should produce the sequence ``x[0]``, ``x[1]``, ... of zero-dimensional arrays. Iteration behavior for arrays having more than one dimension is unspecified and thus implementation-defined. + When ``__getitem__`` is defined on an object, Python will automatically define iteration (i.e., the behavior from ``iter(x)``) as ``x[0]``, ``x[1]``, and so forth. This can also be implemented directly by defining ``__iter__``. Therefore, for one-dimensional arrays, iteration should produce a sequence of zero-dimensional arrays ``x[0]``, ``x[1]``, and so forth. Iteration behavior for arrays having more than one dimension is unspecified and thus implementation-defined. """ From 8727c76f08bca95abca6c79b8f682b5fb8ae4d6e Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 18 Sep 2024 22:50:52 -0700 Subject: [PATCH 5/6] Apply suggestions from code review --- src/array_api_stubs/_draft/array_object.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_api_stubs/_draft/array_object.py b/src/array_api_stubs/_draft/array_object.py index 807fbebb6..9664745c1 100644 --- a/src/array_api_stubs/_draft/array_object.py +++ b/src/array_api_stubs/_draft/array_object.py @@ -631,7 +631,7 @@ def __getitem__( an array containing the accessed value(s). The returned array must have the same data type as ``self``. .. note:: - When ``__getitem__`` is defined on an object, Python will automatically define iteration (i.e., the behavior from ``iter(x)``) as ``x[0]``, ``x[1]``, and so forth. This can also be implemented directly by defining ``__iter__``. Therefore, for one-dimensional arrays, iteration should produce a sequence of zero-dimensional arrays ``x[0]``, ``x[1]``, and so forth. Iteration behavior for arrays having more than one dimension is unspecified and thus implementation-defined. + When ``__getitem__`` is defined on an object, Python will automatically define iteration (i.e., the behavior from ``iter(x)``) as ``x[0]``, ``x[1]``, ..., ``x[N-1]``. This can also be implemented directly by defining ``__iter__``. Therefore, for a one-dimensional array ``x``, iteration should produce a sequence of zero-dimensional arrays ``x[0]``, ``x[1]``, ..., ``x[N-1]``, where ``N`` is the number of elements in the array. Iteration behavior for arrays having more than one dimension is unspecified and thus implementation-defined. """ From 4461c9d8466dad1c0b8cc04d78b1bee30cce2eda Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 30 Oct 2024 20:37:16 -0700 Subject: [PATCH 6/6] Apply suggestions from code review --- src/array_api_stubs/_draft/array_object.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_api_stubs/_draft/array_object.py b/src/array_api_stubs/_draft/array_object.py index 9664745c1..dcd1c53fa 100644 --- a/src/array_api_stubs/_draft/array_object.py +++ b/src/array_api_stubs/_draft/array_object.py @@ -631,7 +631,7 @@ def __getitem__( an array containing the accessed value(s). The returned array must have the same data type as ``self``. .. note:: - When ``__getitem__`` is defined on an object, Python will automatically define iteration (i.e., the behavior from ``iter(x)``) as ``x[0]``, ``x[1]``, ..., ``x[N-1]``. This can also be implemented directly by defining ``__iter__``. Therefore, for a one-dimensional array ``x``, iteration should produce a sequence of zero-dimensional arrays ``x[0]``, ``x[1]``, ..., ``x[N-1]``, where ``N`` is the number of elements in the array. Iteration behavior for arrays having more than one dimension is unspecified and thus implementation-defined. + When ``__getitem__`` is defined on an object, Python will automatically define iteration (i.e., the behavior from ``iter(x)``) as ``x[0]``, ``x[1]``, ..., ``x[N-1]``. This can also be implemented directly by defining ``__iter__``. Therefore, for a one-dimensional array ``x``, iteration should produce a sequence of zero-dimensional arrays ``x[0]``, ``x[1]``, ..., ``x[N-1]``, where ``N`` is the number of elements in the array. Iteration behavior for arrays having zero dimensions or more than one dimension is unspecified and thus implementation-defined. """