You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spec/API_specification/creation_functions.md
+5-2Lines changed: 5 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,8 @@ A conforming implementation of the array API standard must provide and support t
7
7
- Positional parameters must be [positional-only](https://www.python.org/dev/peps/pep-0570/) parameters. Positional-only parameters have no externally-usable name. When a function accepting positional-only parameters is called, positional arguments are mapped to these parameters based solely on their order.
8
8
- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
9
9
10
+
## Objects in API
11
+
10
12
<!-- NOTE: please keep the functions in alphabetical order -->
@@ -23,9 +25,10 @@ Returns evenly spaced values within the half-open interval `[start, stop)` as a
23
25
24
26
- the end of the interval. Default: `None`.
25
27
26
-
.. note::
28
+
```{note}
27
29
28
-
This function cannot guarantee that the interval does not include the `stop` value in those cases where `step` is not an integer and floating-point rounding errors affect the length of the output array.
30
+
This function cannot guarantee that the interval does not include the `stop` value in those cases where `step` is not an integer and floating-point rounding errors affect the length of the output array.
Copy file name to clipboardExpand all lines: spec/API_specification/data_types.md
+14-10Lines changed: 14 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,33 +1,37 @@
1
-
.. _data-types:
1
+
(data-types)=
2
2
3
3
# Data Types
4
4
5
5
> Array API specification for supported data types.
6
6
7
7
A conforming implementation of the array API standard must provide and support the following data types.
8
8
9
-
.. note::
9
+
```{note}
10
10
11
-
Data types ("dtypes") are objects that can be used as `dtype` specifiers in functions and methods (e.g., `zeros((2, 3), dtype=float32)`). A conforming implementation may add methods or attributes to data type objects; however, these methods and attributes are not included in this specification.
11
+
Data types ("dtypes") are objects that can be used as `dtype` specifiers in functions and methods (e.g., `zeros((2, 3), dtype=float32)`). A conforming implementation may add methods or attributes to data type objects; however, these methods and attributes are not included in this specification.
12
+
```
12
13
13
-
.. note::
14
+
```{note}
14
15
15
-
Implementations may provide other ways to specify data types (e.g.,
16
-
`zeros((2, 3), dtype='f4')`); however, these are not included in this specification.
16
+
Implementations may provide other ways to specify data types (e.g.,
17
+
`zeros((2, 3), dtype='f4')`); however, these are not included in this specification.
18
+
```
17
19
18
20
A conforming implementation of the array API standard may provide and support additional data types beyond those described in this specification.
19
21
20
22
A conforming implementation of the array API standard must define a default floating-point data type (either `float32` or `float64`).
21
23
22
-
.. note::
24
+
```{note}
23
25
24
-
The default floating-point data type should be clearly defined in a conforming library's documentation.
26
+
The default floating-point data type should be clearly defined in a conforming library's documentation.
27
+
```
25
28
26
29
A conforming implementation of the array API standard must define a default data type for an array index (either `int32` or `int64`).
27
30
28
-
.. note::
31
+
```{note}
29
32
30
-
The default array index data type should be clearly defined in a conforming library's documentation.
33
+
The default array index data type should be clearly defined in a conforming library's documentation.
Copy file name to clipboardExpand all lines: spec/API_specification/indexing.md
+37-26Lines changed: 37 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
.. _indexing:
1
+
(indexing)=
2
2
3
3
# Indexing
4
4
@@ -16,21 +16,24 @@ To index a single array axis, an array must support standard Python indexing rul
16
16
17
17
-**Valid** nonnegative indices must reside on the half-open interval `[0, n)`.
18
18
19
-
.. note::
19
+
```{note}
20
20
21
-
This specification does not require bounds checking. The behavior for out-of-bounds integer indices is left unspecified.
21
+
This specification does not require bounds checking. The behavior for out-of-bounds integer indices is left unspecified.
22
+
```
22
23
23
24
- 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).
24
25
25
-
.. note::
26
+
```{note}
26
27
27
-
A negative index `j` is equivalent to `n-j`; the former is syntactic sugar for the latter, providing a shorthand for indexing elements that would otherwise need to be specified in terms of the axis (dimension) size.
28
+
A negative index `j` is equivalent to `n-j`; the former is syntactic sugar for the latter, providing a shorthand for indexing elements that would otherwise need to be specified in terms of the axis (dimension) size.
29
+
```
28
30
29
31
- **Valid** negative indices must reside on the closed interval `[-n, -1]`.
30
32
31
-
.. note::
33
+
```{note}
32
34
33
-
This specification does not require bounds checking. The behavior for out-of-bounds integer indices is left unspecified.
35
+
This specification does not require bounds checking. The behavior for out-of-bounds integer indices is left unspecified.
36
+
```
34
37
35
38
- A negative index `j` is related to a zero-based nonnegative index `i` via `i = n+j`.
36
39
@@ -56,9 +59,10 @@ A[i::k]
56
59
A[i:j:k]
57
60
```
58
61
59
-
.. note::
62
+
```{note}
60
63
61
-
Slice syntax can be equivalently achieved using the Python built-in [`slice()`](https://docs.python.org/3/library/functions.html#slice) API. From the perspective from `A`, the behavior of `A[i:j:k]` and `A[slice(i, j, k)]` is indistinguishable (i.e., both retrieve the same set of items from `__getitem__`).
64
+
Slice syntax can be equivalently achieved using the Python built-in [`slice()`](https://docs.python.org/3/library/functions.html#slice) API. From the perspective from `A`, the behavior of `A[i:j:k]` and `A[slice(i, j, k)]` is indistinguishable (i.e., both retrieve the same set of items from `__getitem__`).
65
+
```
62
66
63
67
Using a slice to index a single array axis must select `m` elements with index values
64
68
@@ -84,13 +88,15 @@ such that
84
88
j > i + (m-1)k
85
89
```
86
90
87
-
.. note::
91
+
```{note}
88
92
89
-
For `i` on the interval `[0, n)` (where `n` is the axis size), `j` on the interval `(0, n]`, `i` less than `j`, and positive step `k`, a starting index `i` is **always** included, while the stopping index `j` is **always** excluded. This preserves `x[:i]+x[i:]` always being equal to `x`.
93
+
For `i` on the interval `[0, n)` (where `n` is the axis size), `j` on the interval `(0, n]`, `i` less than `j`, and positive step `k`, a starting index `i` is **always** included, while the stopping index `j` is **always** excluded. This preserves `x[:i]+x[i:]` always being equal to `x`.
94
+
```
90
95
91
-
.. note::
96
+
```{note}
92
97
93
-
Using a slice to index into a single array axis should select the same elements as using a slice to index a Python list of the same size.
98
+
Using a slice to index into a single array axis should select the same elements as using a slice to index a Python list of the same size.
99
+
```
94
100
95
101
Slice syntax must have the following defaults. Let `n` be the axis (dimension) size.
96
102
@@ -106,27 +112,30 @@ Using a slice to index a single array axis must adhere to the following rules. L
106
112
107
113
- Indexing via `:` and `::` must be equivalent and have defaults derived from the rules above. Both `:` and `::` indicate to select all elements along a single axis (dimension).
108
114
109
-
.. note::
115
+
```{note}
110
116
111
-
This specification does not require "clipping" out-of-bounds indices (i.e., requiring the starting and stopping indices `i` and `j` be bound by `0` and `n`, respectively).
117
+
This specification does not require "clipping" out-of-bounds indices (i.e., requiring the starting and stopping indices `i` and `j` be bound by `0` and `n`, respectively).
112
118
113
-
_Rationale: this is consistent with bounds checking for integer indexing; the behavior of out-of-bounds indices is left unspecified. Implementations may choose to clip, raise an exception, return junk values, or some other behavior depending on device requirements and performance considerations._
119
+
_Rationale: this is consistent with bounds checking for integer indexing; the behavior of out-of-bounds indices is left unspecified. Implementations may choose to clip, raise an exception, return junk values, or some other behavior depending on device requirements and performance considerations._
120
+
```
114
121
115
-
.. note::
122
+
```{note}
116
123
117
-
This specification leaves unspecified the behavior of indexing a single array axis with an out-of-bounds slice (i.e., a slice which does not select any array axis elements).
124
+
This specification leaves unspecified the behavior of indexing a single array axis with an out-of-bounds slice (i.e., a slice which does not select any array axis elements).
118
125
119
-
_Rationale: this is consistent with bounds checking for integer indexing; the behavior of out-of-bounds indices is left unspecified. Implementations may choose to return an empty array (whose axis (dimension) size along the indexed axis is `0`), raise an exception, or some other behavior depending on device requirements and performance considerations._
126
+
_Rationale: this is consistent with bounds checking for integer indexing; the behavior of out-of-bounds indices is left unspecified. Implementations may choose to return an empty array (whose axis (dimension) size along the indexed axis is `0`), raise an exception, or some other behavior depending on device requirements and performance considerations._
127
+
```
120
128
121
129
## Multi-axis Indexing
122
130
123
131
Multi-dimensional arrays must extend the concept of single-axis indexing to multiple axes by applying single-axis indexing rules along each axis (dimension) and supporting the following additional rules. Let `N` be the number of dimensions ("rank") of a multi-dimensional array `A`.
124
132
125
133
- Each axis may be independently indexed via single-axis indexing by providing a comma-separated sequence ("selection tuple") of single-axis indexing expressions (e.g., `A[:, 2:10, :, 5]`).
126
134
127
-
.. note::
135
+
```{note}
128
136
129
-
In Python, `x[(exp1, exp2, ..., expN)]` is equivalent to `x[exp1, exp2, ..., expN]`; the latter is syntactic sugar for the former.
137
+
In Python, `x[(exp1, exp2, ..., expN)]` is equivalent to `x[exp1, exp2, ..., expN]`; the latter is syntactic sugar for the former.
138
+
```
130
139
131
140
- Providing a single nonnegative integer `i` as a single-axis index must index the same elements as the slice `i:i+1`.
132
141
@@ -144,21 +153,23 @@ Multi-dimensional arrays must extend the concept of single-axis indexing to mult
144
153
145
154
- The result of multi-axis indexing must be an array of the same data type as the indexed array.
146
155
147
-
.. note::
156
+
```{note}
148
157
149
-
This specification leaves unspecified the behavior of providing a slice which attempts to select elements along a particular axis, but whose starting index is out-of-bounds.
158
+
This specification leaves unspecified the behavior of providing a slice which attempts to select elements along a particular axis, but whose starting index is out-of-bounds.
150
159
151
-
_Rationale: this is consistent with bounds-checking for single-axis indexing. An implementation may choose to set the axis (dimension) size of the result array to `0`, raise an exception, return junk values, or some other behavior depending on device requirements and performance considerations._
160
+
_Rationale: this is consistent with bounds-checking for single-axis indexing. An implementation may choose to set the axis (dimension) size of the result array to `0`, raise an exception, return junk values, or some other behavior depending on device requirements and performance considerations._
161
+
```
152
162
153
163
## Boolean Array Indexing
154
164
155
165
An array must support indexing via a **single**`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)`.
156
166
157
167
- 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)]`.
158
168
159
-
.. note::
169
+
```{note}
160
170
161
-
For example, if `N == M == 2`, indexing `A` via a boolean array `B` will return a one-dimensional array whose size is equal to the number of `True` elements in `B`.
171
+
For example, if `N == M == 2`, indexing `A` via a boolean array `B` will return a one-dimensional array whose size is equal to the number of `True` elements in `B`.
172
+
```
162
173
163
174
- If `N < M`, then an `IndexError` exception must be raised.
Copy file name to clipboardExpand all lines: spec/API_specification/linear_algebra_functions.md
+9-7Lines changed: 9 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,13 @@ A conforming implementation of the array API standard must provide and support t
6
6
7
7
- Positional parameters must be [positional-only](https://www.python.org/dev/peps/pep-0570/) parameters. Positional-only parameters have no externally-usable name. When a function accepting positional-only parameters is called, positional arguments are mapped to these parameters based solely on their order.
8
8
- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
9
-
- Broadcasting semantics must follow the semantics defined in :ref:`broadcasting`.
10
-
- Unless stated otherwise, functions must support the data types defined in :ref:`data-types`.
11
-
- Unless stated otherwise, functions must adhere to the type promotion rules defined in :ref:`type-promotion`.
9
+
- Broadcasting semantics must follow the semantics defined in {ref}`broadcasting`.
10
+
- Unless stated otherwise, functions must support the data types defined in {ref}`data-types`.
11
+
- Unless stated otherwise, functions must adhere to the type promotion rules defined in {ref}`type-promotion`.
12
12
- Unless stated otherwise, floating-point operations must adhere to IEEE 754-2019.
13
13
14
+
## Objects in API
15
+
14
16
<!-- NOTE: please keep the functions in alphabetical order -->
@@ -39,7 +41,7 @@ Returns the cross product of 3-element vectors. If `x1` and `x2` are multi-dimen
39
41
40
42
-**out**: _<array>_
41
43
42
-
- an array containing the cross products. The returned array must have a data type determined by :ref:`type-promotion` rules.
44
+
- an array containing the cross products. The returned array must have a data type determined by {ref}`type-promotion` rules.
43
45
44
46
### <aname="det"href="#det">#</a> det(x, /)
45
47
@@ -55,7 +57,7 @@ Returns the determinant of a square matrix (or stack of square matrices) `x`.
55
57
56
58
-**out**: _<array>_
57
59
58
-
- if `x` is a two-dimensional array, a zero-dimensional array containing the determinant; otherwise, a non-zero dimensional array containing the determinant for each square matrix. The returned array must have a data type determined by :ref:`type-promotion` rules.
60
+
- if `x` is a two-dimensional array, a zero-dimensional array containing the determinant; otherwise, a non-zero dimensional array containing the determinant for each square matrix. The returned array must have a data type determined by {ref}`type-promotion` rules.
@@ -165,7 +167,7 @@ Computes the matrix or vector norm of `x`.
165
167
166
168
-**keepdims**: _bool_
167
169
168
-
- If `True`, the axes (dimensions) specified by `axis` must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if `False`, the axes (dimensions) specified by `axis` must not be included in the result. Default: `False`.
170
+
- If `True`, the axes (dimensions) specified by `axis` must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see {ref}`broadcasting`). Otherwise, if `False`, the axes (dimensions) specified by `axis` must not be included in the result. Default: `False`.
@@ -235,7 +237,7 @@ Computes the outer product of two vectors `x1` and `x2`.
235
237
236
238
-**out**: _<array>_
237
239
238
-
- a two-dimensional array containing the outer product and whose shape is `NxM`. The returned array must have a data type determined by :ref:`type-promotion` rules.
240
+
- a two-dimensional array containing the outer product and whose shape is `NxM`. The returned array must have a data type determined by {ref}`type-promotion` rules.
0 commit comments