Skip to content

Commit 421216e

Browse files
committed
Merge branch 'main' into add-fft-extension
2 parents 0efc3a3 + f69dd9a commit 421216e

16 files changed

+185
-55
lines changed

.circleci/config.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: 2
2+
3+
# Aliases to reuse
4+
_defaults: &defaults
5+
docker:
6+
# CircleCI maintains a library of pre-built images
7+
# documented at https://circleci.com/docs/2.0/circleci-images/
8+
- image: circleci/python:3.7.0
9+
working_directory: ~/repo
10+
11+
jobs:
12+
build_page:
13+
<<: *defaults
14+
steps:
15+
- checkout
16+
- attach_workspace:
17+
at: ~/
18+
- run:
19+
name: build docs
20+
no_output_timeout: 25m
21+
command: |
22+
sudo pip install -r requirements.txt
23+
sphinx-build -b html -WT --keep-going spec build/latest -d doctrees
24+
- store_artifacts:
25+
path: build/latest
26+
27+
workflows:
28+
version: 2
29+
default:
30+
jobs:
31+
- build_page

.github/workflows/preview.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
on: [status]
2+
jobs:
3+
circleci_artifacts_redirector_job:
4+
runs-on: ubuntu-latest
5+
name: Run CircleCI artifacts redirector
6+
steps:
7+
- name: GitHub Action step
8+
id: step1
9+
uses: larsoner/circleci-artifacts-redirector-action@master
10+
with:
11+
repo-token: ${{ secrets.GITHUB_TOKEN }}
12+
artifact-path: 0/build/latest/index.html
13+
circleci-jobs: build_page
14+
job-title: Check the rendered docs here!
15+
- name: Array API preview
16+
run: |
17+
curl --fail ${{ steps.step1.outputs.url }} | grep $GITHUB_SHA

spec/API_specification/array_object.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ Evaluates `self_i << other_i` for each element of an array instance with the res
737737

