You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- 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.
63
63
@@ -72,7 +72,7 @@ Convert the input to an array.
72
72
73
73
-**device**: _Optional\[<devi
A93C
ce>]_
74
74
75
-
- device to place the created array on, if given. Default: `None`.
75
+
- device on which to place the created array. Default: `None`.
76
76
77
77
-**copy**: _Optional\[ bool ]_
78
78
@@ -102,7 +102,7 @@ Returns an uninitialized array having a specified `shape`.
102
102
103
103
-**device**: _Optional\[<device>]_
104
104
105
-
- device to place the created array on, if given. Default: `None`.
105
+
- device on which to place the created array. Default: `None`.
106
106
107
107
#### Returns
108
108
@@ -127,7 +127,7 @@ Returns an uninitialized array with the same `shape` as an input array `x`.
127
127
128
128
-**device**: _Optional\[<device>]_
129
129
130
-
- device to place the created array on, if given. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.
130
+
- device on which to place the created array. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.
131
131
132
132
#### Returns
133
133
@@ -160,7 +160,7 @@ Returns a two-dimensional array with ones on the `k`th diagonal and zeros elsewh
160
160
161
161
-**device**: _Optional\[<device>]_
162
162
163
-
- device to place the created array on, if given. Default: `None`.
163
+
- device on which to place the created array. Default: `None`.
164
164
165
165
#### Returns
166
166
@@ -206,11 +206,15 @@ Returns a new array having a specified `shape` and filled with `fill_value`.
206
206
207
207
- **dtype**: _Optional\[ <dtype> ]_
208
208
209
-
- 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`.
209
+
- output array data type. If `dtype` is `None`, the output array data type must be inferred from `fill_value`. If the fill value is an `int`, the output array data type must be the default integer data type. If the fill value is a `float`, the output array data type must be the default floating-point data type. If the fill value is a `bool`, the output array must have boolean data type. Default: `None`.
210
+
211
+
```{note}
212
+
If `dtype` is `None` and the `fill_value` exceeds the precision of the resolved default output array data type, behavior is left unspecified and, thus, implementation-defined.
213
+
```
210
214
211
215
- **device**: _Optional\[ <device> ]_
212
216
213
-
- device to place the created array on, if given. Default: `None`.
217
+
- device on which to place the created array. Default: `None`.
214
218
215
219
#### Returns
216
220
@@ -237,9 +241,13 @@ Returns a new array filled with `fill_value` and having the same `shape` as an i
237
241
238
242
- 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`.
239
243
244
+
```{note}
245
+
If `dtype` is `None` and the `fill_value` exceeds the precision of the resolved default output array data type, behavior is left unspecified and, thus, implementation-defined.
246
+
```
247
+
240
248
- **device**: _Optional\[ <device> ]_
241
249
242
-
- device to place the created array on, if given. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.
250
+
- device on which to place the created array. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.
243
251
244
252
#### Returns
245
253
@@ -277,7 +285,7 @@ Returns evenly spaced numbers over a specified interval.
277
285
278
286
- **device**: _Optional\[ <device> ]_
279
287
280
-
- device to place the created array on, if given. Default: `None`.
288
+
- device on which to place the created array. Default: `None`.
281
289
282
290
- **endpoint**: _bool_
283
291
@@ -337,7 +345,7 @@ Returns a new array having a specified `shape` and filled with ones.
337
345
338
346
- **device**: _Optional\[ <device> ]_
339
347
340
-
- device to place the created array on, if given. Default: `None`.
348
+
- device on which to place the created array. Default: `None`.
341
349
342
350
#### Returns
343
351
@@ -362,14 +370,72 @@ Returns a new array filled with ones and having the same `shape` as an input arr
362
370
363
371
- **device**: _Optional\[ <device> ]_
364
372
365
-
- device to place the created array on, if given. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.
373
+
- device on which to place the created array. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.
366
374
367
375
#### Returns
368
376
369
377
- **out**: _<array>_
370
378
371
379
- an array having the same shape as `x` and filled with ones.
372
380
381
+
(function-tril)=
382
+
### tril(x, /, *, k=0)
383
+
384
+
Returns the lower triangular part of a matrix (or a stack of matrices) `x`.
385
+
386
+
```{note}
387
+
The lower triangular part of the matrix is defined as the elements on and below the specified diagonal `k`.
388
+
```
389
+
390
+
#### Parameters
391
+
392
+
-**x**: _<array>_
393
+
394
+
- input array having shape `(..., M, N)` and whose innermost two dimensions form `MxN` matrices.
395
+
396
+
-**k**: _int_
397
+
398
+
- diagonal above which to zero elements. If `k = 0`, the diagonal is the main diagonal. If `k < 0`, the diagonal is below the main diagonal. If `k > 0`, the diagonal is above the main diagonal. Default: `0`.
399
+
400
+
```{note}
401
+
The main diagonal is defined as the set of indices `{(i, i)}` for `i` on the interval `[0, min(M, N) - 1]`.
402
+
```
403
+
404
+
#### Returns
405
+
406
+
- **out**: _<array>_
407
+
408
+
- an array containing the lower triangular part(s). The returned array must have the same shape and data type as `x`. All elements above the specified diagonal `k` must be zeroed. The returned array should be allocated on the same device as `x`.
409
+
410
+
(function-triu)=
411
+
### triu(x, /, *, k=0)
412
+
413
+
Returns the upper triangular part of a matrix (or a stack of matrices) `x`.
414
+
415
+
```{note}
416
+
The upper triangular part of the matrix is defined as the elements on and above the specified diagonal `k`.
417
+
```
418
+
419
+
#### Parameters
420
+
421
+
-**x**: _<array>_
422
+
423
+
- input array having shape `(..., M, N)` and whose innermost two dimensions form `MxN` matrices.
424
+
425
+
-**k**: _int_
426
+
427
+
- diagonal below which to zero elements. If `k = 0`, the diagonal is the main diagonal. If `k < 0`, the diagonal is below the main diagonal. If `k > 0`, the diagonal is above the main diagonal. Default: `0`.
428
+
429
+
```{note}
430
+
The main diagonal is defined as the set of indices `{(i, i)}` for `i` on the interval `[0, min(M, N) - 1]`.
431
+
```
432
+
433
+
#### Returns
434
+
435
+
- **out**: _<array>_
436
+
437
+
- an array containing the upper triangular part(s). The returned array must have the same shape and data type as `x`. All elements below the specified diagonal `k` must be zeroed. The returned array should be allocated on the same device as `x`.
438
+
373
439
(function-zeros)=
374
440
### zeros(shape, *, dtype=None, device=None)
375
441
@@ -387,7 +453,7 @@ Returns a new array having a specified `shape` and filled with zeros.
387
453
388
454
- **device**: _Optional\[ <device> ]_
389
455
390
-
- device to place the created array on, if given. Default: `None`.
456
+
- device on which to place the created array. Default: `None`.
391
457
392
458
#### Returns
393
459
@@ -412,7 +478,7 @@ Returns a new array filled with zeros and having the same `shape` as an input ar
412
478
413
479
- **device**: _Optional\[ <device> ]_
414
480
415
-
- device to place the created array on, if given. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.
481
+
- device on which to place the created array. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.
Copy file name to clipboardExpand all lines: spec/API_specification/elementwise_functions.md
+24-7Lines changed: 24 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -944,8 +944,9 @@ each element `x1_i` of the input array `x1` with the respective element `x2_i` o
944
944
945
945
For floating-point operands,
946
946
947
-
- If either `x1_i` or `x2_i` is `NaN`, the result is `NaN`.
948
-
- If either `x1_i` or `x2_i` is `+infinity`, the result is `+infinity`.
947
+
- If either `x1_i` or `x2_i` is `NaN`, the result is `NaN`.
948
+
- If `x1_i` is `+infinity` and `x2_i` is not `NaN`, the result is `+infinity`.
949
+
- If `x1_i` is not `NaN` and `x2_i` is `+infinity`, the result is `+infinity`.
949
950
950
951
#### Parameters
951
952
@@ -967,7 +968,11 @@ For floating-point operands,
967
968
(function-logical_and)=
968
969
### logical_and(x1, x2, /)
969
970
970
-
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 are considered the equivalent of `False`, while non-zeros are considered the equivalent of `True`.
971
+
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`.
972
+
973
+
```{note}
974
+
While this specification recommends that this function only accept input arrays having a boolean data type, specification-compliant array libraries may choose to accept input arrays having numeric data types. If non-boolean data types are supported, zeros must be considered the equivalent of `False`, while non-zeros must be considered the equivalent of `True`.
975
+
```
971
976
972
977
#### Parameters
973
978
@@ -988,7 +993,11 @@ Computes the logical AND for each element `x1_i` of the input array `x1` with th
988
993
(function-logical_not)=
989
994
### logical_not(x, /)
990
995
991
-
Computes the logical NOT for each element `x_i` of the input array `x`. Zeros are considered the equivalent of `False`, while non-zeros are considered the equivalent of `True`.
996
+
Computes the logical NOT for each element `x_i` of the input array `x`.
997
+
998
+
```{note}
999
+
While this specification recommends that this function only accept input arrays having a boolean data type, specification-compliant array libraries may choose to accept input arrays having numeric data types. If non-boolean data types are supported, zeros must be considered the equivalent of `False`, while non-zeros must be considered the equivalent of `True`.
1000
+
```
992
1001
993
1002
#### Parameters
994
1003
@@ -1005,7 +1014,11 @@ Computes the logical NOT for each element `x_i` of the input array `x`. Zeros ar
1005
1014
(function-logical_or)=
1006
1015
### logical_or(x1, x2, /)
1007
1016
1008
-
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 are considered the equivalent of `False`, while non-zeros are considered the equivalent of `True`.
1017
+
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`.
1018
+
1019
+
```{note}
1020
+
While this specification recommends that this function only accept input arrays having a boolean data type, specification-compliant array libraries may choose to accept input arrays having numeric data types. If non-boolean data types are supported, zeros must be considered the equivalent of `False`, while non-zeros must be considered the equivalent of `True`.
1021
+
```
1009
1022
1010
1023
#### Parameters
1011
1024
@@ -1026,7 +1039,11 @@ Computes the logical OR for each element `x1_i` of the input array `x1` with the
1026
1039
(function-logical_xor)=
1027
1040
### logical_xor(x1, x2, /)
1028
1041
1029
-
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 are considered the equivalent of `False`, while non-zeros are considered the equivalent of `True`.
1042
+
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`.
1043
+
1044
+
```{note}
1045
+
While this specification recommends that this function only accept input arrays having a boolean data type, specification-compliant array libraries may choose to accept input arrays having numeric data types. If non-boolean data types are supported, zeros must be considered the equivalent of `False`, while non-zeros must be considered the equivalent of `True`.
1046
+
```
1030
1047
1031
1048
#### Parameters
1032
1049
@@ -1208,7 +1225,7 @@ Returns the remainder of division for each element `x1_i` of the input array `x1
1208
1225
1209
1226
-**out**: _<array>_
1210
1227
1211
-
- 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`.
1228
+
- 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 data type determined by {ref}`type-promotion`.
Copy file name to clipboardExpand all lines: spec/API_specification/linear_algebra_functions.md
+17-21Lines changed: 17 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -60,6 +60,23 @@ The `matmul` function must implement the same semantics as the built-in `@` oper
60
60
- if `x1` is a one-dimensional array having shape `(N)`, `x2` is a one-dimensional array having shape `(M)`, and `N != M`.
61
61
- if `x1` is an array having shape `(..., M, K)`, `x2` is an array having shape `(..., L, N)`, and `K != L`.
62
62
63
+
(function-matrix-transpose)=
64
+
### matrix_transpose(x, /)
65
+
66
+
Transposes a matrix (or a stack of matrices) `x`.
67
+
68
+
#### Parameters
69
+
70
+
-**x**: _<array>_
71
+
72
+
- input array having shape `(..., M, N)` and whose innermost two dimensions form `MxN` matrices.
73
+
74
+
#### Returns
75
+
76
+
-**out**: _<array>_
77
+
78
+
- an array containing the transpose for each matrix and having shape `(..., N, M)`. The returned array must have the same data type as `x`.
79
+
63
80
(function-tensordot)=
64
81
### tensordot(x1, x2, /, *, axes=2)
65
82
@@ -93,27 +110,6 @@ Returns a tensor contraction of `x1` and `x2` over specific axes.
93
110
94
111
- 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`.
95
112
96
-
(function-transpose)=
97
-
### transpose(x, /, *, axes=None)
98
-
99
-
Transposes (or permutes the axes (dimensions)) of an array `x`.
100
-
101
-
#### Parameters
102
-
103
-
-**x**: _<array>_
104
-
105
-
- input array.
106
-
107
-
-**axes**: _Optional\[ Tuple\[ int, ... ]]_
108
-
109
-
- tuple containing a permutation of `(0, 1, ..., N-1)` where `N` is the number of axes (dimensions) of `x`. If `None`, the axes (dimensions) must be permuted in reverse order (i.e., equivalent to setting `axes=(N-1, ..., 1, 0)`). Default: `None`.
110
-
111
-
#### Returns
112
-
113
-
-**out**: _<array>_
114
-
115
-
- an array containing the transpose. The returned array must have the same data type as `x`.
0 commit comments