Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add array indexing specification #46

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 27 commits into from
Nov 8, 2020
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Add notes
  • Loading branch information
kgryte committed Sep 20, 2020
commit ded8acdec9a880b90847033fb14ea13e19e7816c
13 changes: 12 additions & 1 deletion spec/API_specification/indexing.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ A conforming implementation of the array API standard must adhere to the followi

To index a single array axis, an array must support standard Python indexing rules. Let `n` be the axis (dimension) size.

- Indices must be Python integers (i.e., `int`).
- An valid index must be an object satisfying [`operator.index`](https://www.python.org/dev/peps/pep-0357/) (e.g., `int`).

- Nonnegative indices must start at `0` (i.e., zero-based indexing).

- Valid nonnegative indices must reside on the half-open interval `[0, n)`.

.. note::

This specification does not explicitly require bounds checking. The behavior for out-of-bounds integer indices is left unspecified.

- Negative indices must count backward from the last array index, starting from `-1` (i.e., negative-one-based indexing, where `-1` refers to the last array index).

.. note::
Expand All @@ -24,6 +28,10 @@ To index a single array axis, an array must support standard Python indexing rul

- Valid negative indices must reside on the closed interval `[-n, -1]`.

.. note::

This specification does not explicitly require bounds checking. The behavior for out-of-bounds integer indices is left unspecified.

- A negative index `j` is related to a zero-based nonnegative index `i` via `i = n+j`.

- Colons `:` must be used for [slices](https://docs.python.org/3/library/functions.html?highlight=slice#slice): `start:stop:step`, where `start` is inclusive and `stop` is exclusive.
Expand Down Expand Up @@ -109,3 +117,6 @@ Multi-dimensional arrays must extend the concept of single-axis indexing to mult
- If the number of provided single-axis indexing expressions is less than `N`, then `:` must be assumed for the remaining dimensions (e.g., if `A` has rank `2`, `A[2:10] == A[2:10, :]`).

- 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 exception must be raised if more than one ellipsis is provided.

## Boolean Array Indexing