738738
```{note}
739739
740-
Element-wise results must equal the results returned by the equivalent element-wise function [`less_equal(x1, x2)`](elementwise_functions.md#bitwise_left_shiftx1-x2-).
740+
Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_left_shift(x1, x2)`](elementwise_functions.md#bitwise_left_shiftx1-x2-).
741741
```
742742

743743
(method-__lt__)=
@@ -1062,7 +1062,30 @@ Element-wise results must equal the results returned by the equivalent element-w
10621062
(method-__setitem__)=
10631063
### \_\_setitem\_\_(self, key, value, /)
10641064

1065-
_TODO: dependent on the indexing specification._
1065+
Sets `self[key]` to `value`.
1066+
1067+
#### Parameters
1068+
1069+
- **self**: _&lt;array;&gt;_
1070+
1071+
- array instance.
1072+
1073+
- **key**: _Union\[ int, slice, ellipsis, Tuple\[ Union\[ int, slice, ellipsis ], ... ], &lt;array&gt; ]_
1074+
1075+
- index key.
1076+
1077+
- **value**: _Union\[ int, float, bool, &lt;array&gt; ]_
1078+
1079+
- value(s) to set. Must be compatible with `self[key]` (see {ref}`broadcasting`).
1080+
1081+
```{note}
1082+
1083+
Setting array values must not affect the data type of `self`.
1084+
1085+
When `value` is a Python scalar (i.e., `int`, `float`, `bool`), behavior must follow specification guidance on mixing arrays with Python scalars (see {ref}`type-promotion`).
1086+
1087+
When `value` is an `array` of a different data type than `self`, how values are cast to the data type of `self` is implementation defined.
1088+
```
10661089

10671090
(method-__sub__)=
10681091
### \_\_sub\_\_(self, other, /)

spec/API_specification/data_type_functions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Machine limits for floating-point data types.
9595
- largest representable number.
9696
- **min**: _float_
9797
- smallest representable number.
98+
- **smallest_normal**: _float_
99+
- smallest positive floating-point number with full precision.
98100

99101
(function-iinfo)=
100102
### iinfo(type, /)

spec/API_specification/data_types.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
77
A conforming implementation of the array API standard must provide and support the following data types.
88

9-
A conforming implementation of the array API standard must define a default floating-point data type (either `float32` or `float64`), as well as a default integer data type (`int32` or `int64`). These default data types must be the same across platforms. The default integer data type may vary depending on whether Python is 32-bit or 64-bit.
10-
11-
```{note}
12-
The default floating-point and array index integer data types should be clearly defined in a conforming library's documentation.
13-
```
14-
15-
169
## bool
1710

1811
Boolean (`True` or `False`).
@@ -60,8 +53,9 @@ IEEE 754 double-precision (64-bit) binary floating-point number (see IEEE 754-20
6053

6154
:::{admonition} Future extension
6255
:class: hint
63-
It is expected that in the next version of this standard, `complex64` and `complex128`
64-
dtypes will be added, with these casting rules (will be added to {ref}`type-promotion`):
56+
`complex64` and `complex128` dtypes are expected to be included in the next
57+
version of this standard and to have the following casting rules (will be added
58+
to {ref}`type-promotion`):
6559

6660
![Type promotion diagram for complex dtypes in next version](/_static/images/dtype_promotion_complex.png)
6761

@@ -78,13 +72,33 @@ Implementations may provide other ways to specify data types (e.g.,
7872
A conforming implementation of the array API standard may provide and support additional data types beyond those described in this specification.
7973
```
8074

75+
(data-type-defaults)=
76+
## Default Data Types
77+
78+
A conforming implementation of the array API standard must define a default floating-point data type (either `float32` or `float64`) and a default integer data type (`int32` or `int64`).
79+
80+
The default data types must be the same across platforms.
81+
82+
The default integer data type may vary depending on whether Python is 32-bit or 64-bit.
83+
84+
```{note}
85+
The default floating-point and integer data types should be clearly defined in a conforming library's documentation.
86+
```
87+
8188
(data-type-categories)=
8289
## Data Type Categories
8390

84-
For the purposes of this specification, the following data type categories are defined.
85-
Libraries do not need to organize dtypes according to these categories. These
86-
are only for organizing the functions in this specification itself. Future versions of
87-
the specification will include additional categories for complex data types.
91+
For the purpose of organizing functions within this specification, the following data type categories are defined.
92+
93+
```{note}
94+
Conforming libraries are not required to organize dtypes according to these categories. These
95+
categories are only intended for use within this specification.
96+
```
97+
98+
```{note}
99+
Future versions of the specification will include additional categories for
100+
complex data types.
101+
```
88102

89103
### Numeric Data Types
90104

spec/API_specification/elementwise_functions.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ Shifts the bits of each element `x1_i` of the input array `x1` to the left by ap
352352

353353
- **out**: _&lt;array&gt;_
354354

355-
- an array containing the element-wise results. The returned array must have the same data type as `x1`.
355+
- an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
356356

357357
(function-bitwise_invert)=
358358
### bitwise_invert(x, /)
@@ -397,6 +397,11 @@ Computes the bitwise OR of the underlying binary representation of each element
397397

398398
Shifts the bits of each element `x1_i` of the input array `x1` to the right according to the respective element `x2_i` of the input array `x2`.
399399

400+
```{note}
401+
402+
This operation must be an arithmetic shift (i.e., sign-propagating) and thus equivalent to floor division by a power of two.
403+
```
404+
400405
#### Parameters
401406

402407
- **x1**: _&lt;array&gt;_
@@ -411,7 +416,7 @@ Shifts the bits of each element `x1_i` of the input array `x1` to the right acco
411416

412417
- **out**: _&lt;array&gt;_
413418

414-
- an array containing the element-wise results. The returned array must have the same data type as `x1`.
419+
- an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
415420

416421
(function-bitwise_xor)=
417422
### bitwise_xor(x1, x2, /)
@@ -939,8 +944,9 @@ each element `x1_i` of the input array `x1` with the respective element `x2_i` o
939944

940945
For floating-point operands,
941946

942-
- If either `x1_i` or `x2_i` is `NaN`, the result is `NaN`.
943-
- If either `x1_i` or `x2_i` is `+infinity`, the result is `+infinity`.
947+
- If either `x1_i` or `x2_i` is `NaN`, the result is `NaN`.
948+
- If `x1_i` is `+infinity` and `x2_i` is not `NaN`, the result is `+infinity`.
949+
- If `x1_i` is not `NaN` and `x2_i` is `+infinity`, the result is `+infinity`.
944950

945951
#### Parameters
946952

spec/API_specification/indexing.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ _Rationale: this is consistent with bounds-checking for single-axis indexing. An
160160

161161
## Boolean Array Indexing
162162

163+
:::{admonition} Data-dependent output shape
164+
:class: important
165+
166+
For common boolean array use cases (e.g., using a dynamically-sized boolean array mask to filter the values of another array), the shape of the output array is data-dependent; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) may find boolean array indexing difficult to implement. Accordingly, such libraries may choose to omit boolean array indexing. See {ref}`data-dependent-output-shapes` section for more details.
167+
:::
168+
163169
An array must support indexing where the **sole index** is an `M`-dimensional boolean array `B` with shape `S1 = (s1, ..., sM)` according to the following rules. Let `A` be an `N`-dimensional array with shape `S2 = (s1, ..., sM, ..., sN)`.
164170

165171
- If `N >= M`, then `A[B]` must replace the first `M` dimensions of `A` with a single dimension having a size equal to the number of `True` elements in `B`. The values in the resulting array must be in row-major (C-style order); this is equivalent to `A[nonzero(B)]`.

