Skip to content

Commit f5169ad

Browse files
committed
Merge branch 'main' of https://github.com/data-apis/array-api into repeat
2 parents 23d0514 + 293512d commit f5169ad

34 files changed

+486
-46
lines changed

doc-requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
sphinx==4.3.0
1+
sphinx==6.2.1
22
sphinx-material==0.0.30
33
myst-parser
44
sphinx_markdown_tables
55
sphinx_copybutton
66
sphinx_favicon
7-
docutils<0.18
87
sphinx-math-dollar

spec/2021.12/assumptions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ of functions to be predictable from input dtypes only rather than input values.
2626

2727
The only dependency that's assumed in this standard is that on Python itself.
2828
Python >= 3.8 is assumed, motivated by the use of positional-only parameters
29-
(see [function and method signatures](API_specification/function_and_method_signatures.md)).
29+
(see [function and method signatures](API_specification/function_and_method_signatures.rst)).
3030

3131
Importantly, array libraries are not assumed to be aware of each other, or of
3232
a common array-specific layer. The [use cases](use_cases.md) do not require
@@ -39,7 +39,7 @@ for that is:
3939

4040
Array libraries may know how to interoperate with each other, for example by
4141
constructing their own array type from that of another library or by shared
42-
memory use of an array (see [Data interchange mechanisms](design_topics/data_interchange.md)).
42+
memory use of an array (see [Data interchange mechanisms](design_topics/data_interchange.rst)).
4343
This can be done without a dependency though - only adherence to a protocol is
4444
enough.
4545

spec/2021.12/purpose_and_scope.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ standard is shown in this diagram:
151151
_Rationale: this is an important topic for some array-consuming libraries,
152152
but there is no widely shared C/Cython API and hence it doesn't make sense at
153153
this point in time to standardize anything. See
154-
the [C API section](design_topics/C_API.md) for more details._
154+
the [C API section](design_topics/C_API.rst) for more details._
155155

156156
4. Standardization of these dtypes is out of scope: bfloat16, complex, extended
157157
precision floating point, datetime, string, object and void dtypes.

spec/2021.12/use_cases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ array implementation as a dependency.
5959

6060
It's clear that SciPy functionality that relies on compiled extensions (C,
6161
C++, Cython, Fortran) directly can't easily be run on another array library
62-
than NumPy (see [C API](design_topics/C_API.md) for more details about this topic). Pure Python
62+
than NumPy (see [C API](design_topics/C_API.rst) for more details about this topic). Pure Python
6363
code can work though. There's two main possibilities:
6464

6565
1. Testing with another package, manually or in CI, and simply provide a list

spec/2022.12/assumptions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ of functions to be predictable from input dtypes only rather than input values.
2626

2727
The only dependency that's assumed in this standard is that on Python itself.
2828
Python >= 3.8 is assumed, motivated by the use of positional-only parameters
29-
(see [function and method signatures](API_specification/function_and_method_signatures.md)).
29+
(see [function and method signatures](API_specification/function_and_method_signatures.rst)).
3030

3131
Importantly, array libraries are not assumed to be aware of each other, or of
3232
a common array-specific layer. The [use cases](use_cases.md) do not require
@@ -39,7 +39,7 @@ for that is:
3939

4040
Array libraries may know how to interoperate with each other, for example by
4141
constructing their own array type from that of another library or by shared
42-
memory use of an array (see [Data interchange mechanisms](design_topics/data_interchange.md)).
42+
memory use of an array (see [Data interchange mechanisms](design_topics/data_interchange.rst)).
4343
This can be done without a dependency though - only adherence to a protocol is
4444
enough.
4545

spec/2022.12/purpose_and_scope.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,22 @@ standard is shown in this diagram:
144144
_Rationale: execution is the domain of implementations. Attempting to specify
145145
execution behavior in a standard is likely to require much more fine-grained
146146
coordination between developers of implementations, and hence is likely to
147-
become an obstable to adoption._
147+
become an obstacle to adoption._
148148

149149
3. Non-Python API standardization (e.g., Cython or NumPy C APIs)
150150

151151
_Rationale: this is an important topic for some array-consuming libraries,
152152
but there is no widely shared C/Cython API and hence it doesn't make sense at
153153
this point in time to standardize anything. See
154-
the [C API section](design_topics/C_API.md) for more details._
154+
the [C API section](design_topics/C_API.rst) for more details._
155155

156-
4. Standardization of these dtypes is out of scope: bfloat16, complex, extended
156+
4. Standardization of these dtypes is out of scope: bfloat16, extended
157157
precision floating point, datetime, string, object and void dtypes.
158158

