diff --git a/.circleci/config.yml b/.circleci/config.yml
index 829dcbb64..f27e3e5ec 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -5,7 +5,7 @@ _defaults: &defaults
docker:
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
- - image: circleci/python:3.8.0
+ - image: cimg/python:3.10.2
working_directory: ~/repo
jobs:
@@ -19,7 +19,7 @@ jobs:
name: build docs
no_output_timeout: 25m
command: |
- sudo pip install -r requirements.txt
+ pip install -r requirements.txt
sphinx-build -b html -WT --keep-going spec build/latest -d doctrees
- store_artifacts:
path: build/latest
diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml
index 77357707a..67bafdb25 100644
--- a/.github/workflows/pages.yml
+++ b/.github/workflows/pages.yml
@@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@master
- uses: actions/setup-python@v2
with:
- python-version: '3.8' # Version range or exact version of a Python version to use, using semvers version range syntax.
+ python-version: '3.10.2' # Version range or exact version of a Python version to use, using semvers version range syntax.
architecture: 'x64' # (x64 or x86)
- run: |
# add dependencies based on the conf.py
diff --git a/spec/API_specification/linear_algebra_functions.md b/spec/API_specification/linear_algebra_functions.md
deleted file mode 100644
index ce911de6e..000000000
--- a/spec/API_specification/linear_algebra_functions.md
+++ /dev/null
@@ -1,142 +0,0 @@
-# Linear Algebra Functions
-
-> Array API specification for linear algebra functions.
-
-A conforming implementation of the array API standard must provide and support the following functions adhering to the following conventions.
-
-- 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`.
-- Unless stated otherwise, floating-point operations must adhere to IEEE 754-2019.
-
-## Objects in API
-
-
-
-(function-matmul)=
-### matmul(x1, x2, /)
-
-Computes the matrix product.
-
-```{note}
-
-The `matmul` function must implement the same semantics as the built-in `@` operator (see [PEP 465](https://www.python.org/dev/peps/pep-0465)).
-```
-
-#### Parameters
-
-- **x1**: _<array>_
-
- - first input array. Should have a numeric data type. Must have at least one dimension. If `x1` is one-dimensional having shape `(M,)` and `x2` has more than one dimension, `x1` must be promoted to a two-dimensional array by prepending `1` to its dimensions (i.e., must have shape `(1, M)`). After matrix multiplication, the prepended dimensions in the returned array must be removed. If `x1` has more than one dimension (including after vector-to-matrix promotion), `shape(x1)[:-2]` must be compatible with `shape(x2)[:-2]` (after vector-to-matrix promotion) (see {ref}`broadcasting`). If `x1` has shape `(..., M, K)`, the innermost two dimensions form matrices on which to perform matrix multiplication.
-
-- **x2**: _<array>_
-
- - second input array. Should have a numeric data type. Must have at least one dimension. If `x2` is one-dimensional having shape `(N,)` and `x1` has more than one dimension, `x2` must be promoted to a two-dimensional array by appending `1` to its dimensions (i.e., must have shape `(N, 1)`). After matrix multiplication, the appended dimensions in the returned array must be removed. If `x2` has more than one dimension (including after vector-to-matrix promotion), `shape(x2)[:-2]` must be compatible with `shape(x1)[:-2]` (after vector-to-matrix promotion) (see {ref}`broadcasting`). If `x2` has shape `(..., K, N)`, the innermost two dimensions form matrices on which to perform matrix multiplication.
-
-#### Returns
-
-- **out**: _<array>_
-
- - if both `x1` and `x2` are one-dimensional arrays having shape `(N,)`, a zero-dimensional array containing the inner product as its only element.
- - if `x1` is a two-dimensional array having shape `(M, K)` and `x2` is a two-dimensional array having shape `(K, N)`, a two-dimensional array containing the [conventional matrix product](https://en.wikipedia.org/wiki/Matrix_multiplication) and having shape `(M, N)`.
- - if `x1` is a one-dimensional array having shape `(K,)` and `x2` is an array having shape `(..., K, N)`, an array having shape `(..., N)` (i.e., prepended dimensions during vector-to-matrix promotion must be removed) and containing the [conventional matrix product](https://en.wikipedia.org/wiki/Matrix_multiplication).
- - if `x1` is an array having shape `(..., M, K)` and `x2` is a one-dimensional array having shape `(K,)`, an array having shape `(..., M)` (i.e., appended dimensions during vector-to-matrix promotion must be removed) and containing the [conventional matrix product](https://en.wikipedia.org/wiki/Matrix_multiplication).
- - if `x1` is a two-dimensional array having shape `(M, K)` and `x2` is an array having shape `(..., K, N)`, an array having shape `(..., M, N)` and containing the [conventional matrix product](https://en.wikipedia.org/wiki/Matrix_multiplication) for each stacked matrix.
- - if `x1` is an array having shape `(..., M, K)` and `x2` is a two-dimensional array having shape `(K, N)`, an array having shape `(..., M, N)` and containing the [conventional matrix product](https://en.wikipedia.org/wiki/Matrix_multiplication) for each stacked matrix.
- - if either `x1` or `x2` has more than two dimensions, an array having a shape determined by {ref}`broadcasting` `shape(x1)[:-2]` against `shape(x2)[:-2]` and containing the [conventional matrix product](https://en.wikipedia.org/wiki/Matrix_multiplication) for each stacked matrix.
-
- The returned array must have a data type determined by {ref}`type-promotion`.
-
-#### Raises
-
-- if either `x1` or `x2` is a zero-dimensional array.
-- if `x1` is a one-dimensional array having shape `(K,)`, `x2` is a one-dimensional array having shape `(L,)`, and `K != L`.
-- if `x1` is a one-dimensional array having shape `(K,)`, `x2` is an array having shape `(..., L, N)`, and `K != L`.
-- if `x1` is an array having shape `(..., M, K)`, `x2` is a one-dimensional array having shape `(L,)`, and `K != L`.
-- if `x1` is an array having shape `(..., M, K)`, `x2` is an array having shape `(..., L, N)`, and `K != L`.
-
-(function-matrix-transpose)=
-### matrix_transpose(x, /)
-
-Transposes a matrix (or a stack of matrices) `x`.
-
-#### Parameters
-
-- **x**: _<array>_
-
- - input array having shape `(..., M, N)` and whose innermost two dimensions form `MxN` matrices.
-
-#### Returns
-
-- **out**: _<array>_
-
- - an array containing the transpose for each matrix and having shape `(..., N, M)`. The returned array must have the same data type as `x`.
-
-(function-tensordot)=
-### tensordot(x1, x2, /, *, axes=2)
-
-Returns a tensor contraction of `x1` and `x2` over specific axes.
-
-#### Parameters
-
-- **x1**: _<array>_
-
- - first input array. Should have a numeric data type.
-
-- **x2**: _<array>_
-
- - second input array. Must be compatible with `x1` for all non-contracted axes (see {ref}`broadcasting`). Should have a numeric data type.
-
- ```{note}
- Contracted axes (dimensions) must not be broadcasted.
- ```
-
-- **axes**: _Union\[ int, Tuple\[ Sequence\[ int ], Sequence\[ int ] ] ]_
-
- - number of axes (dimensions) to contract or explicit sequences of axes (dimensions) for `x1` and `x2`, respectively.
-
- If `axes` is an `int` equal to `N`, then contraction must be performed over the last `N` axes of `x1` and the first `N` axes of `x2` in order. The size of each corresponding axis (dimension) must match. Must be nonnegative.
-
- - If `N` equals `0`, the result is the tensor (outer) product.
- - If `N` equals `1`, the result is the tensor dot product.
- - If `N` equals `2`, the result is the tensor double contraction (default).
-
- If `axes` is a tuple of two sequences `(x1_axes, x2_axes)`, the first sequence must apply to `x` and the second sequence to `x2`. Both sequences must have the same length. Each axis (dimension) `x1_axes[i]` for `x1` must have the same size as the respective axis (dimension) `x2_axes[i]` for `x2`. Each sequence must consist of unique (nonnegative) integers that specify valid axes for each respective array.
-
-#### Returns
-
-- **out**: _<array>_
-
- - an array containing the tensor contraction whose shape consists of the non-contracted axes (dimensions) of the first array `x1`, followed by the non-contracted axes (dimensions) of the second array `x2`. The returned array must have a data type determined by {ref}`type-promotion`.
-
-(function-vecdot)=
-### vecdot(x1, x2, /, *, axis=-1)
-
-Computes the (vector) dot product of two arrays.
-
-#### Parameters
-
-- **x1**: _<array>_
-
- - first input array. Should have a numeric data type.
-
-- **x2**: _<array>_
-
- - second input array. Must be compatible with `x1` (see {ref}`broadcasting`). Should have a numeric data type.
-
-- **axis**: _int_
-
- - axis over which to compute the dot product. Must be an integer on the interval `[-N, N)`, where `N` is the rank (number of dimensions) of the shape determined according to {ref}`broadcasting`. If specified as a negative integer, the function must determine the axis along which to compute the dot product by counting backward from the last dimension (where `-1` refers to the last dimension). By default, the function must compute the dot product over the last axis. Default: `-1`.
-
-#### Returns
-
-- **out**: _<array>_
-
- - if `x1` and `x2` are both one-dimensional arrays, a zero-dimensional containing the dot product; otherwise, a non-zero-dimensional array containing the dot products and having rank `N-1`, where `N` is the rank (number of dimensions) of the shape determined according to {ref}`broadcasting`. The returned array must have a data type determined by {ref}`type-promotion`.
-
-#### Raises
-
-- if provided an invalid `axis`.
-- if the size of the axis over which to compute the dot product is not the same for both `x1` and `x2`.
diff --git a/spec/API_specification/linear_algebra_functions.rst b/spec/API_specification/linear_algebra_functions.rst
new file mode 100644
index 000000000..c12144aa4
--- /dev/null
+++ b/spec/API_specification/linear_algebra_functions.rst
@@ -0,0 +1,29 @@
+Linear Algebra Functions
+========================
+
+ Array API specification for linear algebra functions.
+
+A conforming implementation of the array API standard must provide and support the following functions adhering to the following conventions.
+
+* Positional parameters must be `positional-only `_ 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 `_ 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`.
+* Unless stated otherwise, floating-point operations must adhere to IEEE 754-2019.
+
+.. currentmodule:: signatures.linear_algebra_functions
+
+Objects in API
+--------------
+..
+ NOTE: please keep the functions in alphabetical order
+
+.. autosummary::
+ :toctree: generated
+ :template: method.rst
+
+ matmul
+ matrix_transpose
+ tensordot
+ vecdot
diff --git a/spec/API_specification/signatures/array_object.py b/spec/API_specification/signatures/array_object.py
index 7a3c51322..87a055366 100644
--- a/spec/API_specification/signatures/array_object.py
+++ b/spec/API_specification/signatures/array_object.py
@@ -614,7 +614,7 @@ def __matmul__(self: array, other: array, /) -> array:
.. note::
- Results must equal the results returned by the equivalent function :ref:`function-matmul`.
+ Results must equal the results returned by the equivalent function :func:`signatures.linear_algebra_functions.matmul`.
**Raises**
diff --git a/spec/API_specification/signatures/linear_algebra_functions.py b/spec/API_specification/signatures/linear_algebra_functions.py
new file mode 100644
index 000000000..a7608b9ad
--- /dev/null
+++ b/spec/API_specification/signatures/linear_algebra_functions.py
@@ -0,0 +1,112 @@
+from ._types import Tuple, Union, array
+from collections.abc import Sequence
+
+def matmul(x1: array, x2: array, /) -> array:
+ """
+ Computes the matrix product.
+
+ .. note::
+ The ``matmul`` function must implement the same semantics as the built-in ``@`` operator (see `PEP 465 `_).
+
+ Parameters
+ ----------
+ x1: array
+ first input array. Should have a numeric data type. Must have at least one dimension. If ``x1`` is one-dimensional having shape ``(M,)`` and ``x2`` has more than one dimension, ``x1`` must be promoted to a two-dimensional array by prepending ``1`` to its dimensions (i.e., must have shape ``(1, M)``). After matrix multiplication, the prepended dimensions in the returned array must be removed. If ``x1`` has more than one dimension (including after vector-to-matrix promotion), ``shape(x1)[:-2]`` must be compatible with ``shape(x2)[:-2]`` (after vector-to-matrix promotion) (see :ref:`broadcasting`). If ``x1`` has shape ``(..., M, K)``, the innermost two dimensions form matrices on which to perform matrix multiplication.
+ x2: array
+ second input array. Should have a numeric data type. Must have at least one dimension. If ``x2`` is one-dimensional having shape ``(N,)`` and ``x1`` has more than one dimension, ``x2`` must be promoted to a two-dimensional array by appending ``1`` to its dimensions (i.e., must have shape ``(N, 1)``). After matrix multiplication, the appended dimensions in the returned array must be removed. If ``x2`` has more than one dimension (including after vector-to-matrix promotion), ``shape(x2)[:-2]`` must be compatible with ``shape(x1)[:-2]`` (after vector-to-matrix promotion) (see :ref:`broadcasting`). If ``x2`` has shape ``(..., K, N)``, the innermost two dimensions form matrices on which to perform matrix multiplication.
+
+ Returns
+ -------
+ out: array
+ - if both ``x1`` and ``x2`` are one-dimensional arrays having shape ``(N,)``, a zero-dimensional array containing the inner product as its only element.
+ - if ``x1`` is a two-dimensional array having shape ``(M, K)`` and ``x2`` is a two-dimensional array having shape ``(K, N)``, a two-dimensional array containing the `conventional matrix product `_ and having shape ``(M, N)``.
+ - if ``x1`` is a one-dimensional array having shape ``(K,)`` and ``x2`` is an array having shape ``(..., K, N)``, an array having shape ``(..., N)`` (i.e., prepended dimensions during vector-to-matrix promotion must be removed) and containing the `conventional matrix product `_.
+ - if ``x1`` is an array having shape ``(..., M, K)`` and ``x2`` is a one-dimensional array having shape ``(K,)``, an array having shape ``(..., M)`` (i.e., appended dimensions during vector-to-matrix promotion must be removed) and containing the `conventional matrix product `_.
+ - if ``x1`` is a two-dimensional array having shape ``(M, K)`` and ``x2`` is an array having shape ``(..., K, N)``, an array having shape ``(..., M, N)`` and containing the `conventional matrix product `_ for each stacked matrix.
+ - if ``x1`` is an array having shape ``(..., M, K)`` and ``x2`` is a two-dimensional array having shape ``(K, N)``, an array having shape ``(..., M, N)`` and containing the `conventional matrix product `_ for each stacked matrix.
+ - if either ``x1`` or ``x2`` has more than two dimensions, an array having a shape determined by :ref:`broadcasting` ``shape(x1)[:-2]`` against ``shape(x2)[:-2]`` and containing the `conventional matrix product `_ for each stacked matrix.
+
+ The returned array must have a data type determined by :ref:`type-promotion`.
+
+
+ **Raises**
+
+ - if either ``x1`` or ``x2`` is a zero-dimensional array.
+ - if ``x1`` is a one-dimensional array having shape ``(K,)``, ``x2`` is a one-dimensional array having shape ``(L,)``, and ``K != L``.
+ - if ``x1`` is a one-dimensional array having shape ``(K,)``, ``x2`` is an array having shape ``(..., L, N)``, and ``K != L``.
+ - if ``x1`` is an array having shape ``(..., M, K)``, ``x2`` is a one-dimensional array having shape ``(L,)``, and ``K != L``.
+ - if ``x1`` is an array having shape ``(..., M, K)``, ``x2`` is an array having shape ``(..., L, N)``, and ``K != L``.
+ """
+
+def matrix_transpose(x: array, /) -> array:
+ """
+ Transposes a matrix (or a stack of matrices) ``x``.
+
+ Parameters
+ ----------
+ x: array
+ input array having shape ``(..., M, N)`` and whose innermost two dimensions form ``MxN`` matrices.
+
+ Returns
+ -------
+ out: array
+ an array containing the transpose for each matrix and having shape ``(..., N, M)``. The returned array must have the same data type as ``x``.
+ """
+
+def tensordot(x1: array, x2: array, /, *, axes: Union[int, Tuple[Sequence[int], Sequence[int]]] = 2) -> array:
+ """
+ Returns a tensor contraction of ``x1`` and ``x2`` over specific axes.
+
+ Parameters
+ ----------
+ x1: array
+ first input array. Should have a numeric data type.
+ x2: array
+ second input array. Must be compatible with ``x1`` for all non-contracted axes (see :ref:`broadcasting`). Should have a numeric data type.
+
+ .. note::
+ Contracted axes (dimensions) must not be broadcasted.
+
+ axes: Union[int, Tuple[Sequence[int], Sequence[int]]]
+ number of axes (dimensions) to contract or explicit sequences of axes (dimensions) for ``x1`` and ``x2``, respectively.
+
+ If ``axes`` is an ``int`` equal to ``N``, then contraction must be performed over the last ``N`` axes of ``x1`` and the first ``N`` axes of ``x2`` in order. The size of each corresponding axis (dimension) must match. Must be nonnegative.
+
+ - If ``N`` equals ``0``, the result is the tensor (outer) product.
+ - If ``N`` equals ``1``, the result is the tensor dot product.
+ - If ``N`` equals ``2``, the result is the tensor double contraction (default).
+
+ If ``axes`` is a tuple of two sequences ``(x1_axes, x2_axes)``, the first sequence must apply to ``x`` and the second sequence to ``x2``. Both sequences must have the same length. Each axis (dimension) ``x1_axes[i]`` for ``x1`` must have the same size as the respective axis (dimension) ``x2_axes[i]`` for ``x2``. Each sequence must consist of unique (nonnegative) integers that specify valid axes for each respective array.
+
+ Returns
+ -------
+ out: array
+ an array containing the tensor contraction whose shape consists of the non-contracted axes (dimensions) of the first array ``x1``, followed by the non-contracted axes (dimensions) of the second array ``x2``. The returned array must have a data type determined by :ref:`type-promotion`.
+ """
+
+def vecdot(x1: array, x2: array, /, *, axis: int = -1) -> array:
+ """
+ Computes the (vector) dot product of two arrays.
+
+ Parameters
+ ----------
+ x1: array
+ first input array. Should have a numeric data type.
+ x2: array
+ second input array. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a numeric data type.
+ axis:int
+ axis over which to compute the dot product. Must be an integer on the interval ``[-N, N)``, where ``N`` is the rank (number of dimensions) of the shape determined according to :ref:`broadcasting`. If specified as a negative integer, the function must determine the axis along which to compute the dot product by counting backward from the last dimension (where ``-1`` refers to the last dimension). By default, the function must compute the dot product over the last axis. Default: ``-1``.
+
+ Returns
+ -------
+ out: array
+ if ``x1`` and ``x2`` are both one-dimensional arrays, a zero-dimensional containing the dot product; otherwise, a non-zero-dimensional array containing the dot products and having rank ``N-1``, where ``N`` is the rank (number of dimensions) of the shape determined according to :ref:`broadcasting`. The returned array must have a data type determined by :ref:`type-promotion`.
+
+
+ **Raises**
+
+ - if provided an invalid ``axis``.
+ - if the size of the axis over which to compute the dot product is not the same for both ``x1`` and ``x2``.
+ """
+
+__all__ = ['matmul', 'matrix_transpose', 'tensordot', 'vecdot']
diff --git a/spec/extensions/linear_algebra_functions.md b/spec/extensions/linear_algebra_functions.md
index 6bdcdbd78..3d26436cc 100644
--- a/spec/extensions/linear_algebra_functions.md
+++ b/spec/extensions/linear_algebra_functions.md
@@ -258,7 +258,7 @@ Returns the multiplicative inverse of a square matrix (or a stack of square matr
(function-linalg-matmul)=
### linalg.matmul(x1, x2, /)
-Alias for {ref}`function-matmul`.
+Alias for {func}`signatures.linear_algebra_functions.matmul`.
(function-linalg-matrix-norm)=
### linalg.matrix_norm(x, /, *, keepdims=False, ord='fro')
@@ -352,7 +352,7 @@ Returns the rank (i.e., number of non-zero singular values) of a matrix (or a st
(function-linalg-matrix-transpose)=
### linalg.matrix_transpose(x, /)
-Alias for {ref}`function-matrix-transpose`.
+Alias for {func}`signatures.linear_algebra_functions.matrix_transpose`.
(function-linalg-outer)=
### linalg.outer(x1, x2, /)
@@ -537,7 +537,7 @@ Returns the singular values of a matrix (or a stack of matrices) `x`.
(function-linalg-tensordot)=
### linalg.tensordot(x1, x2, /, *, axes=2)
-Alias for {ref}`function-tensordot`.
+Alias for {func}`signatures.linear_algebra_functions.tensordot`.
(function-linalg-trace)=
### linalg.trace(x, /, *, offset=0)
@@ -575,7 +575,7 @@ Returns the sum along the specified diagonals of a matrix (or a stack of matrice
(function-linalg-vecdot)=
### linalg.vecdot(x1, x2, /, *, axis=-1)
-Alias for {ref}`function-vecdot`.
+Alias for {func}`signatures.linear_algebra_functions.vecdot`.
(function-linalg-vector-norm)=
### linalg.vector_norm(x, /, *, axis=None, keepdims=False, ord=2)