1
+ """Public API Functions."""
2
+
1
3
import warnings
2
4
3
5
from ._lib import _compat , _utils
@@ -22,14 +24,15 @@ def atleast_nd(x: Array, /, *, ndim: int, xp: ModuleType | None = None) -> Array
22
24
Parameters
23
25
----------
24
26
x : array
27
+ Input array.
25
28
ndim : int
26
29
The minimum number of dimensions for the result.
27
30
xp : array_namespace, optional
28
- The standard-compatible namespace for `x`. Default: infer
31
+ The standard-compatible namespace for `x`. Default: infer.
29
32
30
33
Returns
31
34
-------
32
- res : array
35
+ array
33
36
An array with ``res.ndim`` >= `ndim`.
34
37
If ``x.ndim`` >= `ndim`, `x` is returned.
35
38
If ``x.ndim`` < `ndim`, `x` is expanded by prepending new axes
@@ -47,7 +50,6 @@ def atleast_nd(x: Array, /, *, ndim: int, xp: ModuleType | None = None) -> Array
47
50
... [3, 4]]])
48
51
>>> xpx.atleast_nd(x, ndim=1, xp=xp) is x
49
52
True
50
-
51
53
"""
52
54
if xp is None :
53
55
xp = array_namespace (x )
@@ -77,11 +79,11 @@ def cov(m: Array, /, *, xp: ModuleType | None = None) -> Array:
77
79
Each row of `m` represents a variable, and each column a single
78
80
observation of all those variables.
79
81
xp : array_namespace, optional
80
- The standard-compatible namespace for `m`. Default: infer
82
+ The standard-compatible namespace for `m`. Default: infer.
81
83
82
84
Returns
83
85
-------
84
- res : array
86
+ array
85
87
The covariance matrix of the variables.
86
88
87
89
Examples
@@ -104,7 +106,6 @@ def cov(m: Array, /, *, xp: ModuleType | None = None) -> Array:
104
106
Array([[ 1., -1.],
105
107
[-1., 1.]], dtype=array_api_strict.float64)
106
108
107
-
108
109
Note that element :math:`C_{0,1}`, which shows the correlation between
109
110
:math:`x_0` and :math:`x_1`, is negative.
110
111
@@ -122,7 +123,6 @@ def cov(m: Array, /, *, xp: ModuleType | None = None) -> Array:
122
123
123
124
>>> xpx.cov(y, xp=xp)
124
125
Array(2.14413333, dtype=array_api_strict.float64)
125
-
126
126
"""
127
127
if xp is None :
128
128
xp = array_namespace (m )
@@ -161,17 +161,17 @@ def create_diagonal(
161
161
Parameters
162
162
----------
163
163
x : array
164
- A 1-D array
164
+ A 1-D array.
165
165
offset : int, optional
166
166
Offset from the leading diagonal (default is ``0``).
167
167
Use positive ints for diagonals above the leading diagonal,
168
168
and negative ints for diagonals below the leading diagonal.
169
169
xp : array_namespace, optional
170
- The standard-compatible namespace for `x`. Default: infer
170
+ The standard-compatible namespace for `x`. Default: infer.
171
171
172
172
Returns
173
173
-------
174
- res : array
174
+ array
175
175
A 2-D array with `x` on the diagonal (offset by `offset`).
176
176
177
177
Examples
@@ -191,7 +191,6 @@ def create_diagonal(
191
191
[2, 0, 0, 0, 0],
192
192
[0, 4, 0, 0, 0],
193
193
[0, 0, 8, 0, 0]], dtype=array_api_strict.int64)
194
-
195
194
"""
196
195
if xp is None :
197
196
xp = array_namespace (x )
@@ -221,18 +220,19 @@ def expand_dims(
221
220
Parameters
222
221
----------
223
222
a : array
223
+ Array to have its shape expanded.
224
224
axis : int or tuple of ints, optional
225
225
Position(s) in the expanded axes where the new axis (or axes) is/are placed.
226
226
If multiple positions are provided, they should be unique (note that a position
227
227
given by a positive index could also be referred to by a negative index -
228
228
that will also result in an error).
229
229
Default: ``(0,)``.
230
230
xp : array_namespace, optional
231
- The standard-compatible namespace for `a`. Default: infer
231
+ The standard-compatible namespace for `a`. Default: infer.
232
232
233
233
Returns
234
234
-------
235
- res : array
235
+ array
236
236
`a` with an expanded shape.
237
237
238
238
Examples
@@ -270,7 +270,6 @@ def expand_dims(
270
270
>>> y
271
271
Array([[[1],
272
272
[2]]], dtype=array_api_strict.int64)
273
-
274
273
"""
275
274
if xp is None :
276
275
xp = array_namespace (a )
@@ -304,12 +303,13 @@ def kron(a: Array, b: Array, /, *, xp: ModuleType | None = None) -> Array:
304
303
Parameters
305
304
----------
306
305
a, b : array
306
+ Input arrays.
307
307
xp : array_namespace, optional
308
- The standard-compatible namespace for `a` and `b`. Default: infer
308
+ The standard-compatible namespace for `a` and `b`. Default: infer.
309
309
310
310
Returns
311
311
-------
312
- res : array
312
+ array
313
313
The Kronecker product of `a` and `b`.
314
314
315
315
Notes
@@ -333,7 +333,6 @@ def kron(a: Array, b: Array, /, *, xp: ModuleType | None = None) -> Array:
333
333
[ ... ... ],
334
334
[ a[-1,0]*b, a[-1,1]*b, ... , a[-1,-1]*b ]]
335
335
336
-
337
336
Examples
338
337
--------
339
338
>>> import array_api_strict as xp
@@ -352,7 +351,6 @@ def kron(a: Array, b: Array, /, *, xp: ModuleType | None = None) -> Array:
352
351
[0., 0., 1., 1.],
353
352
[0., 0., 1., 1.]], dtype=array_api_strict.float64)
354
353
355
-
356
354
>>> a = xp.reshape(xp.arange(100), (2, 5, 2, 5))
357
355
>>> b = xp.reshape(xp.arange(24), (2, 3, 4))
358
356
>>> c = xpx.kron(a, b, xp=xp)
@@ -365,7 +363,6 @@ def kron(a: Array, b: Array, /, *, xp: ModuleType | None = None) -> Array:
365
363
>>> K = tuple(xp.asarray(I) * xp.asarray(S1) + xp.asarray(J1))
366
364
>>> c[K] == a[I]*b[J]
367
365
Array(True, dtype=array_api_strict.bool)
368
-
369
366
"""
370
367
if xp is None :
371
368
xp = array_namespace (a , b )
@@ -424,11 +421,11 @@ def setdiff1d(
424
421
If ``True``, the input arrays are both assumed to be unique, which
425
422
can speed up the calculation. Default is ``False``.
426
423
xp : array_namespace, optional
427
- The standard-compatible namespace for `x1` and `x2`. Default: infer
424
+ The standard-compatible namespace for `x1` and `x2`. Default: infer.
428
425
429
426
Returns
430
427
-------
431
- res : array
428
+ array
432
429
1D array of values in `x1` that are not in `x2`. The result
433
430
is sorted when `assume_unique` is ``False``, but otherwise only sorted
434
431
if the input is sorted.
@@ -442,7 +439,6 @@ def setdiff1d(
442
439
>>> x2 = xp.asarray([3, 4, 5, 6])
443
440
>>> xpx.setdiff1d(x1, x2, xp=xp)
444
441
Array([1, 2], dtype=array_api_strict.int64)
445
-
446
442
"""
447
443
if xp is None :
448
444
xp = array_namespace (x1 , x2 )
@@ -476,11 +472,11 @@ def sinc(x: Array, /, *, xp: ModuleType | None = None) -> Array:
476
472
Array (possibly multi-dimensional) of values for which to calculate
477
473
``sinc(x)``. Must have a real floating point dtype.
478
474
xp : array_namespace, optional
479
- The standard-compatible namespace for `x`. Default: infer
475
+ The standard-compatible namespace for `x`. Default: infer.
480
476
481
477
Returns
482
478
-------
483
- res : array
479
+ array
484
480
``sinc(x)`` calculated elementwise, which has the same shape as the input.
485
481
486
482
Notes
@@ -528,7 +524,6 @@ def sinc(x: Array, /, *, xp: ModuleType | None = None) -> Array:
528
524
-5.84680802e-02, -8.90384387e-02,
529
525
-8.40918587e-02, -4.92362781e-02,
530
526
-3.89817183e-17], dtype=array_api_strict.float64)
531
-
532
527
"""
533
528
if xp is None :
534
529
xp = array_namespace (x )
0 commit comments