diff --git a/requirements.txt b/requirements.txt
index c6267867c..fa2e7d09f 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,5 @@
sphinx==3.1.1
sphinx-material==0.0.30
-recommonmark
+myst-parser
sphinx_markdown_tables
sphinx_copybutton
diff --git a/spec/API_specification/array_object.md b/spec/API_specification/array_object.md
index ee8b21833..4007edc39 100644
--- a/spec/API_specification/array_object.md
+++ b/spec/API_specification/array_object.md
@@ -1,4 +1,4 @@
-.. array-object:
+(array-object)=
# Array object
@@ -8,9 +8,9 @@ A conforming implementation of the array API standard must provide and support a
- 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 method accepting positional-only parameters is called, positional arguments are mapped to these parameters based solely on their order.
- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
-- Broadcasting semantics must follow the semantics defined in :ref:`broadcasting`.
-- Unless stated otherwise, methods must support the data types defined in :ref:`data-types`.
-- Unless stated otherwise, methods must adhere to the type promotion rules defined in :ref:`type-promotion`.
+- Broadcasting semantics must follow the semantics defined in {ref}`broadcasting`.
+- Unless stated otherwise, methods must support the data types defined in {ref}`data-types`.
+- Unless stated otherwise, methods must adhere to the type promotion rules defined in {ref}`type-promotion`.
- Unless stated otherwise, floating-point operations must adhere to IEEE 754-2019.
* * *
@@ -19,114 +19,114 @@ A conforming implementation of the array API standard must provide and support a
A conforming implementation of the array API standard must provide and support an array object supporting the following Python operators:
-- `x1 < x2`: [`__lt__(x1, x2)`](#__lt__)
+- `x1 < x2`: [`__lt__(x1, x2)`](#__lt__x1-x2-)
- [`operator.lt(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.lt)
- [`operator.__lt__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__lt__)
-- `x1 <= x2`: [`__le__(x1, x2)`](#__le__)
+- `x1 <= x2`: [`__le__(x1, x2)`](#__le__x1-x2-)
- [`operator.le(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.le)
- [`operator.__le__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__le__)
-- `x1 > x2`: [`__gt__(x1, x2)`](#__gt__)
+- `x1 > x2`: [`__gt__(x1, x2)`](#__gt__x1-x2-)
- [`operator.gt(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.gt)
- [`operator.__gt__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__gt__)
-- `x1 >= x2`: [`__ge__(x1, x2)`](#__ge__)
+- `x1 >= x2`: [`__ge__(x1, x2)`](#__ge__x1-x2-)
- [`operator.ge(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.ge)
- [`operator.__ge__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__ge__)
-- `x1 == x2`: [`__eq__(x1, x2)`](#__eq__)
+- `x1 == x2`: [`__eq__(x1, x2)`](#__eq__x1-x2-)
- [`operator.eq(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.eq)
- [`operator.__eq__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__eq__)
-- `x1 != x2`: [`__ne__(x1, x2)`](#__ne__)
+- `x1 != x2`: [`__ne__(x1, x2)`](#__ne__x1-x2-)
- [`operator.ne(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.ne)
- [`operator.__ne__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__ne__)
-- `+x`: [`__pos__(x)`](#__pos__)
+- `+x`: [`__pos__(x)`](#__pos__x-)
- [`operator.pos(x)`](https://docs.python.org/3/library/operator.html#operator.pos)
- [`operator.__pos__(x)`](https://docs.python.org/3/library/operator.html#operator.__pos__)
-- `-x`: [`__neg__(x)`](#__neg__)
+- `-x`: [`__neg__(x)`](#__neg__x-)
- [`operator.neg(x)`](https://docs.python.org/3/library/operator.html#operator.neg)
- [`operator.__neg__(x)`](https://docs.python.org/3/library/operator.html#operator.__neg__)
-- `x1 + x2`: [`__add__(x1, x2)`](#__add__)
+- `x1 + x2`: [`__add__(x1, x2)`](#__add__x1-x2-)
- [`operator.add(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.add)
- [`operator.__add__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__add__)
-- `x1 - x2`: [`__sub__(x1, x2)`](#__sub__)
+- `x1 - x2`: [`__sub__(x1, x2)`](#__sub__x1-x2-)
- [`operator.sub(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.sub)
- [`operator.__sub__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__sub__)
-- `x1 * x2`: [`__mul__(x1, x2)`](#__mul__)
+- `x1 * x2`: [`__mul__(x1, x2)`](#__mul__x1-x2-)
- [`operator.mul(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.mul)
- [`operator.__mul__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__mul__)
-- `x1 / x2`: [`__truediv__(x1, x2)`](#__truediv__)
+- `x1 / x2`: [`__truediv__(x1, x2)`](#__truediv__x1-x2-)
- [`operator.truediv(x1,x2)`](https://docs.python.org/3/library/operator.html#operator.truediv)
- [`operator.__truediv__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__truediv__)
-- `x1 // x2`: [`__floordiv__(x1, x2)`](#__floordiv__)
+- `x1 // x2`: [`__floordiv__(x1, x2)`](#__floordiv__x1-x2-)
- [`operator.floordiv(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.floordiv)
- [`operator.__floordiv__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__floordiv__)
-- `x1 % x2`: [`__mod__(x1, x2)`](#__mod__)
+- `x1 % x2`: [`__mod__(x1, x2)`](#__mod__x1-x2-)
- [`operator.mod(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.mod)
- [`operator.__mod__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__mod__)
-- `x1 ** x2`: [`__pow__(x1, x2)`](#__pow__)
+- `x1 ** x2`: [`__pow__(x1, x2)`](#__pow__x1-x2-)
- [`operator.pow(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.pow)
- [`operator.__pow__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__pow__)
-- `x1 @ x2`: [`__matmul__(x1, x2)`](#__matmul__)
+- `x1 @ x2`: [`__matmul__(x1, x2)`](#__matmul__x1-x2-)
- [`operator.matmul(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.matmul)
- [`operator.__matmul__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__matmul__)
-- `~x`: [`__invert__(x)`](#__invert__)
+- `~x`: [`__invert__(x)`](#__invert__x-)
- [`operator.inv(x)`](https://docs.python.org/3/library/operator.html#operator.inv)
- [`operator.invert(x)`](https://docs.python.org/3/library/operator.html#operator.invert)
- [`operator.__inv__(x)`](https://docs.python.org/3/library/operator.html#operator.__inv__)
- [`operator.__invert__(x)`](https://docs.python.org/3/library/operator.html#operator.__invert__)
-- `x1 & x2`: [`__and__(x1, x2)`](#__and__)
+- `x1 & x2`: [`__and__(x1, x2)`](#__and__x1-x2-)
- [`operator.and(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.and)
- [`operator.__and__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__and__)
-- `x1 | x2`: [`__or__(x1, x2)`](#__or__)
+- `x1 | x2`: [`__or__(x1, x2)`](#__or__x1-x2-)
- [`operator.or(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.or)
- [`operator.__or__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__or__)
-- `x1 ^ x2`: [`__xor__(x1, x2)`](#__xor__)
+- `x1 ^ x2`: [`__xor__(x1, x2)`](#__xor__x1-x2-)
- [`operator.xor(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.xor)
- [`operator.__xor__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__xor__)
-- `x1 << x2`: [`__lshift__(x1, x2)`](#__lshift__)
+- `x1 << x2`: [`__lshift__(x1, x2)`](#__lshift__x1-x2-)
- [`operator.lshift(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.lshift)
- [`operator.__lshift__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__lshift__)
-- `x1 >> x2`: [`__rshift__(x1, x2)`](#__rshift__)
+- `x1 >> x2`: [`__rshift__(x1, x2)`](#__rshift__x1-x2-)
- [`operator.rshift(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.rshift)
- [`operator.__rshift__(x1, x2)`](https://docs.python.org/3/library/operator.html#operator.__rshift__)
@@ -134,7 +134,7 @@ A conforming implementation of the array API standard must provide and support a
### In-place operators
-As discussed in :ref:`copyview-mutability`, in-place operators need to be
+As discussed in {ref}`copyview-mutability`, in-place operators need to be
supported. The following operators must be supported:
- `+=`. May be (but does not have to be) implemented via `__iadd__`.
@@ -241,7 +241,7 @@ Transpose of the array.
-### # \_\_abs\_\_(x, /)
+### \_\_abs\_\_(x, /)
Calculates the absolute value for each element `x_i` of an array instance `x` (i.e., the element-wise result has the same magnitude as the respective element in `x` but has positive sign).
@@ -263,11 +263,12 @@ Calculates the absolute value for each element `x_i` of an array instance `x` (i
- an array containing the element-wise absolute value. The returned array must have the same data type as `x`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`abs(x)`](elementwise_functions.md#abs).
+Element-wise results must equal the results returned by the equivalent element-wise function [`abs(x)`](elementwise_functions.md#absx-).
+```
-### # \_\_add\_\_(x1, x2, /)
+### \_\_add\_\_(x1, x2, /)
Calculates the sum for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`. For floating-point arithmetic,
@@ -291,9 +292,10 @@ Calculates the sum for each element `x1_i` of an array instance `x1` with the re
- If `x1_i` is a nonzero finite number and `x2_i` is `-x1_i`, the result is `+0`.
- In the remaining cases, when neither `infinity`, `+0`, `-0`, nor a `NaN` is involved, and the operands have the same mathematical sign or have different magnitudes, the sum must be computed and rounded to the nearest representable value according to IEEE 754-2019 and a supported round mode. If the magnitude is too large to represent, the operation overflows and the result is an `infinity` of appropriate mathematical sign.
-.. note::
+```{note}
- Floating-point addition is a commutative operation, but not always associative.
+Floating-point addition is a commutative operation, but not always associative.
+```
#### Parameters
@@ -303,19 +305,20 @@ Calculates the sum for each element `x1_i` of an array instance `x1` with the re
- **x2**: _<array>_
- - addend array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - addend array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the element-wise sums. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise sums. The returned array must have a data type determined by {ref}`type-promotion`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`add(x1, x2)`](elementwise_functions.md#add).
+Element-wise results must equal the results returned by the equivalent element-wise function [`add(x1, x2)`](elementwise_functions.md#addx1-x2-).
+```
-### # \_\_and\_\_(x1, x2, /)
+### \_\_and\_\_(x1, x2, /)
Evaluates `x1_i & x2_i` for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`.
@@ -327,19 +330,20 @@ Evaluates `x1_i & x2_i` for each element `x1_i` of an array instance `x1` with t
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`). Must have an integer or boolean data type.
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`). Must have an integer or boolean data type.
#### Returns
- **out**: _<array>_
- - an array containing the element-wise results. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_and(x1, x2)`](elementwise_functions.md#and).
+Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_and(x1, x2)`](elementwise_functions.md#logical_andx1-x2-).
+```
-### # \_\_eq\_\_(x1, x2, /)
+### \_\_eq\_\_(x1, x2, /)
Computes the truth value of `x1_i == x2_i` for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`.
@@ -351,7 +355,7 @@ Computes the truth value of `x1_i == x2_i` for each element `x1_i` of an array i
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -359,11 +363,12 @@ Computes the truth value of `x1_i == x2_i` for each element `x1_i` of an array i
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`equal(x1, x2)`](elementwise_functions.md#equal).
+Element-wise results must equal the results returned by the equivalent element-wise function [`equal(x1, x2)`](elementwise_functions.md#equalx1-x2-).
+```
-### # \_\_floordiv\_\_(x1, x2, /)
+### \_\_floordiv\_\_(x1, x2, /)
Evaluates `x1_i // x2_i` for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`.
@@ -375,19 +380,20 @@ Evaluates `x1_i // x2_i` for each element `x1_i` of an array instance `x1` with
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the element-wise results. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`floor_divide(x1, x2)`](elementwise_functions.md#floor_divide).
+Element-wise results must equal the results returned by the equivalent element-wise function [`floor_divide(x1, x2)`](elementwise_functions.md#floor_dividex1-x2-).
+```
-### # \_\_ge\_\_(x1, x2, /)
+### \_\_ge\_\_(x1, x2, /)
Computes the truth value of `x1_i >= x2_i` for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`.
@@ -399,7 +405,7 @@ Computes the truth value of `x1_i >= x2_i` for each element `x1_i` of an array i
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -407,15 +413,16 @@ Computes the truth value of `x1_i >= x2_i` for each element `x1_i` of an array i
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`greater_equal(x1, x2)`](elementwise_functions.md#greater_equal).
+Element-wise results must equal the results returned by the equivalent element-wise function [`greater_equal(x1, x2)`](elementwise_functions.md#greater_equalx1-x2-).
+```
-### # \_\_getitem\_\_(x, key, /)
+### \_\_getitem\_\_(x, key, /)
_TODO: dependent on the indexing specification._
-### # \_\_gt\_\_(x1, x2, /)
+### \_\_gt\_\_(x1, x2, /)
Computes the truth value of `x1_i > x2_i` for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`.
@@ -427,7 +434,7 @@ Computes the truth value of `x1_i > x2_i` for each element `x1_i` of an array in
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -435,11 +442,12 @@ Computes the truth value of `x1_i > x2_i` for each element `x1_i` of an array in
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`greater(x1, x2)`](elementwise_functions.md#greater).
+Element-wise results must equal the results returned by the equivalent element-wise function [`greater(x1, x2)`](elementwise_functions.md#greaterx1-x2-).
+```
-### # \_\_invert\_\_(x, /)
+### \_\_invert\_\_(x, /)
Evaluates `~x_i` for each element `x_i` of an array instance `x`.
@@ -455,11 +463,12 @@ Evaluates `~x_i` for each element `x_i` of an array instance `x`.
- an array containing the element-wise results. The returned array must have the same data type as `x`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_invert(x)`](elementwise_functions.md#bitwise_invert).
+Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_invert(x)`](elementwise_functions.md#bitwise_invertx-).
+```
-### # \_\_le\_\_(x1, x2, /)
+### \_\_le\_\_(x1, x2, /)
Computes the truth value of `x1_i <= x2_i` for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`.
@@ -471,7 +480,7 @@ Computes the truth value of `x1_i <= x2_i` for each element `x1_i` of an array i
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -479,15 +488,16 @@ Computes the truth value of `x1_i <= x2_i` for each element `x1_i` of an array i
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`less_equal(x1, x2)`](elementwise_functions.md#less_equal).
+Element-wise results must equal the results returned by the equivalent element-wise function [`less_equal(x1, x2)`](elementwise_functions.md#less_equalx1-x2-).
+```
-### # \_\_len\_\_(x, /)
+### \_\_len\_\_(x, /)
_TODO: need to more carefully consider this in order to accommodate, e.g., graph tensors where a shape may be dynamic._
-### # \_\_lshift\_\_(x1, x2, /)
+### \_\_lshift\_\_(x1, x2, /)
Evaluates `x1_i << x2_i` for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`.
@@ -499,7 +509,7 @@ Evaluates `x1_i << x2_i` for each element `x1_i` of an array instance `x1` with
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`). Must have an integer data type. Each element must be greater than or equal to `0`.
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`). Must have an integer data type. Each element must be greater than or equal to `0`.
#### Returns
@@ -507,11 +517,12 @@ Evaluates `x1_i << x2_i` for each element `x1_i` of an array instance `x1` with
- an array containing the element-wise results. The returned array must have the same data type as `x1`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`less_equal(x1, x2)`](elementwise_functions.md#bitwise_left_shift).
+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-).
+```
-### # \_\_lt\_\_(x1, x2, /)
+### \_\_lt\_\_(x1, x2, /)
Computes the truth value of `x1_i < x2_i` for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`.
@@ -523,7 +534,7 @@ Computes the truth value of `x1_i < x2_i` for each element `x1_i` of an array in
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -531,11 +542,12 @@ Computes the truth value of `x1_i < x2_i` for each element `x1_i` of an array in
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`less(x1, x2)`](elementwise_functions.md#less).
+Element-wise results must equal the results returned by the equivalent element-wise function [`less(x1, x2)`](elementwise_functions.md#lessx1-x2-).
+```
-### # \_\_matmul\_\_(x1, x2, /)
+### \_\_matmul\_\_(x1, x2, /)
_TODO: awaiting `matmul` functional equivalent._
@@ -547,7 +559,7 @@ _TODO: awaiting `matmul` functional equivalent._
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -555,7 +567,7 @@ _TODO: awaiting `matmul` functional equivalent._
- _TODO_
-### # \_\_mod\_\_(x1, x2, /)
+### \_\_mod\_\_(x1, x2, /)
Evaluates `x1_i % x2_i` for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`.
@@ -567,19 +579,20 @@ Evaluates `x1_i % x2_i` for each element `x1_i` of an array instance `x1` with t
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the element-wise results. Each element-wise result must have the same sign as the respective element `x2_i`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise results. Each element-wise result must have the same sign as the respective element `x2_i`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`remainder(x1, x2)`](elementwise_functions.md#remainder).
+Element-wise results must equal the results returned by the equivalent element-wise function [`remainder(x1, x2)`](elementwise_functions.md#remainderx1-x2-).
+```
-### # \_\_mul\_\_(x1, x2, /)
+### \_\_mul\_\_(x1, x2, /)
Calculates the product for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`. For floating-point arithmetic,
@@ -595,9 +608,10 @@ Calculates the product for each element `x1_i` of an array instance `x1` with th
- If `x1_i` is a nonzero finite number and `x2_i` is either `+infinity` or `-infinity`, the result is a signed infinity with the mathematical sign determined by the rule already stated above.
- In the remaining cases, where neither `infinity` nor `NaN` is involved, the product must be computed and rounded to the nearest representable value according to IEEE 754-2019 and a supported rounding mode. If the magnitude is too large to represent, the result is an `infinity` of appropriate mathematical sign. If the magnitude is too small to represent, the result is a zero of appropriate mathematical sign.
-.. note::
+```{note}
- Floating-point multiplication is not always associative due to finite precision.
+Floating-point multiplication is not always associative due to finite precision.
+```
#### Parameters
@@ -607,19 +621,20 @@ Calculates the product for each element `x1_i` of an array instance `x1` with th
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the element-wise products. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise products. The returned array must have a data type determined by {ref}`type-promotion`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`multiply(x1, x2)`](elementwise_functions.md#multiply).
+Element-wise results must equal the results returned by the equivalent element-wise function [`multiply(x1, x2)`](elementwise_functions.md#multiplyx1-x2-).
+```
-### # \_\_ne\_\_(x1, x2, /)
+### \_\_ne\_\_(x1, x2, /)
Computes the truth value of `x1_i != x2_i` for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`.
@@ -631,7 +646,7 @@ Computes the truth value of `x1_i != x2_i` for each element `x1_i` of an array i
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -639,11 +654,12 @@ Computes the truth value of `x1_i != x2_i` for each element `x1_i` of an array i
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`not_equal(x1, x2)`](elementwise_functions.md#not_equal).
+Element-wise results must equal the results returned by the equivalent element-wise function [`not_equal(x1, x2)`](elementwise_functions.md#not_equalx1-x2-).
+```
-### # \_\_neg\_\_(x, /)
+### \_\_neg\_\_(x, /)
Evaluates `-x_i` for each element `x_i` of an array instance `x`.
@@ -657,13 +673,14 @@ Evaluates `-x_i` for each element `x_i` of an array instance `x`.
- **out**: _<array>_
- - an array containing the evaluated result for each element in `x`. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the evaluated result for each element in `x`. The returned array must have a data type determined by {ref}`type-promotion`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`negative(x)`](elementwise_functions.md#negative).
+Element-wise results must equal the results returned by the equivalent element-wise function [`negative(x)`](elementwise_functions.md#negativex-).
+```
-### # \_\_or\_\_(x1, x2, /)
+### \_\_or\_\_(x1, x2, /)
Evaluates `x1_i | x2_i` for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`.
@@ -675,19 +692,20 @@ Evaluates `x1_i | x2_i` for each element `x1_i` of an array instance `x1` with t
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`). Must have an integer or boolean data type.
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`). Must have an integer or boolean data type.
#### Returns
- **out**: _<array>_
- - an array containing the element-wise results. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`positive(x1, x2)`](elementwise_functions.md#bitwise_or).
+Element-wise results must equal the results returned by the equivalent element-wise function [`positive(x1, x2)`](elementwise_functions.md#bitwise_orx1-x2-).
+```
-### # \_\_pos\_\_(x, /)
+### \_\_pos\_\_(x, /)
Evaluates `+x_i` for each element `x_i` of an array instance `x`.
@@ -703,11 +721,12 @@ Evaluates `+x_i` for each element `x_i` of an array instance `x`.
- an array containing the evaluated result for each element in `x`. The returned array must have the same data type as `x`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`positive(x)`](elementwise_functions.md#positive).
+Element-wise results must equal the results returned by the equivalent element-wise function [`positive(x)`](elementwise_functions.md#positivex-).
+```
-### # \_\_pow\_\_(x1, x2, /)
+### \_\_pow\_\_(x1, x2, /)
Calculates an implementation-dependent approximation of exponentiation by raising each element `x1_i` (the base) of an array instance `x1` to the power of `x2_i` (the exponent), where `x2_i` is the corresponding element of the array `x2`.
@@ -746,19 +765,20 @@ Calculates an implementation-dependent approximation of exponentiation by raisin
- **x2**: _<array>_
- - other array whose elements correspond to the exponentiation exponent. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - other array whose elements correspond to the exponentiation exponent. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the element-wise results. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`pow(x1, x2)`](elementwise_functions.md#pow).
+Element-wise results must equal the results returned by the equivalent element-wise function [`pow(x1, x2)`](elementwise_functions.md#powx1-x2-).
+```
-### # \_\_rshift\_\_(x1, x2, /)
+### \_\_rshift\_\_(x1, x2, /)
Evaluates `x1_i >> x2_i` for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`.
@@ -770,7 +790,7 @@ Evaluates `x1_i >> x2_i` for each element `x1_i` of an array instance `x1` with
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`). Must have an integer data type. Each element must be greater than or equal to `0`.
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`). Must have an integer data type. Each element must be greater than or equal to `0`.
#### Returns
@@ -778,17 +798,18 @@ Evaluates `x1_i >> x2_i` for each element `x1_i` of an array instance `x1` with
- an array containing the element-wise results. The returned array must have the same data type as `x1`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_right_shift(x1, x2)`](elementwise_functions.md#bitwise_right_shift).
+Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_right_shift(x1, x2)`](elementwise_functions.md#bitwise_right_shiftx1-x2-).
+```
-### # \_\_setitem\_\_(x, key, value, /)
+### \_\_setitem\_\_(x, key, value, /)
_TODO: dependent on the indexing specification._
-### # \_\_sub\_\_(x1, x2, /)
+### \_\_sub\_\_(x1, x2, /)
-Calculates the difference for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`. The result of `x1_i - x2_i` must be the same as `x1_i + (-x2_i)` and is thus governed by the same floating-point rules as addition (see [`__add__()`](#__add__)).
+Calculates the difference for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`. The result of `x1_i - x2_i` must be the same as `x1_i + (-x2_i)` and is thus governed by the same floating-point rules as addition (see [`__add__()`](#__add__x1-x2-)).
#### Parameters
@@ -798,19 +819,20 @@ Calculates the difference for each element `x1_i` of an array instance `x1` with
- **x2**: _<array>_
- - subtrahend array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - subtrahend array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the element-wise differences. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise differences. The returned array must have a data type determined by {ref}`type-promotion`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`subtract(x1, x2)`](elementwise_functions.md#subtract).
+Element-wise results must equal the results returned by the equivalent element-wise function [`subtract(x1, x2)`](elementwise_functions.md#subtractx1-x2-).
+```
-### # \_\_truediv\_\_(x1, x2, /)
+### \_\_truediv\_\_(x1, x2, /)
Evaluates `x1_i / x2_i` for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`. For floating-point arithmetic,
@@ -847,19 +869,20 @@ Evaluates `x1_i / x2_i` for each element `x1_i` of an array instance `x1` with t
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the element-wise results. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`divide(x1, x2)`](elementwise_functions.md#divide).
+Element-wise results must equal the results returned by the equivalent element-wise function [`divide(x1, x2)`](elementwise_functions.md#dividex1-x2-).
+```
-### # \_\_xor\_\_(x1, x2, /)
+### \_\_xor\_\_(x1, x2, /)
Evaluates `x1_i ^ x2_i` for each element `x1_i` of an array instance `x1` with the respective element `x2_i` of the array `x2`.
@@ -871,14 +894,15 @@ Evaluates `x1_i ^ x2_i` for each element `x1_i` of an array instance `x1` with t
- **x2**: _<array>_
- - other array. Must be compatible with `x1` (see :ref:`broadcasting`). Must have an integer or boolean data type.
+ - other array. Must be compatible with `x1` (see {ref}`broadcasting`). Must have an integer or boolean data type.
#### Returns
- **out**: _<array>_
- - an array containing the element-wise results. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
-.. note::
+```{note}
- Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_xor(x1, x2)`](elementwise_functions.md#bitwise_xor).
\ No newline at end of file
+Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_xor(x1, x2)`](elementwise_functions.md#bitwise_xorx1-x2-).
+```
diff --git a/spec/API_specification/broadcasting.md b/spec/API_specification/broadcasting.md
index 7bb7e86a0..34e90cd0b 100644
--- a/spec/API_specification/broadcasting.md
+++ b/spec/API_specification/broadcasting.md
@@ -1,4 +1,4 @@
-.. _broadcasting:
+(broadcasting)=
# Broadcasting
diff --git a/spec/API_specification/casting.md b/spec/API_specification/casting.md
deleted file mode 100644
index 658b457a8..000000000
--- a/spec/API_specification/casting.md
+++ /dev/null
@@ -1 +0,0 @@
-# Dtype casting
diff --git a/spec/API_specification/constants.md b/spec/API_specification/constants.md
index acb214ef0..2da4f61fa 100644
--- a/spec/API_specification/constants.md
+++ b/spec/API_specification/constants.md
@@ -6,6 +6,8 @@ A conforming implementation of the array API standard must provide and support t
+## Objects in API
+
### # e
Euler's constant.
diff --git a/spec/API_specification/creation_functions.md b/spec/API_specification/creation_functions.md
index fcfedd234..97cf6f2e1 100644
--- a/spec/API_specification/creation_functions.md
+++ b/spec/API_specification/creation_functions.md
@@ -7,6 +7,8 @@ A conforming implementation of the array API standard must provide and support t
- 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.
- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
+## Objects in API
+
### # arange(start, /, *, stop=None, step=1, dtype=None)
@@ -23,9 +25,10 @@ Returns evenly spaced values within the half-open interval `[start, stop)` as a
- the end of the interval. Default: `None`.
-.. note::
+```{note}
- 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.
+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.
+```
- **step**: _Union\[ int, float ]_
diff --git a/spec/API_specification/data_types.md b/spec/API_specification/data_types.md
index 0d6f6d99d..3918b78c6 100644
--- a/spec/API_specification/data_types.md
+++ b/spec/API_specification/data_types.md
@@ -1,4 +1,4 @@
-.. _data-types:
+(data-types)=
# Data Types
@@ -6,28 +6,32 @@
A conforming implementation of the array API standard must provide and support the following data types.
-.. note::
+```{note}
- 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.
+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.
+```
-.. note::
+```{note}
- Implementations may provide other ways to specify data types (e.g.,
- `zeros((2, 3), dtype='f4')`); however, these are not included in this specification.
+Implementations may provide other ways to specify data types (e.g.,
+`zeros((2, 3), dtype='f4')`); however, these are not included in this specification.
+```
A conforming implementation of the array API standard may provide and support additional data types beyond those described in this specification.
A conforming implementation of the array API standard must define a default floating-point data type (either `float32` or `float64`).
-.. note::
+```{note}
- The default floating-point data type should be clearly defined in a conforming library's documentation.
+The default floating-point data type should be clearly defined in a conforming library's documentation.
+```
A conforming implementation of the array API standard must define a default data type for an array index (either `int32` or `int64`).
-.. note::
+```{note}
- The default array index data type should be clearly defined in a conforming library's documentation.
+The default array index data type should be clearly defined in a conforming library's documentation.
+```
## bool
diff --git a/spec/API_specification/elementwise_functions.md b/spec/API_specification/elementwise_functions.md
index 348f974b4..b82d37966 100644
--- a/spec/API_specification/elementwise_functions.md
+++ b/spec/API_specification/elementwise_functions.md
@@ -1,4 +1,4 @@
-.. _element-wise-functions:
+(element-wise-functions)=
# Element-wise Functions
@@ -8,15 +8,17 @@ A conforming implementation of the array API standard must provide and support t
- 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.
- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
-- Broadcasting semantics must follow the semantics defined in :ref:`broadcasting`.
-- Unless stated otherwise, functions must support the data types defined in :ref:`data-types`.
-- Unless stated otherwise, functions must adhere to the type promotion rules defined in :ref:`type-promotion`.
+- Broadcasting semantics must follow the semantics defined in {ref}`broadcasting`.
+- Unless stated otherwise, functions must support the data types defined in {ref}`data-types`.
+- Unless stated otherwise, functions must adhere to the type promotion rules defined in {ref}`type-promotion`.
- Unless stated otherwise, floating-point operations must adhere to IEEE 754-2019.
-- Unless stated otherwise, element-wise mathematical functions must satisfy the minimum accuracy requirements defined in :ref:`accuracy`.
+- Unless stated otherwise, element-wise mathematical functions must satisfy the minimum accuracy requirements defined in {ref}`accuracy`.
+
+## Objects in API
-### # abs(x, /)
+### abs(x, /)
Calculates the absolute value for each element `x_i` of the input array `x` (i.e., the element-wise result has the same magnitude as the respective element in `x` but has positive sign).
@@ -38,7 +40,7 @@ Calculates the absolute value for each element `x_i` of the input array `x` (i.e
- an array containing the absolute value of each element in `x`. The returned array must have the same data type as `x`.
-### # acos(x, /)
+### acos(x, /)
Calculates an implementation-dependent approximation of the principal value of the inverse cosine, having domain `[-1, +1]` and codomain `[+0, +π]`, for each element `x_i` of the input array `x`. Each element-wise result is expressed in radians.
@@ -59,9 +61,9 @@ Calculates an implementation-dependent approximation of the principal value of t
- **out**: _<array>_
- - an array containing the inverse cosine of each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the inverse cosine of each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # acosh(x, /)
+### acosh(x, /)
Calculates an implementation-dependent approximation to the inverse hyperbolic cosine, having domain `[+1, +infinity]` and codomain `[+0, +infinity]`, for each element `x_i` of the input array `x`.
@@ -82,9 +84,9 @@ Calculates an implementation-dependent approximation to the inverse hyperbolic c
- **out**: _<array>_
- - an array containing the inverse hyperbolic cosine of each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the inverse hyperbolic cosine of each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # add(x1, x2, /)
+### add(x1, x2, /)
Calculates the sum for each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`. For floating-point arithmetic,
@@ -108,9 +110,10 @@ Calculates the sum for each element `x1_i` of the input array `x1` with the resp
- If `x1_i` is a nonzero finite number and `x2_i` is `-x1_i`, the result is `+0`.
- In the remaining cases, when neither `infinity`, `+0`, `-0`, nor a `NaN` is involved, and the operands have the same mathematical sign or have different magnitudes, the sum must be computed and rounded to the nearest representable value according to IEEE 754-2019 and a supported round mode. If the magnitude is too large to represent, the operation overflows and the result is an `infinity` of appropriate mathematical sign.
-.. note::
+```{note}
- Floating-point addition is a commutative operation, but not always associative.
+Floating-point addition is a commutative operation, but not always associative.
+```
#### Parameters
@@ -120,15 +123,15 @@ Calculates the sum for each element `x1_i` of the input array `x1` with the resp
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the element-wise sums. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise sums. The returned array must have a data type determined by {ref}`type-promotion`.
-### # asin(x, /)
+### asin(x, /)
Calculates an implementation-dependent approximation of the principal value of the inverse sine, having domain `[-1, +1]` and codomain `[-π/2, +π/2]` for each element `x_i` of the input array `x`. Each element-wise result is expressed in radians.
@@ -150,9 +153,9 @@ Calculates an implementation-dependent approximation of the principal value of t
- **out**: _<array>_
- - an array containing the inverse sine of each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the inverse sine of each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # asinh(x, /)
+### asinh(x, /)
Calculates an implementation-dependent approximation to the inverse hyperbolic sine, having domain `[-infinity, +infinity]` and codomain `[-infinity, +infinity]`, for each element `x_i` in the input array `x`.
@@ -174,9 +177,9 @@ Calculates an implementation-dependent approximation to the inverse hyperbolic s
- **out**: _<array>_
- - an array containing the inverse hyperbolic sine of each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the inverse hyperbolic sine of each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # atan(x, /)
+### atan(x, /)
Calculates an implementation-dependent approximation of the principal value of the inverse tangent, having domain `[-infinity, +infinity]` and codomain `[-π/2, +π/2]`, for each element `x_i` of the input array `x`. Each element-wise result is expressed in radians.
@@ -198,17 +201,18 @@ Calculates an implementation-dependent approximation of the principal value of t
- **out**: _<array>_
- - an array containing the inverse tangent of each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the inverse tangent of each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # atan2(x1, x2, /)
+### atan2(x1, x2, /)
Calculates an implementation-dependent approximation of the inverse tangent of the quotient `x1/x2`, having domain `[-infinity, +infinity] x [-infinity, +infinity]` (where the `x` notation denotes the set of ordered pairs of elements `(x1_i, x2_i)`) and codomain `[-π, +π]`, for each pair of elements `(x1_i, x2_i)` of the input arrays `x1` and `x2`, respectively. Each element-wise result is expressed in radians.
The mathematical signs of `x1_i` and `x2_i` determine the quadrant of each element-wise result. The quadrant (i.e., branch) is chosen such that each element-wise result is the signed angle in radians between the ray ending at the origin and passing through the point `(1,0)` and the ray ending at the origin and passing through the point `(x2_i, x1_i)`.
-.. note::
+```{note}
- Note the role reversal: the "y-coordinate" is the first function parameter; the "x-coordinate" is the second function parameter. The parameter order is intentional and traditional for the two-argument inverse tangent function where the y-coordinate argument is first and the x-coordinate argument is second.
+Note the role reversal: the "y-coordinate" is the first function parameter; the "x-coordinate" is the second function parameter. The parameter order is intentional and traditional for the two-argument inverse tangent function where the y-coordinate argument is first and the x-coordinate argument is second.
+```
By IEEE 754 convention, the inverse tangent of the quotient `x1/x2` is defined for `x2_i` equal to positive or negative zero and for either or both of `x1_i` and `x2_i` equal to positive or negative `infinity`.
@@ -246,15 +250,15 @@ By IEEE 754 convention, the inverse tangent of the quotient `x1/x2` is defined f
- **x2**: _<array>_
- - input array corresponding to the x-coordinates. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - input array corresponding to the x-coordinates. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the inverse tangent of the quotient `x1/x2`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the inverse tangent of the quotient `x1/x2`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # atanh(x, /)
+### atanh(x, /)
Calculates an implementation-dependent approximation to the inverse hyperbolic tangent, having domain `[-1, +1]` and codomain `[-infinity, +infinity]`, for each element `x_i` of the input array `x`.
@@ -278,9 +282,9 @@ Calculates an implementation-dependent approximation to the inverse hyperbolic t
- **out**: _<array>_
- - an array containing the inverse hyperbolic tangent of each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the inverse hyperbolic tangent of each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # bitwise_and(x1, x2, /)
+### bitwise_and(x1, x2, /)
Computes the bitwise AND of the underlying binary representation of each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`.
@@ -292,15 +296,15 @@ Computes the bitwise AND of the underlying binary representation of each element
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`). Must have an integer or boolean data type.
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`). Must have an integer or boolean data type.
#### Returns
- **out**: _<array>_
- - an array containing the element-wise results. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
-### # bitwise_left_shift(x1, x2, /)
+### bitwise_left_shift(x1, x2, /)
Shifts the bits of each element `x1_i` of the input array `x1` to the left by appending `x2_i` (i.e., the respective element in the input array `x2`) zeros to the right of `x1_i`.
@@ -312,7 +316,7 @@ Shifts the bits of each element `x1_i` of the input array `x1` to the left by ap
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`). Must have an integer data type. Each element must be greater than or equal to `0`.
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`). Must have an integer data type. Each element must be greater than or equal to `0`.
#### Returns
@@ -320,7 +324,7 @@ Shifts the bits of each element `x1_i` of the input array `x1` to the left by ap
- an array containing the element-wise results. The returned array must have the same data type as `x1`.
-### # bitwise_invert(x, /)
+### bitwise_invert(x, /)
Inverts (flips) each bit for each element `x_i` of the input array `x`.
@@ -336,7 +340,7 @@ Inverts (flips) each bit for each element `x_i` of the input array `x`.
- an array containing the element-wise results. The returned array must have the same data type as `x`.
-### # bitwise_or(x1, x2, /)
+### bitwise_or(x1, x2, /)
Computes the bitwise OR of the underlying binary representation of each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`.
@@ -348,15 +352,15 @@ Computes the bitwise OR of the underlying binary representation of each element
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`). Must have an integer or boolean data type.
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`). Must have an integer or boolean data type.
#### Returns
- **out**: _<array>_
- - an array containing the element-wise results. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
-### # bitwise_right_shift(x1, x2, /)
+### bitwise_right_shift(x1, x2, /)
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`.
@@ -368,7 +372,7 @@ Shifts the bits of each element `x1_i` of the input array `x1` to the right acco
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`). Must have an integer data type. Each element must be greater than or equal to `0`.
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`). Must have an integer data type. Each element must be greater than or equal to `0`.
#### Returns
@@ -376,7 +380,7 @@ Shifts the bits of each element `x1_i` of the input array `x1` to the right acco
- an array containing the element-wise results. The returned array must have the same data type as `x1`.
-### # bitwise_xor(x1, x2, /)
+### bitwise_xor(x1, x2, /)
Computes the bitwise XOR of the underlying binary representation of each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`.
@@ -388,15 +392,15 @@ Computes the bitwise XOR of the underlying binary representation of each element
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`). Must have an integer or boolean data type.
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`). Must have an integer or boolean data type.
#### Returns
- **out**: _<array>_
- - an array containing the element-wise results. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
-### # ceil(x, /)
+### ceil(x, /)
Rounds each element `x_i` of the input array `x` to the smallest (i.e., closest to `-infinity`) integer-valued number that is not less than `x_i`.
@@ -416,7 +420,7 @@ Rounds each element `x_i` of the input array `x` to the smallest (i.e., closest
- an array containing the rounded result for each element in `x`. The returned array must have the same data type as `x`.
-### # cos(x, /)
+### cos(x, /)
Calculates an implementation-dependent approximation to the cosine, having domain `(-infinity, +infinity)` and codomain `[-1, +1]`, for each element `x_i` of the input array `x`. Each element `x_i` is assumed to be expressed in radians.
@@ -438,9 +442,9 @@ Calculates an implementation-dependent approximation to the cosine, having domai
- **out**: _<array>_
- - an array containing the cosine of each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the cosine of each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # cosh(x, /)
+### cosh(x, /)
Calculates an implementation-dependent approximation to the hyperbolic cosine, having domain `[-infinity, +infinity]` and codomain `[-infinity, +infinity]`, for each element `x_i` in the input array `x`.
@@ -460,9 +464,9 @@ Calculates an implementation-dependent approximation to the hyperbolic cosine, h
- **out**: _<array>_
- - an array containing the hyperbolic cosine of each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the hyperbolic cosine of each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # divide(x1, x2, /)
+### divide(x1, x2, /)
Calculates the division for each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`. For floating-point arithmetic,
@@ -499,15 +503,15 @@ Calculates the division for each element `x1_i` of the input array `x1` with the
- **x2**: _<array>_
- - divisor input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - divisor input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the element-wise results. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise results. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # equal(x1, x2, /)
+### equal(x1, x2, /)
Computes the truth value of `x1_i == x2_i` for each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`.
@@ -519,7 +523,7 @@ Computes the truth value of `x1_i == x2_i` for each element `x1_i` of the input
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -527,7 +531,7 @@ Computes the truth value of `x1_i == x2_i` for each element `x1_i` of the input
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-### # exp(x, /)
+### exp(x, /)
Calculates an implementation-dependent approximation to the exponential function, having domain `[-infinity, +infinity]` and codomain `[+0, +infinity]`, for each element `x_i` of the input array `x` (`e` raised to the power of `x_i`, where `e` is the base of the natural logarithm).
@@ -549,15 +553,16 @@ Calculates an implementation-dependent approximation to the exponential function
- **out**: _<array>_
- - an array containing the evaluated exponential function result for each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the evaluated exponential function result for each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # expm1(x, /)
+### expm1(x, /)
Calculates an implementation-dependent approximation to `exp(x)-1`, having domain `[-infinity, +infinity]` and codomain `[-1, +infinity]`, for each element `x_i` of the input array `x`.
-.. note::
+```{note}
- The purpose of this function is to calculate `exp(x)-1.0` more accurately when `x` is close to zero. Accordingly, conforming implementations should avoid implementing this function as simply `exp(x)-1.0`. See FDLIBM, or some other IEEE 754-2019 compliant mathematical library, for a potential reference implementation.
+The purpose of this function is to calculate `exp(x)-1.0` more accurately when `x` is close to zero. Accordingly, conforming implementations should avoid implementing this function as simply `exp(x)-1.0`. See FDLIBM, or some other IEEE 754-2019 compliant mathematical library, for a potential reference implementation.
+```
#### Special Cases
@@ -577,9 +582,9 @@ Calculates an implementation-dependent approximation to `exp(x)-1`, having domai
- **out**: _<array>_
- - an array containing the evaluated result for each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the evaluated result for each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # floor(x, /)
+### floor(x, /)
Rounds each element `x_i` of the input array `x` to the greatest (i.e., closest to `+infinity`) integer-valued number that is not greater than `x_i`.
@@ -599,7 +604,7 @@ Rounds each element `x_i` of the input array `x` to the greatest (i.e., closest
- an array containing the rounded result for each element in `x`. The returned array must have the same data type as `x`.
-### # floor_divide(x1, x2, /)
+### floor_divide(x1, x2, /)
Rounds the result of dividing each element `x1_i` of the input array `x1` by the respective element `x2_i` of the input array `x2` to the greatest (i.e., closest to `+infinity`) integer-value number that is not greater than the division result.
@@ -611,15 +616,15 @@ Rounds the result of dividing each element `x1_i` of the input array `x1` by the
- **x2**: _<array>_
- - divisor input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - divisor input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the element-wise results. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise results. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # greater(x1, x2, /)
+### greater(x1, x2, /)
Computes the truth value of `x1_i > x2_i` for each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`.
@@ -631,7 +636,7 @@ Computes the truth value of `x1_i > x2_i` for each element `x1_i` of the input a
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -639,7 +644,7 @@ Computes the truth value of `x1_i > x2_i` for each element `x1_i` of the input a
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-### # greater_equal(x1, x2, /)
+### greater_equal(x1, x2, /)
Computes the truth value of `x1_i >= x2_i` for each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`.
@@ -651,7 +656,7 @@ Computes the truth value of `x1_i >= x2_i` for each element `x1_i` of the input
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -659,7 +664,7 @@ Computes the truth value of `x1_i >= x2_i` for each element `x1_i` of the input
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-### # isfinite(x, /)
+### isfinite(x, /)
Tests each element `x_i` of the input array `x` to determine if finite (i.e., not `NaN` and not equal to positive or negative infinity).
@@ -675,7 +680,7 @@ Tests each element `x_i` of the input array `x` to determine if finite (i.e., no
- an array containing test results. An element `out_i` is `True` if `x_i` is finite and `False` otherwise. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-### # isinf(x, /)
+### isinf(x, /)
Tests each element `x_i` of the input array `x` to determine if equal to positive or negative infinity.
@@ -691,7 +696,7 @@ Tests each element `x_i` of the input array `x` to determine if equal to positiv
- an array containing test results. An element `out_i` is `True` if `x_i` is either positive or negative infinity and `False` otherwise. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-### # isnan(x, /)
+### isnan(x, /)
Tests each element `x_i` of the input array `x` to determine whether the element is `NaN`.
@@ -707,7 +712,7 @@ Tests each element `x_i` of the input array `x` to determine whether the element
- an array containing test results. An element `out_i` is `True` if `x_i` is `NaN` and `False` otherwise. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-### # less(x1, x2, /)
+### less(x1, x2, /)
Computes the truth value of `x1_i < x2_i` for each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`.
@@ -719,7 +724,7 @@ Computes the truth value of `x1_i < x2_i` for each element `x1_i` of the input a
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -727,7 +732,7 @@ Computes the truth value of `x1_i < x2_i` for each element `x1_i` of the input a
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-### # less_equal(x1, x2, /)
+### less_equal(x1, x2, /)
Computes the truth value of `x1_i <= x2_i` for each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`.
@@ -739,7 +744,7 @@ Computes the truth value of `x1_i <= x2_i` for each element `x1_i` of the input
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -747,7 +752,7 @@ Computes the truth value of `x1_i <= x2_i` for each element `x1_i` of the input
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-### # log(x, /)
+### log(x, /)
Calculates an implementation-dependent approximation to the natural (base `e`) logarithm, having domain `[0, +infinity]` and codomain `[-infinity, +infinity]`, for each element `x_i` of the input array `x`.
@@ -769,15 +774,16 @@ Calculates an implementation-dependent approximation to the natural (base `e`) l
- **out**: _<array>_
- - an array containing the evaluated natural logarithm for each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the evaluated natural logarithm for each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # log1p(x, /)
+### log1p(x, /)
Calculates an implementation-dependent approximation to `log(1+x)`, where `log` refers to the natural (base `e`) logarithm, having domain `[-1, +infinity]` and codomain `[-infinity, +infinity]`, for each element `x_i` of the input array `x`.
-.. note::
+```{note}
- The purpose of this function is to calculate `log(1+x)` more accurately when `x` is close to zero. Accordingly, conforming implementations should avoid implementing this function as simply `log(1+x)`. See FDLIBM, or some other IEEE 754-2019 compliant mathematical library, for a potential reference implementation.
+The purpose of this function is to calculate `log(1+x)` more accurately when `x` is close to zero. Accordingly, conforming implementations should avoid implementing this function as simply `log(1+x)`. See FDLIBM, or some other IEEE 754-2019 compliant mathematical library, for a potential reference implementation.
+```
#### Special Cases
@@ -798,9 +804,9 @@ Calculates an implementation-dependent approximation to `log(1+x)`, where `log`
- **out**: _<array>_
- - an array containing the evaluated result for each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the evaluated result for each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # log2(x, /)
+### log2(x, /)
Calculates an implementation-dependent approximation to the base `2` logarithm, having domain `[0, +infinity]` and codomain `[-infinity, +infinity]`, for each element `x_i` of the input array `x`.
@@ -822,9 +828,9 @@ Calculates an implementation-dependent approximation to the base `2` logarithm,
- **out**: _<array>_
- - an array containing the evaluated base `2` logarithm for each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the evaluated base `2` logarithm for each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # log10(x, /)
+### log10(x, /)
Calculates an implementation-dependent approximation to the base `10` logarithm, having domain `[0, +infinity]` and codomain `[-infinity, +infinity]`, for each element `x_i` of the input array `x`.
@@ -846,9 +852,9 @@ Calculates an implementation-dependent approximation to the base `10` logarithm,
- **out**: _<array>_
- - an array containing the evaluated base `10` logarithm for each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the evaluated base `10` logarithm for each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # logical_and(x1, x2, /)
+### logical_and(x1, x2, /)
Computes the logical AND for each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`. Zeros should be considered the equivalent of `False`, while non-zeros should be considered the equivalent of `True`.
@@ -860,7 +866,7 @@ Computes the logical AND for each element `x1_i` of the input array `x1` with th
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -868,7 +874,7 @@ Computes the logical AND for each element `x1_i` of the input array `x1` with th
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-### # logical_not(x, /)
+### logical_not(x, /)
Computes the logical NOT for each element `x_i` of the input array `x`. Zeros should be considered the equivalent of `False`, while non-zeros should be considered the equivalent of `True`.
@@ -884,7 +890,7 @@ Computes the logical NOT for each element `x_i` of the input array `x`. Zeros sh
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-### # logical_or(x1, x2, /)
+### logical_or(x1, x2, /)
Computes the logical OR for each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`. Zeros should be considered the equivalent of `False`, while non-zeros should be considered the equivalent of `True`.
@@ -896,7 +902,7 @@ Computes the logical OR for each element `x1_i` of the input array `x1` with the
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -904,7 +910,7 @@ Computes the logical OR for each element `x1_i` of the input array `x1` with the
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-### # logical_xor(x1, x2, /)
+### logical_xor(x1, x2, /)
Computes the logical XOR for each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`. Zeros should be considered the equivalent of `False`, while non-zeros should be considered the equivalent of `True`.
@@ -916,7 +922,7 @@ Computes the logical XOR for each element `x1_i` of the input array `x1` with th
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -924,7 +930,7 @@ Computes the logical XOR for each element `x1_i` of the input array `x1` with th
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-### # multiply(x1, x2, /)
+### multiply(x1, x2, /)
Calculates the product for each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`. For floating-point arithmetic,
@@ -940,9 +946,10 @@ Calculates the product for each element `x1_i` of the input array `x1` with the
- If `x1_i` is a nonzero finite number and `x2_i` is either `+infinity` or `-infinity`, the result is a signed infinity with the mathematical sign determined by the rule already stated above.
- In the remaining cases, where neither `infinity` nor `NaN` is involved, the product must be computed and rounded to the nearest representable value according to IEEE 754-2019 and a supported rounding mode. If the magnitude is too large to represent, the result is an `infinity` of appropriate mathematical sign. If the magnitude is too small to represent, the result is a zero of appropriate mathematical sign.
-.. note::
+```{note}
- Floating-point multiplication is not always associative due to finite precision.
+Floating-point multiplication is not always associative due to finite precision.
+```
#### Parameters
@@ -952,15 +959,15 @@ Calculates the product for each element `x1_i` of the input array `x1` with the
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the element-wise products. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise products. The returned array must have a data type determined by {ref}`type-promotion`.
-### # negative(x, /)
+### negative(x, /)
Computes the numerical negative of each element `x_i` (i.e., `y_i = -x_i`) of the input array `x`.
@@ -974,9 +981,9 @@ Computes the numerical negative of each element `x_i` (i.e., `y_i = -x_i`) of th
- **out**: _<array>_
- - an array containing the evaluated result for each element in `x`. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the evaluated result for each element in `x`. The returned array must have a data type determined by {ref}`type-promotion`.
-### # not_equal(x1, x2, /)
+### not_equal(x1, x2, /)
Computes the truth value of `x1_i != x2_i` for each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`.
@@ -988,7 +995,7 @@ Computes the truth value of `x1_i != x2_i` for each element `x1_i` of the input
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
@@ -996,7 +1003,7 @@ Computes the truth value of `x1_i != x2_i` for each element `x1_i` of the input
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
-### # positive(x, /)
+### positive(x, /)
Computes the numerical positive of each element `x_i` (i.e., `y_i = +x_i`) of the input array `x`.
@@ -1012,7 +1019,7 @@ Computes the numerical positive of each element `x_i` (i.e., `y_i = +x_i`) of th
- an array containing the evaluated result for each element in `x`. The returned array must have the same data type as `x`.
-### # pow(x1, x2, /)
+### pow(x1, x2, /)
Calculates an implementation-dependent approximation of exponentiation by raising each element `x1_i` (the base) of the input array `x1` to the power of `x2_i` (the exponent), where `x2_i` is the corresponding element of the input array `x2`.
@@ -1051,15 +1058,15 @@ Calculates an implementation-dependent approximation of exponentiation by raisin
- **x2**: _<array>_
- - second input array whose elements correspond to the exponentiation exponent. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - second input array whose elements correspond to the exponentiation exponent. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the element-wise results. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
-### # remainder(x1, x2, /)
+### remainder(x1, x2, /)
Returns the remainder of division for each element `x1_i` of the input array `x1` and the respective element `x2_i` of the input array `x2`.
@@ -1071,15 +1078,15 @@ Returns the remainder of division for each element `x1_i` of the input array `x1
- **x2**: _<array>_
- - divisor input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - divisor input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the element-wise results. Each element-wise result must have the same sign as the respective element `x2_i`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise results. Each element-wise result must have the same sign as the respective element `x2_i`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # round(x, /)
+### round(x, /)
Rounds each element `x_i` of the input array `x` to the nearest integer-valued number.
@@ -1100,7 +1107,7 @@ Rounds each element `x_i` of the input array `x` to the nearest integer-valued n
- an array containing the rounded result for each element in `x`. The returned array must have the same data type as `x`.
-### # sign(x, /)
+### sign(x, /)
Returns an indication of the sign of a number for each element `x_i` of the input array `x`.
@@ -1122,7 +1129,7 @@ Returns an indication of the sign of a number for each element `x_i` of the inpu
- an array containing the evaluated result for each element in `x`. The returned array must have the same data type as `x`.
-### # sin(x, /)
+### sin(x, /)
Calculates an implementation-dependent approximation to the sine, having domain `(-infinity, +infinity)` and codomain `[-1, +1]`, for each element `x_i` of the input array `x`. Each element `x_i` is assumed to be expressed in radians.
@@ -1143,9 +1150,9 @@ Calculates an implementation-dependent approximation to the sine, having domain
- **out**: _<array>_
- - an array containing the sine of each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the sine of each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # sinh(x, /)
+### sinh(x, /)
Calculates an implementation-dependent approximation to the hyperbolic sine, having domain `[-infinity, +infinity]` and codomain `[-infinity, +infinity]`, for each element `x_i` of the input array `x`.
@@ -1167,9 +1174,9 @@ Calculates an implementation-dependent approximation to the hyperbolic sine, hav
- **out**: _<array>_
- - an array containing the hyperbolic sine of each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the hyperbolic sine of each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # square(x, /)
+### square(x, /)
Squares (`x_i * x_i`) each element `x_i` of the input array `x`.
@@ -1183,9 +1190,9 @@ Squares (`x_i * x_i`) each element `x_i` of the input array `x`.
- **out**: _<array>_
- - an array containing the evaluated result for each element in `x`. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the evaluated result for each element in `x`. The returned array must have a data type determined by {ref}`type-promotion`.
-### # sqrt(x, /)
+### sqrt(x, /)
Calculates the square root, having domain `[0, +infinity]` and codomain `[0, +infinity]`, for each element `x_i` of the input array `x`. After rounding, each result should be indistinguishable from the infinitely precise result (as required by IEEE 754).
@@ -1207,11 +1214,11 @@ Calculates the square root, having domain `[0, +infinity]` and codomain `[0, +in
- **out**: _<array>_
- - an array containing the square root of each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the square root of each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # subtract(x1, x2, /)
+### subtract(x1, x2, /)
-Calculates the difference for each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`. The result of `x1_i - x2_i` must be the same as `x1_i + (-x2_i)` and is thus governed by the same floating-point rules as addition (see [`add()`](#add)).
+Calculates the difference for each element `x1_i` of the input array `x1` with the respective element `x2_i` of the input array `x2`. The result of `x1_i - x2_i` must be the same as `x1_i + (-x2_i)` and is thus governed by the same floating-point rules as addition (see [`add()`](#addx1-x2-)).
#### Parameters
@@ -1221,15 +1228,15 @@ Calculates the difference for each element `x1_i` of the input array `x1` with t
- **x2**: _<array>_
- - second input array. Must be compatible with `x1` (see :ref:`broadcasting`).
+ - second input array. Must be compatible with `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array containing the element-wise differences. The returned array must have a data type determined by :ref:`type-promotion`.
+ - an array containing the element-wise differences. The returned array must have a data type determined by {ref}`type-promotion`.
-### # tan(x, /)
+### tan(x, /)
Calculates an implementation-dependent approximation to the tangent, having domain `(-infinity, +infinity)` and codomain `(-infinity, +infinity)`, for each element `x_i` of the input array `x`. Each element `x_i` is assumed to be expressed in radians.
@@ -1250,9 +1257,9 @@ Calculates an implementation-dependent approximation to the tangent, having doma
- **out**: _<array>_
- - an array containing the tangent of each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the tangent of each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # tanh(x, /)
+### tanh(x, /)
Calculates an implementation-dependent approximation to the hyperbolic tangent, having domain `[-infinity, +infinity]` and codomain `[-1, +1]`, for each element `x_i` of the input array `x`.
@@ -1274,9 +1281,9 @@ Calculates an implementation-dependent approximation to the hyperbolic tangent,
- **out**: _<array>_
- - an array containing the hyperbolic tangent of each element in `x`. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
+ - an array containing the hyperbolic tangent of each element in `x`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
-### # trunc(x, /)
+### trunc(x, /)
Rounds each element `x_i` of the input array `x` to the integer-valued number that is closest to but no greater than `x_i`.
diff --git a/spec/API_specification/function_and_method_signatures.md b/spec/API_specification/function_and_method_signatures.md
index 1aa25091f..1c51b47ea 100644
--- a/spec/API_specification/function_and_method_signatures.md
+++ b/spec/API_specification/function_and_method_signatures.md
@@ -1,4 +1,4 @@
-.. _function-and-method-signatures:
+(function-and-method-signatures)=
# Function and method signatures
@@ -13,12 +13,13 @@ Function signatures in this standard adhere to the following:
_Rationale: existing libraries have incompatible conventions, and using names
of positional parameters is not normal/recommended practice._
- .. note::
+ ```{note}
- Positional-only parameters are only available in Python >= 3.8. Libraries
- still supporting 3.7 or 3.6 may consider making the API standard-compliant
- namespace >= 3.8. Alternatively, they can add guidance to their users in the
- documentation to use the functions as if they were positional-only.
+ Positional-only parameters are only available in Python >= 3.8. Libraries
+ still supporting 3.7 or 3.6 may consider making the API standard-compliant
+ namespace >= 3.8. Alternatively, they can add guidance to their users in the
+ documentation to use the functions as if they were positional-only.
+ ```
2. Optional parameters must be
[keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
diff --git a/spec/API_specification/index.rst b/spec/API_specification/index.rst
index bba493e32..7f3f069e3 100644
--- a/spec/API_specification/index.rst
+++ b/spec/API_specification/index.rst
@@ -12,7 +12,6 @@ API specification
indexing
data_types
type_promotion
- casting
broadcasting
creation_functions
manipulation_functions
diff --git a/spec/API_specification/indexing.md b/spec/API_specification/indexing.md
index 792896e06..b1fd6b171 100644
--- a/spec/API_specification/indexing.md
+++ b/spec/API_specification/indexing.md
@@ -1,4 +1,4 @@
-.. _indexing:
+(indexing)=
# Indexing
@@ -16,21 +16,24 @@ To index a single array axis, an array must support standard Python indexing rul
- **Valid** nonnegative indices must reside on the half-open interval `[0, n)`.
- .. note::
+ ```{note}
- This specification does not require bounds checking. The behavior for out-of-bounds integer indices is left unspecified.
+ This specification does not 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::
+ ```{note}
- 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.
+ 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.
+ ```
- **Valid** negative indices must reside on the closed interval `[-n, -1]`.
- .. note::
+ ```{note}
- This specification does not require bounds checking. The behavior for out-of-bounds integer indices is left unspecified.
+ This specification does not 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`.
@@ -56,9 +59,10 @@ A[i::k]
A[i:j:k]
```
-.. note::
+```{note}
- 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__`).
+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__`).
+```
Using a slice to index a single array axis must select `m` elements with index values
@@ -84,13 +88,15 @@ such that
j > i + (m-1)k
```
-.. note::
+```{note}
- 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`.
+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`.
+```
-.. note::
+```{note}
- 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.
+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.
+```
Slice syntax must have the following defaults. Let `n` be the axis (dimension) size.
@@ -106,17 +112,19 @@ Using a slice to index a single array axis must adhere to the following rules. L
- 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).
-.. note::
+```{note}
- 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).
+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).
- _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._
+_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._
+```
-.. note::
+```{note}
- 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).
+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).
- _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._
+_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._
+```
## Multi-axis Indexing
@@ -124,9 +132,10 @@ Multi-dimensional arrays must extend the concept of single-axis indexing to mult
- 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]`).
- .. note::
+ ```{note}
- In Python, `x[(exp1, exp2, ..., expN)]` is equivalent to `x[exp1, exp2, ..., expN]`; the latter is syntactic sugar for the former.
+ In Python, `x[(exp1, exp2, ..., expN)]` is equivalent to `x[exp1, exp2, ..., expN]`; the latter is syntactic sugar for the former.
+ ```
- Providing a single nonnegative integer `i` as a single-axis index must index the same elements as the slice `i:i+1`.
@@ -144,11 +153,12 @@ Multi-dimensional arrays must extend the concept of single-axis indexing to mult
- The result of multi-axis indexing must be an array of the same data type as the indexed array.
-.. note::
+```{note}
- 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.
+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.
- _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._
+_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._
+```
## Boolean Array Indexing
@@ -156,9 +166,10 @@ An array must support indexing via a **single** `M`-dimensional boolean array `B
- 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)]`.
- .. note::
+ ```{note}
- 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`.
+ 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`.
+ ```
- If `N < M`, then an `IndexError` exception must be raised.
diff --git a/spec/API_specification/linear_algebra_functions.md b/spec/API_specification/linear_algebra_functions.md
index 464dddeee..06b50faa2 100644
--- a/spec/API_specification/linear_algebra_functions.md
+++ b/spec/API_specification/linear_algebra_functions.md
@@ -6,11 +6,13 @@ A conforming implementation of the array API standard must provide and support t
- 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.
- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
-- Broadcasting semantics must follow the semantics defined in :ref:`broadcasting`.
-- Unless stated otherwise, functions must support the data types defined in :ref:`data-types`.
-- Unless stated otherwise, functions must adhere to the type promotion rules defined in :ref:`type-promotion`.
+- Broadcasting semantics must follow the semantics defined in {ref}`broadcasting`.
+- Unless stated otherwise, functions must support the data types defined in {ref}`data-types`.
+- Unless stated otherwise, functions must adhere to the type promotion rules defined in {ref}`type-promotion`.
- Unless stated otherwise, floating-point operations must adhere to IEEE 754-2019.
+## Objects in API
+
### # cholesky()
@@ -39,7 +41,7 @@ Returns the cross product of 3-element vectors. If `x1` and `x2` are multi-dimen
- **out**: _<array>_
- - an array containing the cross products. The returned array must have a data type determined by :ref:`type-promotion` rules.
+ - an array containing the cross products. The returned array must have a data type determined by {ref}`type-promotion` rules.
### # det(x, /)
@@ -55,7 +57,7 @@ Returns the determinant of a square matrix (or stack of square matrices) `x`.
- **out**: _<array>_
- - 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.
+ - 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.
### # diagonal(x, /, *, axis1=0, axis2=1, offset=0)
@@ -165,7 +167,7 @@ Computes the matrix or vector norm of `x`.
- **keepdims**: _bool_
- - 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`.
+ - 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`.
- **ord**: _Optional\[ int, float, Literal\[ inf, -inf, 'fro', 'nuc' ] ]_
@@ -235,7 +237,7 @@ Computes the outer product of two vectors `x1` and `x2`.
- **out**: _<array>_
- - 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.
+ - 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.
### # pinv()
diff --git a/spec/API_specification/manipulation_functions.md b/spec/API_specification/manipulation_functions.md
index 6e168a242..1d8b0546e 100644
--- a/spec/API_specification/manipulation_functions.md
+++ b/spec/API_specification/manipulation_functions.md
@@ -6,7 +6,9 @@ A conforming implementation of the array API standard must provide and support t
- 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.
- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
-- Unless stated otherwise, functions must adhere to the type promotion rules defined in :ref:`type-promotion`.
+- Unless stated otherwise, functions must adhere to the type promotion rules defined in {ref}`type-promotion`.
+
+## Objects in API
@@ -30,9 +32,10 @@ Joins a sequence of arrays along an existing axis.
- an output array containing the concatenated values. If the input arrays have different data types, normal [type promotion rules](type_promotion.md) must apply. If the input arrays have the same data type, the output array must have the same data type as the input arrays.
- .. note::
+ ```{note}
- This specification leaves type promotion between data type families (i.e., `intxx` and `floatxx`) unspecified.
+ This specification leaves type promotion between data type families (i.e., `intxx` and `floatxx`) unspecified.
+ ```
### # expand_dims(x, axis, /)
@@ -158,6 +161,7 @@ Joins a sequence of arrays along a new axis.
- an output array having rank `N+1`, where `N` is the rank (number of dimensions) of `x`. If the input arrays have different data types, normal [type promotion rules](type_promotion.md) must apply. If the input arrays have the same data type, the output array must have the same data type as the input arrays.
- .. note::
+ ```{note}
- This specification leaves type promotion between data type families (i.e., `intxx` and `floatxx`) unspecified.
\ No newline at end of file
+ This specification leaves type promotion between data type families (i.e., `intxx` and `floatxx`) unspecified.
+ ```
\ No newline at end of file
diff --git a/spec/API_specification/searching_functions.md b/spec/API_specification/searching_functions.md
index 9468f190a..7975e672a 100644
--- a/spec/API_specification/searching_functions.md
+++ b/spec/API_specification/searching_functions.md
@@ -1,4 +1,4 @@
-.. _searching-functions:
+(searching-functions)=
# Searching Functions
@@ -8,9 +8,11 @@ A conforming implementation of the array API standard must provide and support t
- 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.
- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
-- Broadcasting semantics must follow the semantics defined in :ref:`broadcasting`.
-- Unless stated otherwise, functions must support the data types defined in :ref:`data-types`.
-- Unless stated otherwise, functions must adhere to the type promotion rules defined in :ref:`type-promotion`.
+- Broadcasting semantics must follow the semantics defined in {ref}`broadcasting`.
+- Unless stated otherwise, functions must support the data types defined in {ref}`data-types`.
+- Unless stated otherwise, functions must adhere to the type promotion rules defined in {ref}`type-promotion`.
+
+## Objects in API
@@ -30,7 +32,7 @@ Returns the indices of the maximum values along a specified axis. When the maxim
- **keepdims**: _bool_
- - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
+ - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
#### Returns
@@ -54,7 +56,7 @@ Returns the indices of the minimum values along a specified axis. When the minim
- **keepdims**: _bool_
- - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
+ - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
#### Returns
@@ -86,18 +88,18 @@ Returns elements chosen from `x1` or `x2` depending on `condition`.
- **condition**: _<array<bool>>_
- - when `True`, yield `x1_i`; otherwise, yield `x2_i`. Must be compatible with `x1` and `x2` (see :ref:`broadcasting`).
+ - when `True`, yield `x1_i`; otherwise, yield `x2_i`. Must be compatible with `x1` and `x2` (see {ref}`broadcasting`).
- **x1**: _<array>_
- - first input array. Must be compatible with `condition` and `x2` (see :ref:`broadcasting`).
+ - first input array. Must be compatible with `condition` and `x2` (see {ref}`broadcasting`).
- **x2**: _<array>_
- - second input array. Must be compatible with `condition` and `x1` (see :ref:`broadcasting`).
+ - second input array. Must be compatible with `condition` and `x1` (see {ref}`broadcasting`).
#### Returns
- **out**: _<array>_
- - an array with elements from `x1` where `condition` is `True`, and elements from `x2` elsewhere. The returned array must have a data type determined by :ref:`type-promotion` rules.
\ No newline at end of file
+ - an array with elements from `x1` where `condition` is `True`, and elements from `x2` elsewhere. The returned array must have a data type determined by {ref}`type-promotion` rules.
\ No newline at end of file
diff --git a/spec/API_specification/set_functions.md b/spec/API_specification/set_functions.md
index 3e7c95898..81547e733 100644
--- a/spec/API_specification/set_functions.md
+++ b/spec/API_specification/set_functions.md
@@ -6,7 +6,9 @@ A conforming implementation of the array API standard must provide and support t
- 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.
- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
-- Unless stated otherwise, functions must support the data types defined in :ref:`data-types`.
+- Unless stated otherwise, functions must support the data types defined in {ref}`data-types`.
+
+## Objects in API
diff --git a/spec/API_specification/sorting_functions.md b/spec/API_specification/sorting_functions.md
index 2cc31a082..64e581b39 100644
--- a/spec/API_specification/sorting_functions.md
+++ b/spec/API_specification/sorting_functions.md
@@ -6,7 +6,9 @@ A conforming implementation of the array API standard must provide and support t
- 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.
- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
-- Unless stated otherwise, functions must support the data types defined in :ref:`data-types`.
+- Unless stated otherwise, functions must support the data types defined in {ref}`data-types`.
+
+## Objects in API
diff --git a/spec/API_specification/statistical_functions.md b/spec/API_specification/statistical_functions.md
index c4c034761..c120a7cde 100644
--- a/spec/API_specification/statistical_functions.md
+++ b/spec/API_specification/statistical_functions.md
@@ -6,11 +6,13 @@ A conforming implementation of the array API standard must provide and support t
- 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.
- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
-- Broadcasting semantics must follow the semantics defined in :ref:`broadcasting`.
-- Unless stated otherwise, functions must support the data types defined in :ref:`data-types`.
-- Unless stated otherwise, functions must adhere to the type promotion rules defined in :ref:`type-promotion`.
+- Broadcasting semantics must follow the semantics defined in {ref}`broadcasting`.
+- Unless stated otherwise, functions must support the data types defined in {ref}`data-types`.
+- Unless stated otherwise, functions must adhere to the type promotion rules defined in {ref}`type-promotion`.
- Unless stated otherwise, floating-point operations must adhere to IEEE 754-2019.
+## Objects in API
+
### # max(x, /, *, axis=None, keepdims=False)
@@ -29,7 +31,7 @@ Calculates the maximum value of the input array `x`.
- **keepdims**: _bool_
- - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
+ - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
#### Returns
@@ -53,7 +55,7 @@ Calculates the arithmetic mean of the input array `x`.
- **keepdims**: _bool_
- - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
+ - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
#### Returns
@@ -77,7 +79,7 @@ Calculates the minimum value of the input array `x`.
- **keepdims**: _bool_
- - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
+ - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
#### Returns
@@ -101,7 +103,7 @@ Calculates the product of input array `x` elements.
- **keepdims**: _bool_
- - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
+ - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
#### Returns
@@ -129,7 +131,7 @@ Calculates the standard deviation of the input array `x`.
- **keepdims**: _bool_
- - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
+ - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
#### Returns
@@ -153,7 +155,7 @@ Calculates the sum of the input array `x`.
- **keepdims**: _bool_
- - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
+ - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
#### Returns
@@ -181,7 +183,7 @@ Calculates the variance of the input array `x`.
- **keepdims**: _bool_
- - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
+ - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
#### Returns
diff --git a/spec/API_specification/type_promotion.md b/spec/API_specification/type_promotion.md
index c2831e04c..f599629a2 100644
--- a/spec/API_specification/type_promotion.md
+++ b/spec/API_specification/type_promotion.md
@@ -1,4 +1,4 @@
-.. _type-promotion:
+(type-promotion)=
# Type Promotion Rules
@@ -8,10 +8,11 @@ A conforming implementation of the array API standard must implement the followi
A conforming implementation of the array API standard may support additional type promotion rules beyond those described in this specification.
-.. note::
+```{note}
- Type codes are used here to keep tables readable; they are not part of the standard.
- In code, use the data type objects specified in :ref:`data-types` (e.g., `int16` rather than `'i2'`).
+Type codes are used here to keep tables readable; they are not part of the standard.
+In code, use the data type objects specified in {ref}`data-types` (e.g., `int16` rather than `'i2'`).
+```
## Rules
@@ -76,7 +77,8 @@ A conforming implementation of the array API standard may support additional typ
- Non-array ("scalar") operands must not participate in type promotion.
-.. note::
+```{note}
- Mixed integer and floating-point type promotion rules are not specified
- because behavior varies between implementations.
\ No newline at end of file
+Mixed integer and floating-point type promotion rules are not specified
+because behavior varies between implementations.
+```
diff --git a/spec/API_specification/utility_functions.md b/spec/API_specification/utility_functions.md
index a6bbe2939..54f1ccb24 100644
--- a/spec/API_specification/utility_functions.md
+++ b/spec/API_specification/utility_functions.md
@@ -6,11 +6,13 @@ A conforming implementation of the array API standard must provide and support t
- 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.
- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
-- Broadcasting semantics must follow the semantics defined in :ref:`broadcasting`.
-- Unless stated otherwise, functions must support the data types defined in :ref:`data-types`.
-- Unless stated otherwise, functions must adhere to the type promotion rules defined in :ref:`type-promotion`.
+- Broadcasting semantics must follow the semantics defined in {ref}`broadcasting`.
+- Unless stated otherwise, functions must support the data types defined in {ref}`data-types`.
+- Unless stated otherwise, functions must adhere to the type promotion rules defined in {ref}`type-promotion`.
- Unless stated otherwise, floating-point operations must adhere to IEEE 754-2019.
+## Objects in API
+
### # all(x, /, *, axis=None, keepdims=False)
@@ -29,7 +31,7 @@ Tests whether all input array elements evaluate to `True` along a specified axis
- **keepdims**: _bool_
- - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
+ - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
#### Returns
@@ -53,7 +55,7 @@ Tests whether any input array element evaluates to `True` along a specified axis
- **keepdims**: _bool_
- - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
+ - If `True`, the reduced axes (dimensions) 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 reduced axes (dimensions) must not be included in the result. Default: `False`.
#### Returns
diff --git a/spec/assumptions.md b/spec/assumptions.md
index 20267d2db..3a315e6cd 100644
--- a/spec/assumptions.md
+++ b/spec/assumptions.md
@@ -1,3 +1,5 @@
+(Assumptions)=
+
# Assumptions
## Hardware and software environments
@@ -18,7 +20,7 @@ made in the API standard. For example, JIT compilers may require output dtypes
of functions to be predictable from input dtypes only rather than input values.
-.. _assumptions-dependencies:
+(assumptions-dependencies)=
## Dependencies
@@ -55,8 +57,7 @@ likely unwilling to make significant backwards-incompatible changes for the
purpose of conforming to this standard. Therefore it is assumed that the
standard will be made available in a new namespace within each library, or the
library will provide a way to retrieve a module or module-like object that
-adheres to this standard. See [How to adopt this API](purpose_and_scope.html#how-to-adopt-this-api)
-for more details.
+adheres to this standard. See {ref}`how-to-adopt-this-api` for more details.
## Production code & interactive use
diff --git a/spec/benchmark_suite.md b/spec/benchmark_suite.md
index 770008857..da203cbf6 100644
--- a/spec/benchmark_suite.md
+++ b/spec/benchmark_suite.md
@@ -1 +1,3 @@
# Benchmark suite
+
+Adding a benchmark suite is planned in the future.
\ No newline at end of file
diff --git a/spec/conf.py b/spec/conf.py
index 0b9c3a336..98dd78c5c 100644
--- a/spec/conf.py
+++ b/spec/conf.py
@@ -15,7 +15,6 @@
# sys.path.insert(0, os.path.abspath('.'))
import sphinx_material
-from recommonmark.transform import AutoStructify
# -- Project information -----------------------------------------------------
@@ -24,7 +23,7 @@
author = 'Consortium for Python Data API Standards'
# The full version, including alpha/beta/rc tags
-release = '0.1-dev'
+release = '2021.01-DRAFT'
# -- General configuration ---------------------------------------------------
@@ -33,7 +32,7 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
- 'recommonmark',
+ 'myst_parser',
'sphinx.ext.extlinks',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
@@ -49,6 +48,8 @@
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
+# MyST options
+myst_heading_anchors = 3
# -- Options for HTML output -------------------------------------------------
@@ -112,7 +113,7 @@
"nav_links": [
{"href": "index", "internal": True, "title": "Array API standard"},
{
- "href": "https://link-to-consortium-website",
+ "href": "https://data-apis.org",
"internal": False,
"title": "Consortium for Python Data API Standards",
},
@@ -142,19 +143,3 @@
"durole": ("http://docutils.sourceforge.net/docs/ref/rst/" "roles.html#%s", ""),
"dudir": ("http://docutils.sourceforge.net/docs/ref/rst/" "directives.html#%s", ""),
}
-
-
-# Enable eval_rst in markdown
-def setup(app):
- app.add_config_value(
- "recommonmark_config",
- {"enable_math": True, "enable_inline_math": True, "enable_eval_rst": True},
- True,
- )
- app.add_transform(AutoStructify)
- app.add_object_type(
- "confval",
- "confval",
- objname="configuration value",
- indextemplate="pair: %s; configuration value",
- )
diff --git a/spec/design_topics/C_API.md b/spec/design_topics/C_API.md
index 49f655d93..96575ba63 100644
--- a/spec/design_topics/C_API.md
+++ b/spec/design_topics/C_API.md
@@ -1,8 +1,8 @@
-.. _C-api:
+(C-API)=
# C API
-Use of a C API is out of scope for this array API, as mentioned in :ref:`Scope`.
+Use of a C API is out of scope for this array API, as mentioned in {ref}`Scope`.
There are a lot of libraries that do use such an API - in particular via Cython code
or via direct usage of the NumPy C API. When the maintainers of such libraries
want to use this array API standard to support multiple types of arrays, they
@@ -14,33 +14,35 @@ and hence the goal is to make other array types work without converting to a
visualization package), then other array types can simply be handled by converting
to the supported array type.
-.. note::
-
- Often a zero-copy conversion to `numpy.ndarray` is possible, at least for CPU arrays.
- If that's the case, this may be a good way to support other array types.
- The main difficulty in that case will be getting the return array type right - however,
- this standard does provide a Python-level API for array construction that should allow
- doing this. A relevant question is if it's possible to know with
- certainty that a conversion will be zero-copy. This may indeed be
- possible, see :ref:`data-interchange`.
+```{note}
+Often a zero-copy conversion to `numpy.ndarray` is possible, at least for CPU arrays.
+If that's the case, this may be a good way to support other array types.
+The main difficulty in that case will be getting the return array type right - however,
+this standard does provide a Python-level API for array construction that should allow
+doing this. A relevant question is if it's possible to know with
+certainty that a conversion will be zero-copy. This may indeed be
+possible, see {ref}`data-interchange`.
+```
## Example situations for C/Cython usage
### Situation 1: a Python package that is mostly pure Python, with a limited number of Cython extensions
-.. note::
+```{note}
- Projects in this situation include Statsmodels, scikit-bio and QuTiP
+Projects in this situation include Statsmodels, scikit-bio and QuTiP
+```
Main strategy: documentation. The functionality using Cython code will not support other array types (or only with conversion to/from `numpy.ndarray`), which can be documented per function.
### Situation 2: a Python package that contains a lot of Cython code
-.. note::
+```{note}
- Projects in this situation include scikit-learn and scikit-image
+Projects in this situation include scikit-learn and scikit-image
+```
Main strategy: add support for other array types _per submodule_. This keeps it manageable to explain to the user which functionality does and doesn't have support.
@@ -49,9 +51,10 @@ Longer term: specific support for particular array types (e.g. `cupy.ndarray` ca
### Situation 3: a Python package that uses the NumPy or Python C API directly
-.. note::
+```{note}
- Projects in this situation include SciPy and Astropy
+Projects in this situation include SciPy and Astropy
+```
Strategy: similar to _situation 2_, but the number of submodules that can support all array types may be limited.
diff --git a/spec/design_topics/accuracy.md b/spec/design_topics/accuracy.md
index 7590cbc49..1ef6005d0 100644
--- a/spec/design_topics/accuracy.md
+++ b/spec/design_topics/accuracy.md
@@ -1,4 +1,4 @@
-.. _accuracy:
+(accuracy)=
# Accuracy
@@ -50,25 +50,28 @@ This specification does **not** precisely define the behavior of the following f
except to require specific results for certain argument values that represent boundary cases of interest.
-.. note::
+```{note}
- To help readers identify functions lacking precisely defined accuracy behavior, this specification uses the phrase "implementation-dependent approximation" in function descriptions.
+To help readers identify functions lacking precisely defined accuracy behavior, this specification uses the phrase "implementation-dependent approximation" in function descriptions.
+```
For other argument values, these functions should compute approximations to the results of respective mathematical functions; however, this specification recognizes that array libraries may be constrained by underlying hardware and/or seek to optimize performance over absolute accuracy and, thus, allows some latitude in the choice of approximation algorithms.
Although the specification leaves the choice of algorithms to the implementation, this specification recommends (but does not specify) that implementations use the approximation algorithms for IEEE 754-2019 arithmetic contained in [FDLIBM](http://www.netlib.org/fdlibm), the freely distributable mathematical library from Sun Microsystems, or some other comparable IEEE 754-2019 compliant mathematical library.
-.. note::
+```{note}
- With exception of a few mathematical functions, returning results which are indistinguishable from correctly rounded infinitely precise results is difficult, if not impossible, to achieve due to the algorithms involved, the limits of finite-precision, and error propagation. However, this specification recognizes that numerical accuracy alignment among array libraries is desirable in order to ensure portability and reproducibility. Accordingly, for each mathematical function, the specification test suite includes test values which span a function's domain and reports the average and maximum deviation from either a designated standard implementation (e.g., an arbitrary precision arithmetic implementation) or an average computed across a subset of known array library implementations. Such reporting aids users who need to know how accuracy varies among libraries and developers who need to check the validity of their implementations.
+With exception of a few mathematical functions, returning results which are indistinguishable from correctly rounded infinitely precise results is difficult, if not impossible, to achieve due to the algorithms involved, the limits of finite-precision, and error propagation. However, this specification recognizes that numerical accuracy alignment among array libraries is desirable in order to ensure portability and reproducibility. Accordingly, for each mathematical function, the specification test suite includes test values which span a function's domain and reports the average and maximum deviation from either a designated standard implementation (e.g., an arbitrary precision arithmetic implementation) or an average computed across a subset of known array library implementations. Such reporting aids users who need to know how accuracy varies among libraries and developers who need to check the validity of their implementations.
+```
## Statistical Functions
This specification does not specify accuracy requirements for statistical functions; however, this specification does expect that a conforming implementation of the array API standard will make a best-effort attempt to ensure that its implementations are theoretically sound and numerically robust.
-.. note::
+```{note}
- In order for an array library to pass the specification test suite, an array library's statistical function implementations must satisfy certain bare-minimum accuracy requirements (e.g., accurate summation of a small set of positive integers). Unfortunately, imposing more rigorous accuracy requirements is not possible without severely curtailing possible implementation algorithms and unduly increasing implementation complexity.
+In order for an array library to pass the specification test suite, an array library's statistical function implementations must satisfy certain bare-minimum accuracy requirements (e.g., accurate summation of a small set of positive integers). Unfortunately, imposing more rigorous accuracy requirements is not possible without severely curtailing possible implementation algorithms and unduly increasing implementation complexity.
+```
## Linear Algebra
diff --git a/spec/design_topics/copies_views_and_mutation.md b/spec/design_topics/copies_views_and_mutation.md
index 0c1601851..cc48508a2 100644
--- a/spec/design_topics/copies_views_and_mutation.md
+++ b/spec/design_topics/copies_views_and_mutation.md
@@ -1,4 +1,4 @@
-.. _copyview-mutability:
+(copyview-mutability)=
# Copy-view behaviour and mutability
@@ -71,6 +71,7 @@ This leaves the problem of the initial example - with this API standard it
remains possible to write code that will not work the same for all array
libraries. This is something that the user must be careful about.
-.. note::
+```{note}
- It is recommended that users avoid any mutating operations when a view may be involved."
+It is recommended that users avoid any mutating operations when a view may be involved.
+```
diff --git a/spec/design_topics/data_interchange.md b/spec/design_topics/data_interchange.md
index e3218947f..6e2046133 100644
--- a/spec/design_topics/data_interchange.md
+++ b/spec/design_topics/data_interchange.md
@@ -1,9 +1,9 @@
-.. _data-interchange:
+(data-interchange)=
# Data interchange mechanisms
This section discusses the mechanism to convert one type of array into another.
-As discussed in the :ref:`assumptions-dependencies ` section,
+As discussed in the {ref}`assumptions-dependencies ` section,
_functions_ provided by an array library are not expected to operate on
_array types_ implemented by another library. Instead, the array can be
converted to a "native" array type.
@@ -14,7 +14,7 @@ The interchange mechanism must offer the following:
in an implementation-independent manner.
_Rationale: any number of libraries must be able to exchange data, and no
particular package must be needed to do so._
-2. Support for all dtypes in this API standard (see :ref:`data-types`).
+2. Support for all dtypes in this API standard (see {ref}`data-types`).
3. Device support. It must be possible to determine on what device the array
that is to be converted lives.
_Rationale: there are CPU-only, GPU-only, and multi-device array types;
@@ -34,41 +34,42 @@ The best candidate for this protocol is DLPack. See the
[RFC to adopt DLPack](https://github.com/data-apis/consortium-feedback/issues/1)
for details.
-.. note::
+```{note}
- The main alternatives to DLPack are device-specific methods:
+The main alternatives to DLPack are device-specific methods:
- - The [buffer protocol](https://docs.python.org/dev/c-api/buffer.html) on CPU
- - `__cuda_array_interface__` for CUDA, specified in the Numba documentation
- [here](https://numba.pydata.org/numba-doc/0.43.0/cuda/cuda_array_interface.html)
- (Python-side only at the moment)
+- The [buffer protocol](https://docs.python.org/dev/c-api/buffer.html) on CPU
+- `__cuda_array_interface__` for CUDA, specified in the Numba documentation
+ [here](https://numba.pydata.org/numba-doc/0.43.0/cuda/cuda_array_interface.html)
+ (Python-side only at the moment)
- An issue with device-specific protocols are: if two libraries both
- support multiple device types, in which order should the protocols be
- tried? A growth in the number of protocols to support each time a new
- device gets supported by array libraries (e.g. TPUs, AMD GPUs, emerging
- hardware accelerators) also seems undesirable.
-
- In addition to the above argument, it is also clear from adoption
- patterns that DLPack has the widest support. The buffer protocol, despite
- being a lot older and standardized as part of Python itself via PEP 3118,
- hardly has any support from array libraries. CPU interoperability is
- mostly dealt with via the NumPy-specific `__array__` (which, when called,
- means the object it is attached to must return a `numpy.ndarray`
- containing the data the object holds).
+An issue with device-specific protocols are: if two libraries both
+support multiple device types, in which order should the protocols be
+tried? A growth in the number of protocols to support each time a new
+device gets supported by array libraries (e.g. TPUs, AMD GPUs, emerging
+hardware accelerators) also seems undesirable.
+In addition to the above argument, it is also clear from adoption
+patterns that DLPack has the widest support. The buffer protocol, despite
+being a lot older and standardized as part of Python itself via PEP 3118,
+hardly has any support from array libraries. CPU interoperability is
+mostly dealt with via the NumPy-specific `__array__` (which, when called,
+means the object it is attached to must return a `numpy.ndarray`
+containing the data the object holds).
+```
TODO: design an appropriate Python API for DLPACK (`to_dlpack` followed by `from_dlpack` is a little clunky, we'd like it to work more like the buffer protocol does on CPU, with a single constructor function).
TODO: specify the expected behaviour with copy/view/move/shared-memory semantics in detail.
-.. note::
+```{note}
- If an array that is accessed via the interchange protocol lives on a
- device that the requesting library does not support, one of two things
- must happen: moving data to another device, or raising an exception.
- Device transfers are typically expensive, hence doing that silently can
- lead to hard to detect performance issues. Hence it is recommended to
- raise an exception, and let the user explicitly enable device transfers
- via, e.g., a `force=False` keyword that they can set to `True`.
+If an array that is accessed via the interchange protocol lives on a
+device that the requesting library does not support, one of two things
+must happen: moving data to another device, or raising an exception.
+Device transfers are typically expensive, hence doing that silently can
+lead to hard to detect performance issues. Hence it is recommended to
+raise an exception, and let the user explicitly enable device transfers
+via, e.g., a `force=False` keyword that they can set to `True`.
+```
diff --git a/spec/design_topics/device_support.md b/spec/design_topics/device_support.md
index a5538db38..9a1666514 100644
--- a/spec/design_topics/device_support.md
+++ b/spec/design_topics/device_support.md
@@ -1,4 +1,4 @@
-.. _device-support:
+(device-support)=
# Device support
diff --git a/spec/design_topics/static_typing.md b/spec/design_topics/static_typing.md
index 7b4d3e3ad..cc744ca0f 100644
--- a/spec/design_topics/static_typing.md
+++ b/spec/design_topics/static_typing.md
@@ -3,7 +3,7 @@
Good support for static typing both in array libraries and array-consuming
code is desirable. Therefore the exact type or set of types for each
parameter, keyword and return value is specified for functions and methods -
-see :ref:`function-and-method-signatures`. That section specifies arrays
+see {ref}`function-and-method-signatures`. That section specifies arrays
simply as `array`; what that means is dealt with in this section.
Introducing type annotations in libraries became more relevant only when
@@ -15,7 +15,7 @@ problem in individual array libraries yet.
An `array` type annotation can mean either the type of one specific array
object, or some superclass or typing Protocol - as long as it is consistent
-with the array object specified in :ref:`array-object`. To illustrate by
+with the array object specified in {ref}`array-object`. To illustrate by
example:
```python
@@ -37,7 +37,7 @@ should both be fine. There may be other variations possible. Also note that
this standard does not require that input and output array types are the same
(they're expected to be defined in the same library though). Given that
array libraries don't have to be aware of other types of arrays defined in
-other libraries (see :ref:`assumptions-dependencies`), this should be enough
+other libraries (see {ref}`assumptions-dependencies`), this should be enough
for a single array library.
That said, an array-consuming library aiming to support multiple array types
diff --git a/spec/future_API_evolution.md b/spec/future_API_evolution.md
index 30a833d4b..5a5ffcdd5 100644
--- a/spec/future_API_evolution.md
+++ b/spec/future_API_evolution.md
@@ -1,4 +1,4 @@
-.. _future-API-evolution:
+(future-API-evolution)=
# Future API standard evolution
@@ -25,7 +25,7 @@ Any exceptions must have strong rationales, and be clearly documented in the upd
API specification.
-.. _api-versioning:
+(api-versioning)=
## Versioning
@@ -44,15 +44,17 @@ No utilities for dealing with version comparisons need to be provided; given
the format simple string comparisons with Python operators (`=-`, `<`, `>=`,
etc.) will be enough.
-.. note::
+```{note}
- Rationale for the `yyyy.mm` versioning scheme choice:
- the API will be provided as part of a library, which already has a versioning
- scheme (typically PEP 440 compliant and in the form `major.minor.bugfix`),
- and a way to access it via `module.__version__`. The API standard version is
- completely independent from the package version. Given the standardization
- process, it resembles a C/C++ versioning scheme (e.g. `C99`, `C++14`) more
- than Python package versioning.
+Rationale for the `yyyy.mm` versioning scheme choice:
+the API will be provided as part of a library, which already has a versioning
+scheme (typically PEP 440 compliant and in the form `major.minor.bugfix`),
+and a way to access it via `module.__version__`. The API standard version is
+completely independent from the package version. Given the standardization
+process, it resembles a C/C++ versioning scheme (e.g. `C99`, `C++14`) more
+than Python package versioning.
+```
The frequency of releasing a new version of an API standard will likely be at
-regular intervals and on the order of one year, however no assumption on frequency of new versions appearing must be made.
+regular intervals and on the order of one year, however no assumption on
+frequency of new versions appearing must be made.
\ No newline at end of file
diff --git a/spec/index.rst b/spec/index.rst
index aaf20aeec..e7a466413 100644
--- a/spec/index.rst
+++ b/spec/index.rst
@@ -1,8 +1,3 @@
-.. Python array API standard documentation master file, created by
- sphinx-quickstart on Mon Jun 15 16:55:00 2020.
- You can adapt this file completely to your liking, but it should at least
- contain the root `toctree` directive.
-
Python array API standard
=========================
diff --git a/spec/purpose_and_scope.md b/spec/purpose_and_scope.md
index 64e436bad..b2afc7f39 100644
--- a/spec/purpose_and_scope.md
+++ b/spec/purpose_and_scope.md
@@ -31,13 +31,13 @@ sure all existing array libraries can adopt this API.
This document aims to standardize functionality that exists in most/all array
libraries and either is commonly used or is needed for
consistency/completeness. Usage is determined via analysis of downstream
-libraries, see :ref:`usage-data`. An example of consistency is: there are
+libraries, see {ref}`usage-data`. An example of consistency is: there are
functional equivalents for all Python operators (including the rarely used
ones).
Beyond usage and consistency, there's a set of use cases that inform the API
design to ensure it's fit for a wide range of users and situations - see
-:ref:`use-cases`.
+{ref}`use-cases`.
A question that may arise when reading this document is: _"what about
functionality that's not present in this document?_ This:
@@ -48,13 +48,13 @@ functionality that's not present in this document?_ This:
- may indicate that that functionality, if present in a particular array
library, is unlikely to be present in all other libraries
-.. note::
-
- This document is ready for wider community review, but still contains a
- number of TODOs, and is expected to change and evolve before a first
- official release. See :ref:`future-API-evolution` for proposed
- versioning.
+```{note}
+This document is ready for wider community review, but still contains a
+number of TODOs, and is expected to change and evolve before a first
+official release. See {ref}`future-API-evolution` for proposed
+versioning.
+```
### History
@@ -84,6 +84,8 @@ array and tensor libraries. That resulted in this document, describing that
API.
+(Scope)=
+
## Scope (includes out-of-scope / non-goals)
This section outlines what is in scope and out of scope for this API standard.
@@ -158,7 +160,7 @@ extensions are dealt with_):
_Rationale: this is an important topic for some array-consuming libraries,
but there is no widely shared C/Cython API and hence it doesn't make sense at
this point in time to standardize anything. See
- [the C API section](design_topics/C_API.md) for more details._
+ the [C API section](design_topics/C_API.md) for more details._
4. Standardization of these dtypes is out of scope: bfloat16, complex, extended
precision floating point, datetime, string, object and void dtypes.
@@ -308,16 +310,14 @@ relevant:
- [Apache Arrow](https://arrow.apache.org/)
-## High-level API overview
-
-
-
## How to read this document
For guidance on how to read and understand the type annotations included in this specification, consult the Python [documentation](https://docs.python.org/3/library/typing.html).
+(how-to-adopt-this-api)=
+
## How to adopt this API
Most (all) existing array libraries will find something in this API standard
@@ -332,7 +332,7 @@ namespace (e.g. `import package_name.array_api`). This has two issues though:
1. Array-consuming libraries that want to support multiple array libraries
then have to explicitly import each library.
2. It is difficult to _version_ the array API standard implementation (see
- :ref:`api-versioning`).
+ {ref}`api-versioning`).
To address both issues, a uniform way must be provided by a conforming
implementation to access the API namespace, namely a method on the array object:
@@ -348,21 +348,22 @@ request a specific API version:
xp = x.__array_namespace__(api_version='2020.10')
```
-.. note::
+```{note}
- This is inspired by [NEP 37](https://numpy.org/neps/nep-0037-array-module.html#how-to-use-get-array-module),
- however it avoids adding a dependency on NumPy or having to provide a
- separate package just to do `get_array_module(x)`
+This is inspired by [NEP 37](https://numpy.org/neps/nep-0037-array-module.html#how-to-use-get-array-module),
+however it avoids adding a dependency on NumPy or having to provide a
+separate package just to do `get_array_module(x)`
- NEP 37 is still in flux (it was just accepted by JAX and TensorFlow on an
- experimental basis), and it's possible that that should be accepted instead.
+NEP 37 is still in flux (it was just accepted by JAX and TensorFlow on an
+experimental basis), and it's possible that that should be accepted instead.
- TBD: a decision must be made on this topic before a first version of the
- standard can become final. We prefer to delay this decision, to see how
- NEP 37 adoption will work out.
+TBD: a decision must be made on this topic before a first version of the
+standard can become final. We prefer to delay this decision, to see how
+NEP 37 adoption will work out.
+```
The `xp` namespace must contain the array object and all functionality
-specified in :ref:`api-specification`. It may contain other functionality,
+specified in {ref}`api-specification`. It may contain other functionality,
however it is recommended not to add other functions or objects, because that
may make it harder for users to write code that will work with multiple array
libraries.
diff --git a/spec/usage_data.md b/spec/usage_data.md
index 5b7482929..7963333ff 100644
--- a/spec/usage_data.md
+++ b/spec/usage_data.md
@@ -1,4 +1,4 @@
-.. _usage-data:
+(usage-data)=
# Usage Data
diff --git a/spec/use_cases.md b/spec/use_cases.md
index 9562d9935..bd9f4888e 100644
--- a/spec/use_cases.md
+++ b/spec/use_cases.md
@@ -1,4 +1,4 @@
-.. _use-cases:
+(use-cases)=
# Use cases
@@ -21,13 +21,13 @@ considered, and then works out a few concrete use cases in more detail.
## Concrete use cases
-- :ref:`use-case-scipy`
-- :ref:`use-case-einops`
-- :ref:`use-case-xtensor`
-- :ref:`use-case-numba`
+- {ref}`use-case-scipy`
+- {ref}`use-case-einops`
+- {ref}`use-case-xtensor`
+- {ref}`use-case-numba`
-.. _use-case-scipy:
+(use-case-scipy)=
### Use case 1: add hardware accelerator and distributed support to SciPy
@@ -59,7 +59,7 @@ array implementation as a dependency.
It's clear that SciPy functionality that relies on compiled extensions (C,
C++, Cython, Fortran) directly can't easily be run on another array library
-than NumPy (see :ref:`C-api` for more details about this topic). Pure Python
+than NumPy (see [C API](design_topics/C_API.md) for more details about this topic). Pure Python
code can work though. There's two main possibilities:
1. Testing with another package, manually or in CI, and simply provide a list
@@ -115,14 +115,14 @@ freq, Pxx = signal.welch(x)
```
and have `freq`, `Pxx` be arrays of the same type and on the same device as `x`.
-.. note::
-
- This type of use case applies to many other libraries, from scikit-learn
- and scikit-image to domain-specific libraries like AstroPy and
- scikit-bio, to code written for a single purpose or user.
+```{note}
+This type of use case applies to many other libraries, from scikit-learn
+and scikit-image to domain-specific libraries like AstroPy and
+scikit-bio, to code written for a single purpose or user.
+```
-.. _use-case-einops:
+(use-case-einops)=
### Use case 2: simplify einops by removing the backend system
@@ -149,17 +149,19 @@ because the purpose it serves (providing a unified interface to array operations
of the supported backends) is already addressed by the array API standard.
Hence the complete `einops` code base could be close to 50% smaller, and easier to maintain or add to.
-.. note::
+```{note}
- Other libraries that have a similar backend system to support many array libraries
- include [TensorLy](https://github.com/tensorly/tensorly), the (now discontinued)
- multi-backend version of [Keras](https://github.com/keras-team/keras),
- [Unumpy](https://github.com/Quansight-Labs/unumpy) and
- [EagerPy](https://github.com/jonasrauber/eagerpy). Many end users and organizations will also have such glue code - it tends to be needed whenever one tries to support multiple
- array types in a single API.
+Other libraries that have a similar backend system to support many array libraries
+include [TensorLy](https://github.com/tensorly/tensorly), the (now discontinued)
+multi-backend version of [Keras](https://github.com/keras-team/keras),
+[Unumpy](https://github.com/Quansight-Labs/unumpy) and
+[EagerPy](https://github.com/jonasrauber/eagerpy). Many end users and
+organizations will also have such glue code - it tends to be needed whenever
+one tries to support multiple array types in a single API.
+```
-.. _use-case-xtensor:
+(use-case-xtensor)=
### Use case 3: adding a Python API to xtensor
@@ -183,14 +185,15 @@ don't fit their execution model.
This array API standard aims to provide an API that can be readily adopted,
without having to make the above-mentioned choices.
-.. note::
+```{note}
- XND is another array library, written in C, that still needs a Python API.
- Array implementations in other languages are often in a similar situation,
- and could translate this array API standard 1:1 to their language.
+XND is another array library, written in C, that still needs a Python API.
+Array implementations in other languages are often in a similar situation,
+and could translate this array API standard 1:1 to their language.
+```
-.. _use-case-numba:
+(use-case-numba)=
### Use case 4: make JIT compilation of array computations easier and more robust