8000 Some improvements to type hints (#230) · data-apis/array-api@30a317f · GitHub
[go: up one dir, main page]

Skip to content

Commit 30a317f

Browse files
authored
Some improvements to type hints (#230)
* Fix alphabetical function ordering in the linear algebra extension * Update some type hints in the spec These come from comments on the NumPy pull request numpy/numpy#18585. * Clarify that the where() result type is only based on the last two arguments * Use Literal[] for the qr() mode argument type hint * Add bool and int to the asarray type hints * Fix a typo in the __setitem__ annotations
1 parent 96e40ad commit 30a317f

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

spec/API_specification/array_object.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ The `matmul` function must implement the same semantics as the built-in `@` oper
780780

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

783-
- 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.
783+
- 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.
784784

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

@@ -809,7 +809,7 @@ The `matmul` function must implement the same semantics as the built-in `@` oper
809809
810810
- if either `self` or `other` is a zero-dimensional array.
811811
- if `self` is a one-dimensional array having shape `(N)`, `other` is a one-dimensional array having shape `(M)`, and `N != M`.
812-
- if `self` is an array having shape `(..., M, K)`, `other` is an array having shape `(..., L, N)`, and `K != L`.
812+
- if `self` is an array having shape `(..., M, K)`, `other` is an array having shape `(..., L, N)`, and `K != L`.
813813
814814
(method-__mod__)=
815815
### \_\_mod\_\_(self, other, /)
@@ -1066,7 +1066,7 @@ Sets `self[key]` to `value`.
10661066

10671067
#### Parameters
10681068

1069-
- **self**: _<array;>_
1069+
- **self**: _<array>_
10701070

10711071
- array instance.
10721072

spec/API_specification/creation_functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Convert the input to an array.
5757

5858
#### Parameters
5959

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

6262
- 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.
6363

spec/API_specification/manipulation_functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Joins a sequence of arrays along an existing axis.
1919

2020
#### Parameters
2121

22-
- **arrays**: _Tuple\[ <array>, ... ]_
22+
- **arrays**: _Union\[Tuple\[ <array>, ... ], List\[ <array> ] ]_
2323

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

@@ -154,7 +154,7 @@ Joins a sequence of arrays along a new axis.
154154
155155
#### Parameters
156156
157-
- **arrays**: _Tuple\[ <array>, ... ]_
157+
- **arrays 8000 **: _Union\[Tuple\[ <array>, ... ], List\[ <array> ] ]_
158158
159159
- input arrays to join. Each array must have the same shape.
160160

spec/API_specification/searching_functions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Returns the indices of the maximum values along a specified axis. When the maxim
2727

2828
- input array.
2929

30-
- **axis**: _int_
30+
- **axis**: _Optional\[ int ]_
3131

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

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

5353
- input array.
5454

55-
- **axis**: _int_
55+
- **axis**: _Optional\[ int ]_
5656

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

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

113113
- **out**: _<array>_
114114

115-
- 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.
115+
- 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`.

spec/extensions/linear_algebra_functions.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ Computes th A3E2 e qr factorization of a matrix (or a stack of matrices), where `q` is
465465

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

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

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

@@ -552,7 +552,7 @@ Computes the singular value decomposition `A = USVh` of a matrix (or a stack of
552552

553553
#### Returns
554554

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

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

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

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

565-
(function-linalg-tensordot)=
566-
### linalg.tensordot(x1, x2, /, *, axes=2)
567-
568-
Alias for {ref}`function-tensordot`.
569-
570565
(function-linalg-svdvals)=
571566
### linalg.svdvals(x, /)
572567

@@ -584,6 +579,11 @@ Computes the singular values of a matrix (or a stack of matrices) `x`.
584579

585580
- 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`.
586581

582+
(function-linalg-tensordot)=
583+
### linalg.tensordot(x1, x2, /, *, axes=2)
584+
585+
Alias for {ref}`function-tensordot`.
586+
587587
(function-linalg-trace)=
588588
### linalg.trace(x, /, *, offset=0)
589589

0 commit comments

Comments
 (0)
0