159159
_Rationale: these dtypes aren't uniformly supported, and their inclusion at
160160
this point in time could put a significant implementation burden on
161161
libraries. It is expected that some of these dtypes - in particular
162-
`bfloat16`, `complex64`, and `complex128` - will be included in a future
163-
version of the standard._
162+
`bfloat16` - will be included in a future version of the standard._
164163

165164
5. The following topics are out of scope: I/O, polynomials, error handling,
166165
testing routines, building and packaging related functionality, methods of

spec/2022.12/use_cases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ array implementation as a dependency.
5959

6060
It's clear that SciPy functionality that relies on compiled extensions (C,
6161
C++, Cython, Fortran) directly can't easily be run on another array library
62-
than NumPy (see [C API](design_topics/C_API.md) for more details about this topic). Pure Python
62+
than NumPy (see [C API](design_topics/C_API.rst) for more details about this topic). Pure Python
6363
code can work though. There's two main possibilities:
6464

6565
1. Testing with another package, manually or in CI, and simply provide a list

spec/draft/API_specification/array_object.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Array object
77

88
A conforming implementation of the array API standard must provide and support an array object having the following attributes and methods.
99

10-
Furthermore, a conforming implementation of the array API standard must support array objects of arbitrary rank ``N`` (i.e., number of dimensions), where ``N`` is greater than or equal to zero.
10+
Furthermore, a conforming implementation of the array API standard must support, at minimum, array objects of rank (i.e., number of dimensions) ``0``, ``1``, ``2``, ``3``, and ``4`` and must explicitly document their maximum supported rank ``N``.
1111

1212
.. note::
1313
Conforming implementations must support zero-dimensional arrays.

spec/draft/API_specification/elementwise_functions.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ Objects in API
3333
bitwise_right_shift
3434
bitwise_xor
3535
ceil
36+
clip
3637
conj
38+
copysign
3739
cos
3840
cosh
3941
divide
@@ -59,6 +61,8 @@ Objects in API
5961
logical_not
6062
logical_or
6163
logical_xor
64+
maximum
65+
minimum
6266
multiply
6367
negative
6468
not_equal
@@ -68,6 +72,7 @@ Objects in API
6872
remainder
6973
round
7074
sign
75+
signbit
7176
sin
7277
sinh
7378
square

spec/draft/API_specification/function_and_method_signatures.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Function and method signatures
55

66
Function signatures in this standard adhere to the following:
77

8-
1. Positional parameters must be `positional-only <https://www.python.org/dev/peps/pep-0570/>`_ parameters.
8+
1. Positional parameters should be `positional-only <https://www.python.org/dev/peps/pep-0570/>`_ parameters.
99
Positional-only parameters have no externally-usable name. When a function
1010
accepting positional-only parameters is called, positional arguments are
1111
mapped to these parameters based solely on their order.
@@ -20,7 +20,7 @@ Function signatures in this standard adhere to the following:
2020
namespace >= 3.8. Alternatively, they can add guidance to their users in the
2121
documentation to use the functions as if they were positional-only.
2222

23-
2. Optional parameters must be `keyword-only <https://www.python.org/dev/peps/pep-3102/>`_ arguments.
23+
2. Optional parameters should be `keyword-only <https://www.python.org/dev/peps/pep-3102/>`_ arguments.
2424

2525
*Rationale: this leads to more readable code, and it makes it easier to
2626
evolve an API over time by adding keywords without having to worry about
@@ -30,8 +30,8 @@ Function signatures in this standard adhere to the following:
3030
is called ``x``. For functions that have multiple array parameters, those
3131
parameters are called ``xi`` with ``i = 1, 2, ...`` (i.e., ``x1``, ``x2``).
3232

33-
4. Type annotations are left out of the signatures themselves for readability; however,
34-
they are added to individual parameter descriptions. For code which aims to
33+
4. Signatures include type annotations. The type annotations are also added to
34+
individual parameter and return value descriptions. For code which aims to
3535
adhere to the standard, adding type annotations is strongly recommended.
3636

3737
A function signature and description will look like:
@@ -57,3 +57,7 @@ A function signature and description will look like:
5757

5858

5959
Method signatures will follow the same conventions modulo the addition of ``self``.
60+
61+
Note that there are a few exceptions to rules (1) and (2), in cases where
62+
it enhances readability or use of the non-default form of the parameter in
63+
question is commonly used in code written for existing array libraries.

spec/draft/API_specification/indexing.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ Multi-dimensional arrays must extend the concept of single-axis indexing to mult
156156
.. note::
157157
Expanding dimensions can be equivalently achieved via repeated invocation of :func:`~array_api.expand_dims`.
158158