spec/API_specification/searching_functions.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ Returns the indices of the minimum values along a specified axis. When the minim
6969
(function-nonzero)=
7070
### nonzero(x, /)
7171

72+
:::{admonition} Data-dependent output shape
73+
:class: important
74+
75+
The shape of the output array for this function depends on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) may find this function difficult to implement without knowing array values. Accordingly, such libraries may choose to omit this function. See {ref}`data-dependent-output-shapes` section for more details.
76+
:::
77+
7278
Returns the indices of the array elements which are non-zero.
7379

7480
#### Parameters

spec/API_specification/set_functions.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ A conforming implementation of the array API standard must provide and support t
1515
(function-unique)=
1616
### unique(x, /, *, return_counts=False, return_index=False, return_inverse=False)
1717

18+
:::{admonition} Data-dependent output shape
19+
:class: important
20+
21+
The shapes of one or more of output arrays for this function depend on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) may find this function difficult to implement without knowing array values. Accordingly, such libraries may choose to omit this function. See {ref}`data-dependent-output-shapes` section for more details.
22+
:::
23+
1824
Returns the unique elements of an input array `x`.
1925

2026
#### Parameters
@@ -59,6 +65,4 @@ Returns the unique elements of an input array `x`.
5965
6066
- **counts**: _&lt;array&gt;_
6167
62-
- an array containing the number of times each unique element occurs in `x`.
63-
64-
_TODO: should this be `int64`? This probably makes sense for most hardware; however, may be undesirable for older hardware and/or embedded systems._
68+
- an array containing the number of times each unique element occurs in `x`. The returned array must have the default integer data type.

spec/API_specification/type_promotion.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ where
7070
| **i1** | i2 | i4 | i8 |
7171
| **i2** | i2 | i4 | i8 |
7272
| **i4** | i4 | i4 | i8 |
73+
| **i8** | i8 | i8 | i8 |
7374

7475
### Floating-point type promotion table
7576

@@ -108,6 +109,7 @@ a compatible type and value to the array dtype:
108109
- Python `bool` for a `bool` array dtype,
109110
- a Python `int` within the [bounds](data-types) of the given dtype for integer array dtypes,
110111
- a Python `int` or `float` for floating-point array dtypes
112+
111113
The expected behavior is then equivalent to:
112114

113115
1. Convert the scalar to a 0-D array with the same dtype as that of the array
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(data-dependent-output-shapes)=
2+
3+
# Data-dependent output shapes
4+
5+
Array libraries which build computation graphs commonly employ static analysis that relies upon known shapes. For example, JAX requires known array sizes when compiling code, in order to perform static memory allocation. Functions and operations which are value-dependent present difficulties for such libraries, as array sizes cannot be inferred ahead of time without also knowing the contents of the respective arrays.
6+
7+
While value-dependent functions and operations are not impossible to implement for array libraries which build computation graphs, this specification does not want to impose an undue burden on such libraries and permits omission of value-dependent operations. All other array libraries are expected, however, to implement the value-dependent operations included in this specification in order to be array specification compliant.
8+
9+
Value-dependent operations are demarcated in this specification using an admonition similar to the following:
10+
11+
:::{admonition} Data-dependent output shape
12+
:class: important
13+
14+
The shape of the output array for this function/operation depends on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) may find this function/operation difficult to implement without knowing array values. Accordingly, such libraries may choose to omit this function. See {ref}`data-dependent-output-shapes` section for more details.
15+
:::

spec/design_topics/data_interchange.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,28 @@ The interchange mechanism must offer the following:
1212

1313
1. Data access via a protocol that describes the memory layout of the array
1414
in an implementation-independent manner.
15+
1516
_Rationale: any number of libraries must be able to exchange data, and no
1617
particular package must be needed to do so._
18+
1719
2. Support for all dtypes in this API standard (see {ref}`data-types`).
20+
1821
3. Device support. It must be possible to determine on what device the array
1922
that is to be converted lives.
23+
2024
_Rationale: there are CPU-only, GPU-only, and multi-device array types;
2125
it's best to support these with a single protocol (with separate
2226
per-device protocols it's hard to figure out unambiguous rules for which
2327
protocol gets used, and the situation will get more complex over time
2428
as TPU's and other accelerators become more widely available)._
29+
2530
4. Zero-copy semantics where possible, making a copy only if needed (e.g.
2631
when data is not contiguous in memory).
32+
2733
_Rationale: performance._
34+
2835
5. A Python-side and a C-side interface, the latter with a stable C ABI.
36+
2937
_Rationale: all prominent existing array libraries are implemented in
3038
C/C++, and are released independently from each other. Hence a stable C
3139
ABI is required for packages to work well together._

spec/design_topics/index.rst

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

88
copies_views_and_mutation
9+
data_dependent_output_shapes
910
data_interchange
1011
device_support
1112
static_typing

0 commit comments

Comments
 (0)