Skip to content

PR: Add note for functions that are not compatible with static memory allocation #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8815028
Add note for functions that doesn't support boolean array indexing
steff456 Apr 22, 2021
2757e73
clarify the notes
steff456 Apr 26, 2021
b98c908
remove note from where function
steff456 Apr 26, 2021
ad3156d
Some small fixes to function signatures to make them valid Python (#174)
asmeurer Apr 27, 2021
e6d827a
Update API specification for creation and manipulation functions (#167)
rgommers Apr 27, 2021
b0f4ca0
Change deployment to github actions for github pages (#176)
steff456 May 3, 2021
0c5d913
Specify the input types for logaddexp (#175)
asmeurer May 3, 2021
ffc4d0c
Create a unique admonition for data-dependent shapes
rgommers May 3, 2021
2e759ef
Add data type guidance (#173)
kgryte May 3, 2021
204e283
Rewrite note with the given suggestions
steff456 May 6, 2021
4d74293
Make axis keyword to squeeze() positional (#100)
rgommers May 11, 2021
76730f1
Add Cholesky function specification (#110)
kgryte May 12, 2021
059e4fe
Add slogdet specification (#111)
kgryte May 12, 2021
9893373
Add specification for computing the pseudo-inverse (linalg: pinv) (#118)
kgryte May 12, 2021
36fd440
Add specification for computing the dot product (linalg: vecdot) (#137)
kgryte May 12, 2021
0768fc8
Add specification for computing a tensor contraction (linalg: tensord…
kgryte May 12, 2021
5677c24
Add linalg solve function specification (#115)
kgryte May 12, 2021
56ce784
Add SVD function specification (#114)
kgryte May 12, 2021
e32a6a8
Add specification for returning the least-squares solution to a linea…
kgryte May 12, 2021
a33a710
Add specification for computing the qr factorization (#126)
kgryte May 12, 2021
3add230
Add specification for computing singular values using singular value …
kgryte May 12, 2021
fe3b410
Add specification for computing the eigenvalues and eigenvectors of a…
kgryte May 12, 2021
a1d00d5
Add specification for computing the eigenvalues of a symmetric matrix…
kgryte May 12, 2021
7557e69
Add specification for computing the matrix product (linalg: matmul) (…
kgryte May 12, 2021
e0c0c87
Add specification for computing the number of non-zero singular value…
kgryte May 12, 2021
30b0391
Add matrix_power specification (#112)
kgryte May 12, 2021
d00d255
Fix meshgrid formatting (#178)
leofang May 12, 2021
83c6be3
Add linear algebra design principles (#149)
kgryte May 12, 2021
c2ecccc
Fix matmul formatting (#179)
leofang May 12, 2021
9efd284
Fix norm formatting (#181)
leofang May 12, 2021
03a2b41
Move linear algebra APIs to an extension (#182)
kgryte May 20, 2021
0429693
Fix a typo in the spec (#184)
asmeurer May 20, 2021
2472846
Add a requirement for the producer of a DLPack capsule(#186)
leofang May 25, 2021
e3927fd
Improve documentation for `stream` argument to `__dlpack__` (#185)
rgommers May 26, 2021
192b4d7
Clarify that constants are Python scalars (#169)
kgryte May 31, 2021
63c592e
Fix typo in definition of __lshift__ (#190)
tomwhite Jun 4, 2021
4c8142c
Merge remote-tracking branch 'steff/add-boolean-indexing-notes' into …
kgryte Jun 7, 2021
0a61b94
Update notes
kgryte Jun 7, 2021
c9541aa
Add document stub
kgryte Jun 7, 2021
b1fd96e
Add admonition for boolean array indexing and update reference
kgryte Jun 7, 2021
9f336ae
Add explainer on data-dependent output shapes
kgryte Jun 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
on:
on:
push:
branches:
- main
pull_request:
branches:
branches:
- "**"
jobs:
run:
Expand Down Expand Up @@ -33,9 +33,7 @@ jobs:
if-no-files-found: error
- name: Deploy
if: ${{ github.ref == 'refs/heads/main'}}
uses: JamesIves/[email protected]
env:
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_BRANCH: main # The branch the action should deploy from.
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: build
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
162 changes: 96 additions & 66 deletions spec/API_specification/array_object.md

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions spec/API_specification/constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

> Array API specification for constants.

A conforming implementation of the array API standard must provide and support the following constants.
A conforming implementation of the array API standard must provide and support the following constants adhering to the following conventions.

- Each constant must have a Python floating-point data type (i.e., `float`) and be provided as a Python scalar value.

<!-- NOTE: please keep the constants in alphabetical order -->

Expand All @@ -11,7 +13,7 @@ A conforming implementation of the array API standard must provide and support t
(constant-e)=
### e

Euler's constant.
IEEE 754 floating-point representation of Euler's constant.

```text
e = 2.71828182845904523536028747135266249775724709369995...
Expand All @@ -30,7 +32,7 @@ IEEE 754 floating-point representation of Not a Number (`NaN`).
(constant-pi)=
### pi

The mathematical constant `π`.
IEEE 754 floating-point representation of the mathematical constant `π`.

```text
pi = 3.1415926535897932384626433...
Expand Down
50 changes: 25 additions & 25 deletions spec/API_specification/creation_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A conforming implementation of the array API standard must provide and support t
<!-- NOTE: please keep the functions in alphabetical order -->

(function-arange)=
### arange(start, /, *, stop=None, step=1, dtype=None, device=None)
### arange(start, /, stop=None, step=1, *, dtype=None, device=None)

Returns evenly spaced values within the half-open interval `[start, stop)` as a one-dimensional array.

Expand All @@ -33,11 +33,11 @@ This function cannot guarantee that the interval does not include the `stop` val

- **step**: _Union\[ int, float ]_

- the distance between two adjacent elements (`out[i+1] - out[i]`). Default: `1`.
- the distance between two adjacent elements (`out[i+1] - out[i]`). Must not be `0`; may be negative, this results in an empty array if `stop >= start`. Default: `1`.

- **dtype**: _Optional\[ &lt;dtype&gt; ]_

- output array data type. If `dtype` is `None`, the output array data type must be the default floating-point data type. Default: `None`.
- output array data type. If `dtype` is `None`, the output array data type must be inferred from `start`, `stop` and `step`. If those are all integers, the output array dtype must be the default integer dtype; if one or more have type `float`, then the output array dtype must be the default floating-point data type. Default: `None`.

- **device**: _Optional\[ &lt;device&gt; ]_

Expand All @@ -47,7 +47,7 @@ This function cannot guarantee that the interval does not include the `stop` val

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

- a one-dimensional array containing evenly spaced values. The length of the output array must be `ceil((stop-start)/step)`.
- a one-dimensional array containing evenly spaced values. The length of the output array must be `ceil((stop-start)/step)` if `stop - start` and `step` have the same sign, and length 0 otherwise.


(function-asarray)=
Expand All @@ -68,7 +68,7 @@ Convert the input to an array.

- **dtype**: _Optional\[ &lt;dtype&gt; ]_

- output array data type. If `dtype` is `None`, the output array data type must be inferred from the data type(s) in `obj`. Default: `None`.
- output array data type. If `dtype` is `None`, the output array data type must be inferred from the data type(s) in `obj`. If all input values are Python scalars, then if they're all `bool` the output dtype will be `bool`; if they're a mix of `bool`s and `int` the output dtype will be the default integer data type; if they contain `float`s the output dtype will be the default floating-point data type. Default: `None`.

- **device**: _Optional\[ &lt;device&gt; ]_

Expand All @@ -86,7 +86,7 @@ Convert the input to an array.


(function-empty)=
### empty(shape, /, *, dtype=None, device=None)
### empty(shape, *, dtype=None, device=None)

Returns an uninitialized array having a specified `shape`.

Expand Down Expand Up @@ -136,19 +136,19 @@ Returns an uninitialized array with the same `shape` as an input array `x`.
- an array having the same shape as `x` and containing uninitialized data.

(function-eye)=
### eye(N, /, *, M=None, k=0, dtype=None, device=None)
### eye(n_rows, n_cols=None, /, *, k=0, dtype=None, device=None)

Returns a two-dimensional array with ones on the `k`th diagonal and zeros elsewhere.

#### Parameters

- **N**: _int_
- **n_rows**: _int_

- number of rows in the output array.

- **M**: _Optional\[ int ]_
- **n_cols**: _Optional\[ int ]_

- number of columns in the output array. If `None`, the default number of columns in the output array is `N`. Default: `None`.
- number of columns in the output array. If `None`, the default number of columns in the output array is equal to `n_rows`. Default: `None`.

- **k**: _Optional\[ int ]_

Expand Down Expand Up @@ -190,7 +190,7 @@ Returns a new array containing the data from another (array) object with a `__dl
```

(function-full)=
### full(shape, fill_value, /, *, dtype=None, device=None)
### full(shape, fill_value, *, dtype=None, device=None)

Returns a new array having a specified `shape` and filled with `fill_value`.

Expand All @@ -206,7 +206,7 @@ Returns a new array having a specified `shape` and filled with `fill_value`.

- **dtype**: _Optional\[ &lt;dtype&gt; ]_

- output array data type. If `dtype` is `None`, the output array data type must be the default floating-point data type. Default: `None`.
- output array data type. If `dtype` is `None`, the output array data type must be inferred from `fill_value`. If it's an `int`, the output array dtype must be the default integer dtype; if it's a `float`, then the output array dtype must be the default floating-point data type; if it's a `bool` then the output array must have boolean dtype. Default: `None`.

- **device**: _Optional\[ &lt;device&gt; ]_

Expand All @@ -219,7 +219,7 @@ Returns a new array having a specified `shape` and filled with `fill_value`.
- an array where every element is equal to `fill_value`.

(function-full_like)=
### full_like(x, fill_value, /, *, dtype=None, device=None)
### full_like(x, /, fill_value, *, dtype=None, device=None)

Returns a new array filled with `fill_value` and having the same `shape` as an input array `x`.

Expand All @@ -235,7 +235,7 @@ Returns a new array filled with `fill_value` and having the same `shape` as an i

- **dtype**: _Optional\[ &lt;dtype&gt; ]_

- output array data type. If `dtype` is `None`, the output array data type must be inferred from `x`. Default: `None`.
- output array data type. If `dtype` is `None`, the output array data type must be inferred from `fill_value` (see {ref}`function-full`). Default: `None`.

- **device**: _Optional\[ &lt;device&gt; ]_

Expand All @@ -248,7 +248,7 @@ Returns a new array filled with `fill_value` and having the same `shape` as an i
- an array having the same shape as `x` and where every element is equal to `fill_value`.

(function-linspace)=
### linspace(start, stop, num, /, *, dtype=None, device=None, endpoint=True)
### linspace(start, stop, /, num, *, dtype=None, device=None, endpoint=True)

Returns evenly spaced numbers over a specified interval.

Expand Down Expand Up @@ -290,7 +290,7 @@ Returns evenly spaced numbers over a specified interval.
- a one-dimensional array containing evenly spaced values.

(function-meshgrid)=
### meshgrid(*arrays, /, *, indexing='xy')
### meshgrid(*arrays, indexing='xy')

Returns coordinate matrices from coordinate vectors.

Expand All @@ -302,26 +302,26 @@ Returns coordinate matrices from coordinate vectors.

- **indexing**: _str_

- Cartesian 'xy' or matrix 'ij' indexing of output. If provided zero or one one-dimensional vector(s) (i.e., the zero- and one-dimensional cases, respectively), the `indexing` keyword has no effect and should be ignored. Default: `'xy'`.
- Cartesian 'xy' or matrix 'ij' indexing of output. If provided zero or one one-dimensional vector(s) (i.e., the zero- and one-dimensional cases, respectively), the `indexing` keyword has no effect and should be ignored. Default: `'xy'`.

#### Returns

- **out**: _List\[ &lt;array&gt;, ... ]_

- list of N arrays, where `N` is the number of provided one-dimensional input arrays. Each returned array must have rank `N`. For `N` one-dimensional arrays having lengths `Ni = len(xi)`,
- list of N arrays, where `N` is the number of provided one-dimensional input arrays. Each returned array must have rank `N`. For `N` one-dimensional arrays having lengths `Ni = len(xi)`,

- if matrix indexing `ij`, then each returned array must have the shape `(N1, N2, N3, ..., Nn)`.
- if matrix indexing `ij`, then each returned array must have the shape `(N1, N2, N3, ..., Nn)`.

- if Cartesian indexing `xy`, then each returned array must have shape `(N2, N1, N3, ..., Nn)`.
- if Cartesian indexing `xy`, then each returned array must have shape `(N2, N1, N3, ..., Nn)`.

Accordingly, for the two-dimensional case with input one-dimensional arrays of length `M` and `N`, if matrix indexing `ij`, then each returned array must have shape `(M, N)`, and, if Cartesian indexing `xy`, then each returned array must have shape `(N, M)`.
Accordingly, for the two-dimensional case with input one-dimensional arrays of length `M` and `N`, if matrix indexing `ij`, then each returned array must have shape `(M, N)`, and, if Cartesian indexing `xy`, then each returned array must have shape `(N, M)`.

Similarly, for the three-dimensional case with input one-dimensional arrays of length `M`, `N`, and `P`, if matrix indexing `ij`, then each returned array must have shape `(M, N, P)`, and, if Cartesian indexing `xy`, then each returned array must have shape `(N, M, P)`.
Similarly, for the three-dimensional case with input one-dimensional arrays of length `M`, `N`, and `P`, if matrix indexing `ij`, then each returned array must have shape `(M, N, P)`, and, if Cartesian indexing `xy`, then each returned array must have shape `(N, M, P)`.

The returned arrays must have a numeric data type determined by {ref}`type-promotion`.
The returned arrays must have a numeric data type determined by {ref}`type-promotion`.

(function-ones)=
### ones(shape, /, *, dtype=None, device=None)
### ones(shape, *, dtype=None, device=None)

Returns a new array having a specified `shape` and filled with ones.

Expand Down Expand Up @@ -371,7 +371,7 @@ Returns a new array filled with ones and having the same `shape` as an input arr
- an array having the same shape as `x` and filled with ones.

(function-zeros)=
### zeros(shape, /, *, dtype=None, device=None)
### zeros(shape, *, dtype=None, device=None)

Returns a new array having a specified `shape` and filled with zeros.

Expand Down
16 changes: 8 additions & 8 deletions spec/API_specification/data_type_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ A conforming implementation of the array API standard must provide and support t
<!-- NOTE: please keep the constants in alphabetical order -->

## Objects in API
(function-broadcast-arrays)=
### broadcast_arrays(\*args, /)
(function-broadcast_arrays)=
### broadcast_arrays(*arrays)

Broadcasts one or more arrays against one another.

#### Parameters

- **\*args**: _Sequence\[ &lt;array&gt; ]_
- **arrays**: _Sequence\[ &lt;array&gt; ]_

- arrays to broadcast.

Expand All @@ -24,8 +24,8 @@ Broadcasts one or more arrays against one another.

- a list of broadcasted arrays. Each array must have the same shape. Each array must have the same dtype as its corresponding input array.

(function-broadcast-to)=
### broadcast_to(x, shape, /)
(function-broadcast_to)=
### broadcast_to(x, /, shape)

Broadcasts an array to a specified shape.

Expand All @@ -49,14 +49,14 @@ Broadcasts an array to a specified shape.

- if the array is incompatible with the specified shape (see {ref}`broadcasting`).

(function-can-cast)=
### can_cast(from, to, /)
(function-can_cast)=
### can_cast(from_, to, /)

Determines if one data type can be cast to another data type according {ref}`type-promotion` rules.

#### Parameters

- **from**: _Union\[ &lt;dtype&gt;, &lt;array&gt;]_
- **from_**: _Union\[ &lt;dtype&gt;, &lt;array&gt;]_

- input data type or array from which to cast.

Expand Down
3 changes: 1 addition & 2 deletions spec/API_specification/data_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

A conforming implementation of the array API standard must provide and support the following data types.

A conforming implementation of the array API standard must define a default floating-point data type (either `float32` or `float64`), as well as a default data type for an array index (either `int32` or `int64`).
A conforming implementation of the array API standard must define a default floating-point data type (either `float32` or `float64`), as well as a default integer data type (`int32` or `int64`). These default data types must be the same across platforms. The default integer data type may vary depending on whether Python is 32-bit or 64-bit.

```{note}

The default floating-point and array index integer data types should be clearly defined in a conforming library's documentation.
```

Expand Down
6 changes: 3 additions & 3 deletions spec/API_specification/elementwise_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ Computes the truth value of `x1_i == x2_i` for each element `x1_i` of the input

- **x2**: _&lt;array&gt;_

- second input array. Must be compatible with `x1` (see {ref}`broadcasting`).
- second input array. Must be compatible with `x1` (see {ref}`broadcasting`). May have any data type.

#### Returns

Expand Down Expand Up @@ -946,11 +946,11 @@ For floating-point operands,

- **x1**: _&lt;array&gt;_

- first input array.
- first input array. Should have a floating-point data type.

- **x2**: _&lt;array&gt;_

- second input array. Must be compatible with `x1` (see {ref}`broadcasting`).
- second input array. Must be compatible with `x1` (see {ref}`broadcasting`). Should have a floating-point data type.

#### Returns

Expand Down
6 changes: 6 additions & 0 deletions spec/API_specification/indexing.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ _Rationale: this is consistent with bounds-checking for single-axis indexing. An

## Boolean Array Indexing

:::{admonition} Data-dependent output shape
:class: important

For common boolean array use cases (e.g., using a dynamically-sized boolean array mask to filter the values of another array), the shape of the output array is data-dependent; hence, libraries that build array computation graphs (e.g., JAX, Dask, etc.) may find boolean array indexing difficult to implement. Accordingly, such libraries may choose to omit boolean array indexing. See {ref}`data-dependent-output-shapes` section for more details.
:::

An array must support indexing where the **sole index** is an `M`-dimensional boolean array `B` with shape `S1 = (s1, ..., sM)` according to the following rules. Let `A` be an `N`-dimensional array with shape `S2 = (s1, ..., sM, ..., sN)`.

- 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)]`.
Expand Down
Loading