159+
.. note::
160+
The constant ``newaxis`` is an alias of ``None`` and can thus be used in a similar manner as ``None``.
161+
159162
- 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``.
160163

161164
.. note::

spec/draft/API_specification/manipulation_functions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ Objects in API
3030
roll
3131
squeeze
3232
stack
33+
tile
3334
unstack

spec/draft/API_specification/searching_functions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ Objects in API
2323
argmax
2424
argmin
2525
nonzero
26+
searchsorted
2627
where

spec/draft/API_specification/statistical_functions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Objects in API
1818
:toctree: generated
1919
:template: method.rst
2020

21+
cumulative_sum
2122
max
2223
mean
2324
min

spec/draft/assumptions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ of functions to be predictable from input dtypes only rather than input values.
2626

2727
The only dependency that's assumed in this standard is that on Python itself.
2828
Python >= 3.8 is assumed, motivated by the use of positional-only parameters
29-
(see [function and method signatures](API_specification/function_and_method_signatures.md)).
29+
(see [function and method signatures](API_specification/function_and_method_signatures.rst)).
3030

3131
Importantly, array libraries are not assumed to be aware of each other, or of
3232
a common array-specific layer. The [use cases](use_cases.md) do not require
@@ -39,7 +39,7 @@ for that is:
3939

4040
Array libraries may know how to interoperate with each other, for example by
4141
constructing their own array type from that of another library or by shared
42-
memory use of an array (see [Data interchange mechanisms](design_topics/data_interchange.md)).
42+
memory use of an array (see [Data interchange mechanisms](design_topics/data_interchange.rst)).
4343
This can be done without a dependency though - only adherence to a protocol is
4444
enough.
4545

spec/draft/design_topics/data_interchange.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,22 @@ page gives a high-level specification for data exchange in Python using DLPack.
8484
are recommended to do so using the same syntax and semantics as outlined
8585
below. They are not required to return an array object from ``from_dlpack``
8686
which conforms to this standard.
87+
88+
Non-supported use cases
89+
-----------------------
90+
91+
Use of DLPack requires that the data can be represented by a strided, in-memory
92+
layout on a single device. This covers usage by a large range of, but not all,
93+
known and possible array libraries. Use cases that are not supported by DLPack
94+
include:
95+
96+
- Distributed arrays, i.e., the data residing on multiple nodes or devices,
97+
- Sparse arrays, i.e., sparse representations where a data value (typically
98+
zero) is implicit.
99+
100+
There may be other reasons why it is not possible or desirable for an
101+
implementation to materialize the array as strided data in memory. In such
102+
cases, the implementation may raise a `BufferError` in the `__dlpack__` or
103+
`__dlpack_device__` method. In case an implementation is never able to export
104+
its array data via DLPack, it may omit `__dlpack__` and `__dlpack_device__`
105+
completely, and hence `from_dlpack` may raise an `AttributeError`.

spec/draft/design_topics/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Design topics & constraints
77

88
copies_views_and_mutation
99
data_dependent_output_shapes
10+
lazy_eager
1011
data_interchange
1112
device_support
1213
static_typing
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.. _lazy-eager:
2+
3+
Lazy vs. eager execution
4+
========================
5+
6+
While the execution model for implementations is out of scope of this standard,
7+
there are a few aspects of lazy (or graph-based) execution as contrasted to
8+
eager execution that may have an impact on the prescribed semantics of
9+
individual APIs, and will therefore show up in the API specification.
10+
11+
One important difference is data-dependent or value-dependent behavior, as
12+
described in :ref:`data-dependent-output-shapes`. Because such behavior is hard
13+
to implement, implementers may choose to omit such APIs from their library.
14+
15+
Another difference is when the Python language itself prescribes that a
16+
specific type *must* be returned. For those cases, it is not possible to return
17+
a lazy/delayed kind of object to avoid computing a value. This is the case for
18+
five dunder methods: `__bool__`, `__int__`, `__float__`, `__complex__` and
19+
`__index__`. Each implementation has only two choices when one of these methods
20+
is called:
21+
22+
1. Compute a value of the required type (a Python scalar of type `bool`, `int`,
23+
`float` or `complex`), or
24+
2. Raise an exception.
25+
26+
When an implementation is 100% lazy, for example when it serializes a
27+
computation graph, computing the value is not possible and hence such an
28+
implementation has no choice but to raise an exception. For a "mostly lazy"
29+
implementation, it may make sense to trigger execution instead - but it is not
30+
required to, both choices are valid.
31+
32+
A common code construct where this happens is conditional logic, e.g.::
33+
34+
vals = compute_something()
35+
if all(vals):
36+
# The if-statement will make Python call the __bool__ method
37+
# on the result of `all(vals)`.
38+
do_something_else()
39+
40+
Note that the API does not contain control flow constructs, as of now, that
41+
would allow avoiding the implicit `__bool__` call in the example above. The
42+
only control flow-like function is `where`, but there's no function like `cond`
43+
to replace an `if`-statement.

