Skip to content

Some improvements to type hints #230

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

Merged
merged 7 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions spec/API_specification/array_object.md
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ The `matmul` function must implement the same semantics as the built-in `@` oper

- **self**: _<array>_

- array instance. Should have a numeric data type. Must have at least one dimension. If `self` is one-dimensional having shape `(M)` and `other` has more than one dimension, `self` 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 `self` has more than one dimension (including after vector-to-matrix promotion), `self` must be compatible with `other` (see {ref}`broadcasting`). If `self` has shape `(..., M, K)`, the innermost two dimensions form matrices on which to perform matrix multiplication.
- array instance. Should have a numeric data type. Must have at least one dimension. If `self` is one-dimensional having shape `(M)` and `other` has more than one dimension, `self` 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 `self` has more than one dimension (including after vector-to-matrix promotion), `self` must be compatible with `other` (see {ref}`broadcasting`). If `self` has shape `(..., M, K)`, the innermost two dimensions form matrices on which to perform matrix multiplication.

- **other**: _<array>_

Expand Down Expand Up @@ -809,7 +809,7 @@ The `matmul` function must implement the same semantics as the built-in `@` oper

- if either `self` or `other` is a zero-dimensional array.
- if `self` is a one-dimensional array having shape `(N)`, `other` is a one-dimensional array having shape `(M)`, and `N != M`.
- if `self` is an array having shape `(..., M, K)`, `other` is an array having shape `(..., L, N)`, and `K != L`.
- if `self` is an array having shape `(..., M, K)`, `other` is an array having shape `(..., L, N)`, and `K != L`.

(method-__mod__)=
### \_\_mod\_\_(self, other, /)
Expand Down Expand Up @@ -1066,7 +1066,7 @@ Sets `self[key]` to `value`.

#### Parameters

- **self**: _<array;>_
- **self**: _<array>_

- array instance.

Expand Down
2 changes: 1 addition & 1 deletion spec/API_specification/creation_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Convert the input to an array.

#### Parameters

- **obj**: _Union\[ float, NestedSequence\[ bool | int | float ], SupportsDLPack, SupportsBufferProtocol ]_
- **obj**: _Union\[ <array>, bool, int, float, NestedSequence\[ bool | int | float ], SupportsDLPack, SupportsBufferProtocol ]_

- Object to be converted to an array. Can be a Python scalar, a (possibly nested) sequence of Python scalars, or an object supporting DLPack or the Python buffer protocol.

Expand Down
4 changes: 2 additions & 2 deletions spec/API_specification/manipulation_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Joins a sequence of arrays along an existing axis.

#### Parameters

- **arrays**: _Tuple\[ <array>, ... ]_
- **arrays**: _Union\[Tuple\[ <array>, ... ], List\[ <array> ] ]_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to use Sequence, rather than a Union?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was mentioned here numpy/numpy#18585 (comment). If we agree Sequence is better we can use that instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fairly happy with requiring a tuple or list. Sequence is quite broad (e.g. is an array a sequence?), and I'm not that interested in supporting such flexibility for custom containers, it ends up hurting more than helping often.


- input arrays to join. The arrays must have the same shape, except in the dimension specified by `axis`.

Expand Down Expand Up @@ -154,7 +154,7 @@ Joins a sequence of arrays along a new axis.

#### Parameters

- **arrays**: _Tuple\[ <array>, ... ]_
- **arrays**: _Union\[Tuple\[ <array>, ... ], List\[ <array> ] ]_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above regarding Sequence.


- input arrays to join. Each array must have the same shape.

Expand Down
6 changes: 3 additions & 3 deletions spec/API_specification/searching_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Returns the indices of the maximum values along a specified axis. When the maxim

- input array.

- **axis**: _int_
- **axis**: _Optional\[ int ]_

- axis along which to search. If `None`, the function must return the index of the maximum value of the flattened array. Default: `None`.

Expand All @@ -52,7 +52,7 @@ Returns the indices of the minimum values along a specified axis. When the minim

- input array.

- **axis**: _int_
- **axis**: _Optional\[ int ]_

- axis along which to search. If `None`, the function must return the index of the minimum value of the flattened array. Default: `None`.

Expand Down Expand Up @@ -112,4 +112,4 @@ Returns elements chosen from `x1` or `x2` depending on `condition`.

- **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.
- 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 with the arrays `x1` and `x2`.
14 changes: 7 additions & 7 deletions spec/extensions/linear_algebra_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ Computes the qr factorization of a matrix (or a stack of matrices), where `q` is

- input array having shape `(..., M, N)` and whose innermost two dimensions form `MxN` matrices. Should have a floating-point data type.

- **mode**: _str_
- **mode**: _Literal\[ 'reduced', 'complete' ]_

- factorization mode. Should be one of the following modes:

Expand Down Expand Up @@ -560,7 +560,7 @@ Computes the singular value decomposition `A = USVh` of a matrix (or a stack of

#### Returns

- **out**: _Union\[ <array>, Tuple\[ <array>, ... ] ]_
- **out**: _Tuple\[ <array>, <array>, <array> ]_

- a namedtuple `(u, s, vh)` whose

Expand All @@ -570,11 +570,6 @@ Computes the singular value decomposition `A = USVh` of a matrix (or a stack of

Each returned array must have the same floating-point data type as `x`.

(function-linalg-tensordot)=
### linalg.tensordot(x1, x2, /, *, axes=2)

Alias for {ref}`function-tensordot`.

(function-linalg-svdvals)=
### linalg.svdvals(x, /)

Expand All @@ -592,6 +587,11 @@ Computes the singular values of a matrix (or a stack of matrices) `x`.

- an array with shape `(..., K)` that contains the vector(s) of singular values of length `K`. For each vector, the singular values must be sorted in descending order by magnitude, such that `s[..., 0]` is the largest value, `s[..., 1]` is the second largest value, et cetera. The first `x.ndim-2` dimensions must have the same shape as those of the input `x`. The returned array must have the same floating-point data type as `x`.

(function-linalg-tensordot)=
### linalg.tensordot(x1, x2, /, *, axes=2)

Alias for {ref}`function-tensordot`.

(function-linalg-trace)=
### linalg.trace(x, /, *, axis1=0, axis2=1, offset=0)

Expand Down