spec/draft/extensions/index.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ the implementer, e.g. via a regular submodule that is imported under the
2424
The functions in an extension must adhere to the same conventions as those in
2525
the array API standard. See :ref:`api-specification`.
2626

27-
28-
Extensions
29-
----------
27+
------------------------------------------------------------------------------
3028

3129
.. toctree::
30+
:caption: Extension modules:
3231
:maxdepth: 1
3332

3433
fourier_transform_functions

spec/draft/purpose_and_scope.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,22 @@ standard is shown in this diagram:
144144
_Rationale: execution is the domain of implementations. Attempting to specify
145145
execution behavior in a standard is likely to require much more fine-grained
146146
coordination between developers of implementations, and hence is likely to
147-
become an obstable to adoption._
147+
become an obstacle to adoption._
148148

149149
3. Non-Python API standardization (e.g., Cython or NumPy C APIs)
150150

151151
_Rationale: this is an important topic for some array-consuming libraries,
152152
but there is no widely shared C/Cython API and hence it doesn't make sense at
153153
this point in time to standardize anything. See
154-
the [C API section](design_topics/C_API.md) for more details._
154+
the [C API section](design_topics/C_API.rst) for more details._
155155

156-
4. Standardization of these dtypes is out of scope: bfloat16, complex, extended
156+
4. Standardization of these dtypes is out of scope: bfloat16, extended
157157
precision floating point, datetime, string, object and void dtypes.
158158

159159
_Rationale: these dtypes aren't uniformly supported, and their inclusion at
160160
this point in time could put a significant implementation burden on
161161
libraries. It is expected that some of these dtypes - in particular
162-
`bfloat16`, `complex64`, and `complex128` - will be included in a future
163-
version of the standard._
162+
`bfloat16` - will be included in a future version of the standard._
164163

165164
5. The following topics are out of scope: I/O, polynomials, error handling,
166165
testing routines, building and packaging related functionality, methods of

spec/draft/use_cases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ array implementation as a dependency.
5959

6060
It's clear that SciPy functionality that relies on compiled extensions (C,
6161
C++, Cython, Fortran) directly can't easily be run on another array library
62-
than NumPy (see [C API](design_topics/C_API.md) for more details about this topic). Pure Python
62+
than NumPy (see [C API](design_topics/C_API.rst) for more details about this topic). Pure Python
6363
code can work though. There's two main possibilities:
6464

6565
1. Testing with another package, manually or in CI, and simply provide a list

src/_array_api_conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@
5252
nitpick_ignore = [
5353
("py:class", "collections.abc.Sequence"),
5454
("py:class", "Optional[Union[int, float, Literal[inf, - inf, 'fro', 'nuc']]]"),
55+
("py:class", "int | float | ~typing.Literal[inf, -inf, 'fro', 'nuc'] | None"),
5556
("py:class", "Union[int, float, Literal[inf, - inf]]"),
5657
(
5758
"py:obj",
5859
"typing.Optional[typing.Union[int, float, typing.Literal[inf, - inf, 'fro', 'nuc']]]",
5960
),
6061
("py:obj", "typing.Union[int, float, typing.Literal[inf, - inf]]"),
62+
("py:class", "int | float | ~typing.Literal[inf, -inf]"),
6163
("py:class", "enum.Enum"),
6264
("py:class", "ellipsis"),
6365
]

src/array_api_stubs/_2021_12/array_object.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,12 @@ def __ge__(self: array, other: Union[int, float, array], /) -> array:
453453
def __getitem__(
454454
self: array,
455455
key: Union[
456-
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array
456+
int,
457+
slice,
458+
ellipsis,
459+
None,
460+
Tuple[Union[int, slice, ellipsis, None], ...],
461+
array,
457462
],
458463
/,
459464
) -> array:
@@ -464,7 +469,7 @@ def __getitem__(
464469
----------
465470
self: array
466471
array instance.
467-
key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array]
472+
key: Union[int, slice, ellipsis, None, Tuple[Union[int, slice, ellipsis, None], ...], array]
468473
index key.
469474
470475
Returns

0 commit comments

Comments
 (0)