cobra-array 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cobra_array/__init__.py +105 -0
- cobra_array/_core.py +392 -0
- cobra_array/_utils.py +93 -0
- cobra_array/array_api.py +117 -0
- cobra_array/compat/__init__.py +23 -0
- cobra_array/compat/_array.py +499 -0
- cobra_array/compat/_array.pyi +1816 -0
- cobra_array/compat/_base.py +53 -0
- cobra_array/compat/_namespace.py +305 -0
- cobra_array/compat/_namespace.pyi +833 -0
- cobra_array/convert.py +334 -0
- cobra_array/convert.pyi +73 -0
- cobra_array/default.py +142 -0
- cobra_array/exceptions.py +74 -0
- cobra_array/types.py +68 -0
- cobra_array-0.1.0.dist-info/METADATA +137 -0
- cobra_array-0.1.0.dist-info/RECORD +20 -0
- cobra_array-0.1.0.dist-info/WHEEL +5 -0
- cobra_array-0.1.0.dist-info/licenses/LICENSE +21 -0
- cobra_array-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1816 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Python version: 3.9
|
|
3
|
+
# @TianZhen
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
from torch import Tensor
|
|
7
|
+
from numpy.typing import NDArray
|
|
8
|
+
from typing import (Union, List, Tuple, Optional, Any, Sequence, Generic, TypeVar, Literal, overload)
|
|
9
|
+
|
|
10
|
+
from ._base import Compat
|
|
11
|
+
from ..types import (
|
|
12
|
+
T, DTypeT, DeviceT, dtypeT, deviceT, DType, Device,
|
|
13
|
+
ArrayLike, ArrayLibraryName,
|
|
14
|
+
ArrayOrAny, ArrayOrScalar, ArrayOrReal, ArrayOrIntLike, ArrayOrInt, ArrayOrbool,
|
|
15
|
+
UniqueAllResult, UniqueCountsResult, UniqueInverseResult
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
TT = TypeVar("TT", bound=DType)
|
|
19
|
+
DT = TypeVar("DT", bound=Device)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class CompatArray(Compat, Generic[TT, DT]):
|
|
23
|
+
@overload
|
|
24
|
+
@classmethod
|
|
25
|
+
def from_other(cls, obj: NDArray[dtypeT], /, xp: Literal["numpy"]) -> CompatArray[dtypeT, Literal["cpu"]]: ...
|
|
26
|
+
@overload
|
|
27
|
+
@classmethod
|
|
28
|
+
def from_other(cls, obj: ArrayLike[dtypeT], /, xp: Literal["numpy"]) -> CompatArray[dtypeT, Literal["cpu"]]: ...
|
|
29
|
+
@overload
|
|
30
|
+
@classmethod
|
|
31
|
+
def from_other(cls, obj: object, /, xp: Literal["numpy"]) -> CompatArray[Any, Literal["cpu"]]: ...
|
|
32
|
+
@overload
|
|
33
|
+
@classmethod
|
|
34
|
+
def from_other(cls, obj: NDArray[dtypeT], /, xp: Union[object, ArrayLibraryName]) -> CompatArray[dtypeT, Any]: ...
|
|
35
|
+
@overload
|
|
36
|
+
@classmethod
|
|
37
|
+
def from_other(cls, obj: ArrayLike[dtypeT], /, xp: Union[object, ArrayLibraryName]) -> CompatArray[dtypeT, Any]: ...
|
|
38
|
+
@overload
|
|
39
|
+
@classmethod
|
|
40
|
+
def from_other(cls, obj: object, /, xp: Union[object, ArrayLibraryName]) -> CompatArray[Any, Any]: ...
|
|
41
|
+
@classmethod
|
|
42
|
+
def from_other(cls, obj: object, /, xp: Union[object, ArrayLibraryName]) -> CompatArray[Any, Any]: ...
|
|
43
|
+
|
|
44
|
+
@overload
|
|
45
|
+
def __new__(cls, arr: NDArray[dtypeT], /, **kwargs) -> CompatArray[dtypeT, Literal["cpu"]]: ...
|
|
46
|
+
@overload
|
|
47
|
+
def __new__(cls, arr: Tensor, /, **kwargs) -> CompatArray[Any, Any]: ...
|
|
48
|
+
@overload
|
|
49
|
+
def __new__(cls, arr: CompatArray[dtypeT, deviceT], /, **kwargs) -> CompatArray[dtypeT, deviceT]: ...
|
|
50
|
+
@overload
|
|
51
|
+
def __new__(cls, arr: ArrayLike[dtypeT], /, **kwargs) -> CompatArray[dtypeT, Any]: ...
|
|
52
|
+
def __new__(cls, arr: ArrayLike[Any], /, **kwargs) -> CompatArray[Any, Any]: ...
|
|
53
|
+
|
|
54
|
+
# === Conversion functions ===
|
|
55
|
+
def to_numpy(self, *, copy: bool = False) -> NDArray[TT]: ...
|
|
56
|
+
def to_tensor(self, *, device: Optional[DeviceT] = None, copy: bool = False) -> Tensor: ...
|
|
57
|
+
def to_list(self, *, copy: bool = False) -> List[TT]: ...
|
|
58
|
+
|
|
59
|
+
# === Device functions ===
|
|
60
|
+
def to_device(self, device: DeviceT, /, *, stream: Optional[Any] = None) -> CompatArray[TT, DeviceT]: ...
|
|
61
|
+
|
|
62
|
+
# === Data type functions ===
|
|
63
|
+
@overload
|
|
64
|
+
def astype(self, dtype: DTypeT, /, *, copy: bool = ...) -> CompatArray[DTypeT, DT]: ...
|
|
65
|
+
@overload
|
|
66
|
+
def astype(self, dtype: DTypeT, /, *, copy: bool = ..., device: DeviceT) -> CompatArray[DTypeT, DeviceT]: ...
|
|
67
|
+
|
|
68
|
+
def astype(
|
|
69
|
+
self,
|
|
70
|
+
dtype: DType,
|
|
71
|
+
/, *,
|
|
72
|
+
copy: bool = True,
|
|
73
|
+
device: Optional[Device] = None
|
|
74
|
+
) -> CompatArray[Any, Any]:
|
|
75
|
+
"""
|
|
76
|
+
Copies `self` to a specified data type irrespective of Type Promotion Rules rules.
|
|
77
|
+
|
|
78
|
+
Parameters
|
|
79
|
+
----------
|
|
80
|
+
dtype : DTypeT
|
|
81
|
+
Desired data type.
|
|
82
|
+
|
|
83
|
+
copy : bool, default to `True`
|
|
84
|
+
Specifies whether to copy an array when the specified dtype matches the data type of `self`.
|
|
85
|
+
- `True`: A newly allocated array must always be returned;
|
|
86
|
+
- `False`: Whether :param:`dtype` matches the data type of `self`:
|
|
87
|
+
|
|
88
|
+
- `True`: `self` must be returned;
|
|
89
|
+
- `False`: A newly allocated array must be returned.
|
|
90
|
+
|
|
91
|
+
device : Optional[DeviceT], default to `None`
|
|
92
|
+
DeviceT on which to place the returned array.
|
|
93
|
+
- `None`: The output array device must be inferred from `self`.
|
|
94
|
+
|
|
95
|
+
Returns
|
|
96
|
+
-------
|
|
97
|
+
CompatArray
|
|
98
|
+
An array having the specified data type.
|
|
99
|
+
The returned array must have the same shape as `self`.
|
|
100
|
+
"""
|
|
101
|
+
...
|
|
102
|
+
|
|
103
|
+
# === Elementwise functions ===
|
|
104
|
+
def abs(self) -> CompatArray[TT, DT]:
|
|
105
|
+
"""
|
|
106
|
+
Computes the element-wise `absolute value` of `self`.
|
|
107
|
+
"""
|
|
108
|
+
...
|
|
109
|
+
|
|
110
|
+
def acos(self) -> CompatArray[float, DT]:
|
|
111
|
+
"""
|
|
112
|
+
Computes the element-wise `principal value of the inverse cosine` of `self`.
|
|
113
|
+
- `self` should have a floating-point data type.
|
|
114
|
+
"""
|
|
115
|
+
...
|
|
116
|
+
|
|
117
|
+
def acosh(self) -> CompatArray[float, DT]:
|
|
118
|
+
"""
|
|
119
|
+
Computes the element-wise `inverse hyperbolic cosine` of `self`.
|
|
120
|
+
- `self` should have a floating-point data type.
|
|
121
|
+
"""
|
|
122
|
+
...
|
|
123
|
+
|
|
124
|
+
def add(self, other: ArrayOrScalar, /) -> CompatArray[Any, DT]:
|
|
125
|
+
"""
|
|
126
|
+
Computes the element-wise `sum` of `self` and `other`.
|
|
127
|
+
- `self` should have a numeric data type.
|
|
128
|
+
"""
|
|
129
|
+
...
|
|
130
|
+
|
|
131
|
+
def asin(self) -> CompatArray[float, DT]:
|
|
132
|
+
"""
|
|
133
|
+
Computes the element-wise `principal value of the inverse sine` of `self`.
|
|
134
|
+
- `self` should have a floating-point data type.
|
|
135
|
+
"""
|
|
136
|
+
...
|
|
137
|
+
|
|
138
|
+
def asinh(self) -> CompatArray[float, DT]:
|
|
139
|
+
"""
|
|
140
|
+
Computes the element-wise `inverse hyperbolic sine` of `self`.
|
|
141
|
+
- `self` should have a floating-point data type.
|
|
142
|
+
"""
|
|
143
|
+
...
|
|
144
|
+
|
|
145
|
+
def atan(self) -> CompatArray[float, DT]:
|
|
146
|
+
"""
|
|
147
|
+
Computes the element-wise `principal value of the inverse tangent` of `self`.
|
|
148
|
+
- `self` should have a floating-point data type.
|
|
149
|
+
"""
|
|
150
|
+
...
|
|
151
|
+
|
|
152
|
+
def atan2(self, other: ArrayOrReal, /) -> CompatArray[float, DT]:
|
|
153
|
+
"""
|
|
154
|
+
Computes the element-wise `inverse tangent` of `self / other`, taking into account the signs of both inputs.
|
|
155
|
+
- `self` should have a real-valued floating-point data type.
|
|
156
|
+
- This allows determining the correct quadrant. Results are in radians in [-π, π].
|
|
157
|
+
"""
|
|
158
|
+
...
|
|
159
|
+
|
|
160
|
+
def atanh(self) -> CompatArray[float, DT]:
|
|
161
|
+
"""
|
|
162
|
+
Computes the element-wise `inverse hyperbolic tangent` of `self`.
|
|
163
|
+
- `self` should have a floating-point data type.
|
|
164
|
+
"""
|
|
165
|
+
...
|
|
166
|
+
|
|
167
|
+
def bitwise_and(self, other: ArrayOrIntLike, /) -> CompatArray[TT, DT]:
|
|
168
|
+
"""
|
|
169
|
+
Computes the element-wise `bitwise AND` of `self` and `other`.
|
|
170
|
+
- `self` should have an integer or boolean data type.
|
|
171
|
+
"""
|
|
172
|
+
...
|
|
173
|
+
|
|
174
|
+
def bitwise_left_shift(self, other: ArrayOrInt, /) -> CompatArray[TT, DT]:
|
|
175
|
+
"""
|
|
176
|
+
Computes the element-wise `bitwise left shift` of `self` by `other`.
|
|
177
|
+
- `self` should have an integer data type.
|
|
178
|
+
- Each element is shifted left by the corresponding number of bits.
|
|
179
|
+
"""
|
|
180
|
+
...
|
|
181
|
+
|
|
182
|
+
def bitwise_invert(self) -> CompatArray[TT, DT]:
|
|
183
|
+
"""
|
|
184
|
+
Computes the element-wise `bitwise NOT` of `self`.
|
|
185
|
+
- `self` should have an integer or boolean data type.
|
|
186
|
+
- This operation flips every bit of each element.
|
|
187
|
+
"""
|
|
188
|
+
...
|
|
189
|
+
|
|
190
|
+
def bitwise_or(self, other: ArrayOrIntLike, /) -> CompatArray[TT, DT]:
|
|
191
|
+
"""
|
|
192
|
+
Computes the element-wise `bitwise OR` of `self` and `other`.
|
|
193
|
+
- `self` should have an integer or boolean data type.
|
|
194
|
+
"""
|
|
195
|
+
...
|
|
196
|
+
|
|
197
|
+
def bitwise_right_shift(self, other: ArrayOrInt, /) -> CompatArray[TT, DT]:
|
|
198
|
+
"""
|
|
199
|
+
Computes the element-wise `bitwise right shift` of `self` by `other`.
|
|
200
|
+
- `self` should have an integer data type.
|
|
201
|
+
- Each element is shifted right by the corresponding number of bits.
|
|
202
|
+
"""
|
|
203
|
+
...
|
|
204
|
+
|
|
205
|
+
def bitwise_xor(self, other: ArrayOrIntLike, /) -> CompatArray[TT, DT]:
|
|
206
|
+
"""
|
|
207
|
+
Computes the element-wise `bitwise XOR` of `self` and `other`.
|
|
208
|
+
- `self` should have an integer or boolean data type.
|
|
209
|
+
"""
|
|
210
|
+
...
|
|
211
|
+
|
|
212
|
+
def ceil(self) -> CompatArray[TT, DT]:
|
|
213
|
+
"""
|
|
214
|
+
Computes the element-wise `ceiling` of `self`.
|
|
215
|
+
- `self` should have a real-valued data type.
|
|
216
|
+
- Each element is rounded to the smallest (i.e., closest to -infinity) integer-valued number that is not less than itself.
|
|
217
|
+
"""
|
|
218
|
+
...
|
|
219
|
+
|
|
220
|
+
def clip(self, *, min: Optional[ArrayOrReal] = None, max: Optional[ArrayOrReal] = None) -> CompatArray[TT, DT]:
|
|
221
|
+
"""
|
|
222
|
+
Computes the element-wise `clipping` of `self` to the range [:param:`min`, :param:`max`].
|
|
223
|
+
- `self` should have a real-valued data type.
|
|
224
|
+
"""
|
|
225
|
+
...
|
|
226
|
+
|
|
227
|
+
def conj(self) -> CompatArray[TT, DT]:
|
|
228
|
+
"""
|
|
229
|
+
Computes the element-wise `complex conjugate` of `self`.
|
|
230
|
+
- `self` must have a numeric data type.
|
|
231
|
+
"""
|
|
232
|
+
...
|
|
233
|
+
|
|
234
|
+
def copysign(self, other: ArrayOrReal, /) -> CompatArray[float, DT]:
|
|
235
|
+
"""
|
|
236
|
+
Computes the element-wise `copysign` of `self` with `other`.
|
|
237
|
+
- `self` should have a real-valued floating-point data type.
|
|
238
|
+
- Each element has the magnitude of `self` and the sign of `other`.
|
|
239
|
+
"""
|
|
240
|
+
...
|
|
241
|
+
|
|
242
|
+
def cos(self) -> CompatArray[float, DT]:
|
|
243
|
+
"""
|
|
244
|
+
Computes the element-wise `cosine` of `self`.
|
|
245
|
+
- `self` should have a floating-point data type.
|
|
246
|
+
"""
|
|
247
|
+
...
|
|
248
|
+
|
|
249
|
+
def cosh(self) -> CompatArray[float, DT]:
|
|
250
|
+
"""
|
|
251
|
+
Computes the element-wise `hyperbolic cosine` of `self`.
|
|
252
|
+
- `self` should have a floating-point data type.
|
|
253
|
+
"""
|
|
254
|
+
...
|
|
255
|
+
|
|
256
|
+
def divide(self, other: ArrayOrScalar, /) -> CompatArray[float, DT]:
|
|
257
|
+
"""
|
|
258
|
+
Computes the element-wise `division` of `self` by `other`.
|
|
259
|
+
- `self` should have a numeric data type.
|
|
260
|
+
"""
|
|
261
|
+
...
|
|
262
|
+
|
|
263
|
+
def equal(self, other: ArrayOrAny, /) -> CompatArray[bool, DT]:
|
|
264
|
+
"""
|
|
265
|
+
Computes the element-wise truth value of `self == other`.
|
|
266
|
+
"""
|
|
267
|
+
...
|
|
268
|
+
|
|
269
|
+
def exp(self) -> CompatArray[float, DT]:
|
|
270
|
+
"""
|
|
271
|
+
Computes the element-wise `exponential` (`exp(x)`) of `self`.
|
|
272
|
+
- `self` should have a floating-point data type.
|
|
273
|
+
"""
|
|
274
|
+
...
|
|
275
|
+
|
|
276
|
+
def expm1(self) -> CompatArray[float, DT]:
|
|
277
|
+
"""
|
|
278
|
+
Computes the element-wise `exp(x) - 1` of `self`.
|
|
279
|
+
- `self` should have a floating-point data type.
|
|
280
|
+
"""
|
|
281
|
+
...
|
|
282
|
+
|
|
283
|
+
def floor(self) -> CompatArray[TT, DT]:
|
|
284
|
+
"""
|
|
285
|
+
Computes the element-wise `floor` of `self`.
|
|
286
|
+
- `self` should have a real-valued data type.
|
|
287
|
+
- Each element is rounded to the largest (i.e., closest to +infinity) integer-valued number that is not greater than itself.
|
|
288
|
+
"""
|
|
289
|
+
...
|
|
290
|
+
|
|
291
|
+
def floor_divide(self, other: ArrayOrReal, /) -> CompatArray[TT, DT]:
|
|
292
|
+
"""
|
|
293
|
+
Computes the element-wise `floor division` of `self` by `other`.
|
|
294
|
+
- `self` should have a real-valued data type.
|
|
295
|
+
- Each element of the division result is rounded to the largest (i.e., closest to +infinity) integer-valued number that is not greater than itself.
|
|
296
|
+
"""
|
|
297
|
+
...
|
|
298
|
+
|
|
299
|
+
def greater(self, other: ArrayOrReal, /) -> CompatArray[bool, DT]:
|
|
300
|
+
"""
|
|
301
|
+
Computes the element-wise truth value of `self > other`.
|
|
302
|
+
- `self` should have a real-valued data type.
|
|
303
|
+
"""
|
|
304
|
+
...
|
|
305
|
+
|
|
306
|
+
def greater_equal(self, other: ArrayOrReal, /) -> CompatArray[bool, DT]:
|
|
307
|
+
"""
|
|
308
|
+
Computes the element-wise truth value of `self >= other`.
|
|
309
|
+
- `self` should have a real-valued data type.
|
|
310
|
+
"""
|
|
311
|
+
...
|
|
312
|
+
|
|
313
|
+
def hypot(self, other: ArrayOrReal, /) -> CompatArray[float, DT]:
|
|
314
|
+
"""
|
|
315
|
+
Computes the element-wise `hypotenuse` of `self` and `other`.
|
|
316
|
+
- `self` should have a real-valued floating-point data type.
|
|
317
|
+
- Equivalent to `sqrt(self **2 + other **2)`, computed in a numerically stable way.
|
|
318
|
+
"""
|
|
319
|
+
...
|
|
320
|
+
|
|
321
|
+
def imag(self) -> CompatArray[float, DT]:
|
|
322
|
+
"""
|
|
323
|
+
Computes the element-wise `imaginary component` of `self`.
|
|
324
|
+
- `self` should have a complex floating-point data type.
|
|
325
|
+
"""
|
|
326
|
+
...
|
|
327
|
+
|
|
328
|
+
def isfinite(self) -> CompatArray[bool, DT]:
|
|
329
|
+
"""
|
|
330
|
+
Tests the element-wise `finiteness` of `self`.
|
|
331
|
+
- `self` should have a numeric data type.
|
|
332
|
+
"""
|
|
333
|
+
...
|
|
334
|
+
|
|
335
|
+
def isinf(self) -> CompatArray[bool, DT]:
|
|
336
|
+
"""
|
|
337
|
+
Tests the element-wise `infinity` of `self`.
|
|
338
|
+
- - `self` should have a numeric data type.
|
|
339
|
+
"""
|
|
340
|
+
...
|
|
341
|
+
|
|
342
|
+
def isnan(self) -> CompatArray[bool, DT]:
|
|
343
|
+
"""
|
|
344
|
+
Tests the element-wise `NaN` of `self`.
|
|
345
|
+
- `self` should have a numeric data type.
|
|
346
|
+
"""
|
|
347
|
+
...
|
|
348
|
+
|
|
349
|
+
def less(self, other: ArrayOrReal, /) -> CompatArray[bool, DT]:
|
|
350
|
+
"""
|
|
351
|
+
Computes the element-wise truth value of `self < other`.
|
|
352
|
+
- `self` should have a real-valued data type.
|
|
353
|
+
"""
|
|
354
|
+
...
|
|
355
|
+
|
|
356
|
+
def less_equal(self, other: ArrayOrReal, /) -> CompatArray[bool, DT]:
|
|
357
|
+
"""
|
|
358
|
+
Computes the element-wise truth value of `self <= other`.
|
|
359
|
+
- `self` should have a real-valued data type.
|
|
360
|
+
"""
|
|
361
|
+
...
|
|
362
|
+
|
|
363
|
+
def log(self) -> CompatArray[float, DT]:
|
|
364
|
+
"""
|
|
365
|
+
Computes the element-wise `natural logarithm` (base `e`) of `self`.
|
|
366
|
+
- `self` should have a floating-point data type.
|
|
367
|
+
"""
|
|
368
|
+
...
|
|
369
|
+
|
|
370
|
+
def log1p(self) -> CompatArray[float, DT]:
|
|
371
|
+
"""
|
|
372
|
+
Computes the element-wise `log(1 + x)` (base `e`) of `self`.
|
|
373
|
+
- `self` should have a floating-point data type.
|
|
374
|
+
"""
|
|
375
|
+
...
|
|
376
|
+
|
|
377
|
+
def log2(self) -> CompatArray[float, DT]:
|
|
378
|
+
"""
|
|
379
|
+
Computes the element-wise `base-2 logarithm` of `self`.
|
|
380
|
+
- `self` should have a floating-point data type.
|
|
381
|
+
"""
|
|
382
|
+
...
|
|
383
|
+
|
|
384
|
+
def log10(self) -> CompatArray[float, DT]:
|
|
385
|
+
"""
|
|
386
|
+
Computes the element-wise `base-10 logarithm` of `self`.
|
|
387
|
+
- `self` should have a floating-point data type.
|
|
388
|
+
"""
|
|
389
|
+
...
|
|
390
|
+
|
|
391
|
+
def logaddexp(self, other: ArrayOrReal, /) -> CompatArray[float, DT]:
|
|
392
|
+
"""
|
|
393
|
+
Computes the element-wise `logaddexp` of `self` and `other`.
|
|
394
|
+
- Equivalent to `log(exp(self) + exp(other))`.
|
|
395
|
+
- `self` should have a floating-point data type.
|
|
396
|
+
"""
|
|
397
|
+
...
|
|
398
|
+
|
|
399
|
+
def logical_and(self, other: ArrayOrbool, /) -> CompatArray[bool, DT]:
|
|
400
|
+
"""
|
|
401
|
+
Computes the element-wise `logical AND` of `self` and `other`.
|
|
402
|
+
- `self` should have a boolean data type.
|
|
403
|
+
"""
|
|
404
|
+
...
|
|
405
|
+
|
|
406
|
+
def logical_not(self) -> CompatArray[bool, DT]:
|
|
407
|
+
"""
|
|
408
|
+
Computes the element-wise `logical NOT` of `self`.
|
|
409
|
+
- `self` should have a boolean data type.
|
|
410
|
+
"""
|
|
411
|
+
...
|
|
412
|
+
|
|
413
|
+
def logical_or(self, other: ArrayOrbool, /) -> CompatArray[bool, DT]:
|
|
414
|
+
"""
|
|
415
|
+
Computes the element-wise `logical OR` of `self` and `other`.
|
|
416
|
+
- `self` should have a boolean data type.
|
|
417
|
+
"""
|
|
418
|
+
...
|
|
419
|
+
|
|
420
|
+
def logical_xor(self, other: ArrayOrbool, /) -> CompatArray[bool, DT]:
|
|
421
|
+
"""
|
|
422
|
+
Computes the element-wise `logical XOR` of `self` and `other`.
|
|
423
|
+
- `self` should have a boolean data type.
|
|
424
|
+
"""
|
|
425
|
+
...
|
|
426
|
+
|
|
427
|
+
def maximum(self, other: ArrayOrReal, /) -> CompatArray[Any, DT]:
|
|
428
|
+
"""
|
|
429
|
+
Computes the element-wise `maximum` of `self` and `other`.
|
|
430
|
+
- `self` should have a real-valued data type.
|
|
431
|
+
"""
|
|
432
|
+
...
|
|
433
|
+
|
|
434
|
+
def minimum(self, other: ArrayOrReal, /) -> CompatArray[Any, DT]:
|
|
435
|
+
"""
|
|
436
|
+
Computes the element-wise `minimum` of `self` and `other`.
|
|
437
|
+
- `self` should have a real-valued data type.
|
|
438
|
+
"""
|
|
439
|
+
...
|
|
440
|
+
|
|
441
|
+
def multiply(self, other: ArrayOrScalar, /) -> CompatArray[Any, DT]:
|
|
442
|
+
"""
|
|
443
|
+
Computes the element-wise `product` of `self` and `other`.
|
|
444
|
+
- `self` should have a numeric data type.
|
|
445
|
+
"""
|
|
446
|
+
...
|
|
447
|
+
|
|
448
|
+
def negative(self) -> CompatArray[TT, DT]:
|
|
449
|
+
"""
|
|
450
|
+
Computes the element-wise `numerical negative` of `self`.
|
|
451
|
+
- `self` should have a numeric data type.
|
|
452
|
+
"""
|
|
453
|
+
...
|
|
454
|
+
|
|
455
|
+
def nextafter(self, other: ArrayOrReal, /) -> CompatArray[TT, DT]:
|
|
456
|
+
"""
|
|
457
|
+
Computes the element-wise `next representable floating-point value` of `self` toward `other`.
|
|
458
|
+
- `self` should have a real-valued floating-point data type.
|
|
459
|
+
"""
|
|
460
|
+
...
|
|
461
|
+
|
|
462
|
+
def not_equal(self, other: ArrayOrAny, /) -> CompatArray[bool, DT]:
|
|
463
|
+
"""
|
|
464
|
+
Computes the element-wise truth value of `self != other`.
|
|
465
|
+
"""
|
|
466
|
+
...
|
|
467
|
+
|
|
468
|
+
def positive(self) -> CompatArray[TT, DT]:
|
|
469
|
+
"""
|
|
470
|
+
Computes the element-wise `numerical positive` of `self`.
|
|
471
|
+
- `self` should have a numeric data type.
|
|
472
|
+
"""
|
|
473
|
+
...
|
|
474
|
+
|
|
475
|
+
def pow(self, other: ArrayOrScalar, /) -> CompatArray[Any, DT]:
|
|
476
|
+
"""
|
|
477
|
+
Computes the element-wise `power` of `self` and `other`.
|
|
478
|
+
- `self` should have a numeric data type.
|
|
479
|
+
- Each element of `self` is raised to the corresponding power in `other`.
|
|
480
|
+
"""
|
|
481
|
+
...
|
|
482
|
+
|
|
483
|
+
def real(self) -> CompatArray[float, DT]:
|
|
484
|
+
"""
|
|
485
|
+
Computes the element-wise `real component` of `self`.
|
|
486
|
+
- `self` should have a numeric data type.
|
|
487
|
+
"""
|
|
488
|
+
...
|
|
489
|
+
|
|
490
|
+
def reciprocal(self) -> CompatArray[float, DT]:
|
|
491
|
+
"""
|
|
492
|
+
Computes the element-wise `reciprocal` of `self`.
|
|
493
|
+
- `self` should have a floating-point data type.
|
|
494
|
+
"""
|
|
495
|
+
...
|
|
496
|
+
|
|
497
|
+
def remainder(self, other: ArrayOrReal, /) -> CompatArray[Any, DT]:
|
|
498
|
+
"""
|
|
499
|
+
Computes the element-wise `remainder` of `self` divided by `other`.
|
|
500
|
+
- `self` should have a real-valued data type.
|
|
501
|
+
"""
|
|
502
|
+
...
|
|
503
|
+
|
|
504
|
+
def round(self) -> CompatArray[TT, DT]:
|
|
505
|
+
"""
|
|
506
|
+
Computes the element-wise `rounding` of `self` to the nearest integer-valued number.
|
|
507
|
+
- `self` should have a numeric data type.
|
|
508
|
+
"""
|
|
509
|
+
...
|
|
510
|
+
|
|
511
|
+
def sign(self) -> CompatArray[TT, DT]:
|
|
512
|
+
"""
|
|
513
|
+
Computes the element-wise `indication of the sign` of `self`.
|
|
514
|
+
- `self` should have a numeric data type.
|
|
515
|
+
"""
|
|
516
|
+
...
|
|
517
|
+
|
|
518
|
+
def signbit(self) -> CompatArray[bool, DT]:
|
|
519
|
+
"""
|
|
520
|
+
Tests the element-wise `sign bit` of `self`.
|
|
521
|
+
- Tests each element for whenever is either `-0`, `less than zero`, or a signed `NaN` (i.e., a NaN value whose sign bit is 1).
|
|
522
|
+
- `self` should have a real-valued floating-point data type.
|
|
523
|
+
"""
|
|
524
|
+
...
|
|
525
|
+
|
|
526
|
+
def sin(self) -> CompatArray[float, DT]:
|
|
527
|
+
"""
|
|
528
|
+
Computes the element-wise `sine` of `self`.
|
|
529
|
+
- `self` should have a floating-point data type.
|
|
530
|
+
"""
|
|
531
|
+
...
|
|
532
|
+
|
|
533
|
+
def sinh(self) -> CompatArray[float, DT]:
|
|
534
|
+
"""
|
|
535
|
+
Computes the element-wise `hyperbolic sine` of `self`.
|
|
536
|
+
- `self` should have a floating-point data type.
|
|
537
|
+
"""
|
|
538
|
+
...
|
|
539
|
+
|
|
540
|
+
def square(self) -> CompatArray[TT, DT]:
|
|
541
|
+
"""
|
|
542
|
+
Computes the element-wise `square` of `self`.
|
|
543
|
+
- `self` should have a numeric data type.
|
|
544
|
+
"""
|
|
545
|
+
...
|
|
546
|
+
|
|
547
|
+
def sqrt(self) -> CompatArray[float, DT]:
|
|
548
|
+
"""
|
|
549
|
+
Computes the element-wise `principal square root` of `self`.
|
|
550
|
+
- `self` should have a floating-point data type.
|
|
551
|
+
"""
|
|
552
|
+
...
|
|
553
|
+
|
|
554
|
+
def subtract(self, other: ArrayOrScalar, /) -> CompatArray[Any, DT]:
|
|
555
|
+
"""
|
|
556
|
+
Computes the element-wise `difference` of `self` and `other`.
|
|
557
|
+
- `self` should have a numeric data type.
|
|
558
|
+
"""
|
|
559
|
+
...
|
|
560
|
+
|
|
561
|
+
def tan(self) -> CompatArray[float, DT]:
|
|
562
|
+
"""
|
|
563
|
+
Computes the element-wise `tangent` of `self`.
|
|
564
|
+
- `self` should have a floating-point data type.
|
|
565
|
+
"""
|
|
566
|
+
...
|
|
567
|
+
|
|
568
|
+
def tanh(self) -> CompatArray[float, DT]:
|
|
569
|
+
"""
|
|
570
|
+
Computes the element-wise `hyperbolic tangent` of `self`.
|
|
571
|
+
- `self` should have a floating-point data type.
|
|
572
|
+
"""
|
|
573
|
+
...
|
|
574
|
+
|
|
575
|
+
def trunc(self) -> CompatArray[TT, DT]:
|
|
576
|
+
"""
|
|
577
|
+
Computes the element-wise `truncation` of `self` toward `zero`.
|
|
578
|
+
- `self` should have a real-valued data type.
|
|
579
|
+
- Each element is rounded to the nearest integer-valued number that is closer to `zero` than itself.
|
|
580
|
+
"""
|
|
581
|
+
|
|
582
|
+
# === Indexing functions ===
|
|
583
|
+
def take(self, indices: ArrayLike[Any], /, *, axis: Optional[int] = None) -> CompatArray[TT, DT]:
|
|
584
|
+
"""
|
|
585
|
+
Returns elements of `self` along an :param:`axis`.
|
|
586
|
+
- `self` should have one or more dimensions (axes).
|
|
587
|
+
|
|
588
|
+
Parameters
|
|
589
|
+
----------
|
|
590
|
+
indices : ArrayLike
|
|
591
|
+
The :param:`indices` array must be one-dimensional and have an integer data type. For index in :param:`indices`:
|
|
592
|
+
- _negative_: The function must determine the element to select along a specified axis (dimension) by counting from the last element (where -1 refers to the last element).
|
|
593
|
+
|
|
594
|
+
axis : Optional[int], default to `None`
|
|
595
|
+
Axis over which to select values.
|
|
596
|
+
- _negative_int_: The function must determine the axis along which to select values by counting from the last dimension (where -1 refers to the last dimension).
|
|
597
|
+
|
|
598
|
+
For dimension of `self`:
|
|
599
|
+
- `1`: Providing an :param:`axis` is optional;
|
|
600
|
+
- `> 1`: Providing an :param:`axis` is required.
|
|
601
|
+
|
|
602
|
+
Returns
|
|
603
|
+
-------
|
|
604
|
+
CompatArray
|
|
605
|
+
A :class:`CompatArray` array having the same data type as `self`. The output array must have the same rank (i.e., number of dimensions) as `self` and must have the same shape as `self`, except for the axis specified by :param:`axis` whose size must equal the number of elements in :param:`indices`.
|
|
606
|
+
|
|
607
|
+
Notes
|
|
608
|
+
-----
|
|
609
|
+
- Conceptually, `take(x, indices, axis=3)` is equivalent to `x[:,:,:,indices,...]`; however, explicit indexing via arrays of indices is not currently supported in this specification due to concerns regarding __setitem__ and array mutation semantics;
|
|
610
|
+
- This specification does not require bounds checking. The behavior for out-of-bounds indices is left unspecified;
|
|
611
|
+
- When `self` is a zero-dimensional array, behavior is unspecified and thus implementation-defined.
|
|
612
|
+
"""
|
|
613
|
+
...
|
|
614
|
+
|
|
615
|
+
def take_along_axis(self, indices: ArrayLike[Any], /, *, axis: int = -1) -> CompatArray[TT, DT]:
|
|
616
|
+
"""
|
|
617
|
+
Returns elements from `self` at the one-dimensional indices specified by :param:`indices` along a provided :param:`axis`.
|
|
618
|
+
- `self` must be compatible with :param:`indices`, except for the :param:`axis` (dimension) specified by axis.
|
|
619
|
+
|
|
620
|
+
Parameters
|
|
621
|
+
----------
|
|
622
|
+
indices : ArrayLike
|
|
623
|
+
Must have the same rank (i.e., number of dimensions) as `self`.
|
|
624
|
+
For index in :param:`indices`:
|
|
625
|
+
- _negative_: The function must determine the element to select along a specified axis (dimension) by counting from the last element (where -1 refers to the last element).
|
|
626
|
+
|
|
627
|
+
axis : int, default to `-1`
|
|
628
|
+
Axis along which to select values.
|
|
629
|
+
- _negative_int_: The function must determine the axis along which to select values by counting from the last dimension (where -1 refers to the last dimension).
|
|
630
|
+
|
|
631
|
+
Returns
|
|
632
|
+
-------
|
|
633
|
+
CompatArray
|
|
634
|
+
A :class:`CompatArray` array having the same data type as `self`. Must have the same rank (i.e., number of dimensions) as `self` and must have a shape determined according to Broadcasting, except for the axis (dimension) specified by :param:`axis` whose size must equal the size of the corresponding axis (dimension) in :param:`indices`.
|
|
635
|
+
|
|
636
|
+
Notes
|
|
637
|
+
-----
|
|
638
|
+
- This specification does not require bounds checking. The behavior for out-of-bounds indices is left unspecified.
|
|
639
|
+
"""
|
|
640
|
+
...
|
|
641
|
+
|
|
642
|
+
# === Linear algebra functions ===
|
|
643
|
+
def matmul(self, other: ArrayLike[Any], /) -> CompatArray[Any, DT]:
|
|
644
|
+
"""
|
|
645
|
+
Computes the matrix product.
|
|
646
|
+
- `self` should have a numeric data type. Must have at least one dimension.
|
|
647
|
+
- 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;
|
|
648
|
+
- If `self` has more than one dimension (including after vector-to-matrix promotion), shape(`self`)[:-2] must be compatible with shape(`other`)[:-2] (after vector-to-matrix promotion);
|
|
649
|
+
- If `self` has shape `(..., M, K)`, the innermost two dimensions form matrices on which to perform matrix multiplication.
|
|
650
|
+
|
|
651
|
+
Parameters
|
|
652
|
+
----------
|
|
653
|
+
other : ArrayLike
|
|
654
|
+
Should have a numeric data type. Must have at least one dimension.
|
|
655
|
+
- If `other` is one-dimensional having shape `(N,)` and `self` has more than one dimension, `other` must be promoted to a two-dimensional array by appending 1 to its dimensions (i.e., must have shape `(N, 1)`). After matrix multiplication, the appended dimensions in the returned array must be removed;
|
|
656
|
+
- If `other` has more than one dimension (including after vector-to-matrix promotion), shape(`other`)[:-2] must be compatible with shape(`self`)[:-2] (after vector-to-matrix promotion);
|
|
657
|
+
- If `other` has shape `(..., K, N)`, the innermost two dimensions form matrices on which to perform matrix multiplication.
|
|
658
|
+
|
|
659
|
+
Returns
|
|
660
|
+
-------
|
|
661
|
+
CompatArray
|
|
662
|
+
The returned :class:`CompatArray` array must have a data type determined by Type Promotion Rules.
|
|
663
|
+
- If both `self` and `other` are one-dimensional arrays having shape `(N,)`, a zero-dimensional array containing the inner product as its only element.
|
|
664
|
+
- If `self` is a two-dimensional array having shape `(M, K)` and `other` is a two-dimensional array having shape `(K, N)`, a two-dimensional array containing the conventional matrix product and having shape `(M, N)`.
|
|
665
|
+
- If `self` is a one-dimensional array having shape `(K,)` and `other` is an array having shape `(..., K, N)`, an array having shape `(..., N)` (i.e., prepended dimensions during vector-to-matrix promotion must be removed) and containing the conventional matrix product.
|
|
666
|
+
- If `self` is an array having shape `(..., M, K)` and `other` is a one-dimensional array having shape `(K,)`, an array having shape `(..., M)` (i.e., appended dimensions during vector-to-matrix promotion must be removed) and containing the conventional matrix product.
|
|
667
|
+
- If `self` is a two-dimensional array having shape `(M, K)` and `other` is an array having shape `(..., K, N)`, an array having shape `(..., M, N)` and containing the conventional matrix product for each stacked matrix.
|
|
668
|
+
- If `self` is an array having shape `(..., M, K)` and `other` is a two-dimensional array having shape `(K, N)`, an array having shape `(..., M, N)` and containing the conventional matrix product for each stacked matrix.
|
|
669
|
+
- If either `self` or `other` has more than two dimensions, an array having a shape determined by Broadcasting shape(`self`)[:-2] against shape(`other`)[:-2] and containing the conventional matrix product for each stacked matrix.
|
|
670
|
+
"""
|
|
671
|
+
...
|
|
672
|
+
|
|
673
|
+
def tensordot(self, other: ArrayLike[Any], /, *, axes: Union[int, Tuple[Sequence[int], Sequence[int]]] = 2) -> CompatArray[Any, DT]:
|
|
674
|
+
"""
|
|
675
|
+
Returns a tensor contraction of `self` and `other` over specific axes.
|
|
676
|
+
- The function corresponds to the generalized matrix product.
|
|
677
|
+
- `self` should have a numeric data type.
|
|
678
|
+
|
|
679
|
+
Parameters
|
|
680
|
+
----------
|
|
681
|
+
other : ArrayLike
|
|
682
|
+
Should have a numeric data type. Corresponding contracted axes of `self` and `other` must be equal.
|
|
683
|
+
|
|
684
|
+
NOTE: Contracted axes (dimensions) must not be broadcasted.
|
|
685
|
+
|
|
686
|
+
axes : Union[int, Tuple[Sequence[int], Sequence[int]]], default to `2`
|
|
687
|
+
Number of axes (dimensions) to contract or explicit sequences of axis (dimension) indices for `self` and `other`, respectively.
|
|
688
|
+
- _int_(`N`): Contraction must be performed over the last `N` axes of `self` and the first `N` axes of `other` in order. The size of each corresponding axis (dimension) must match. Must be nonnegative. For `N`:
|
|
689
|
+
|
|
690
|
+
- `0`: The result is the tensor (outer) product;
|
|
691
|
+
- `1`: The result is the tensor dot product;
|
|
692
|
+
- `2`: The result is the tensor double contraction (default).
|
|
693
|
+
- _Tuple[`self_axes`, `other_axes`]_: The first sequence must apply to `self` and the second sequence to `other`. Both sequences must have the same length. Each axis (dimension) `self_axes[i]` for `self` must have the same size as the respective axis (dimension) `other_axes[i]` for `other`. Each index referred to in a sequence must be unique. If `self` has rank (i.e, number of dimensions) `N`, a valid `self` axis must reside on the half-open interval `[-N, N)`. If `other` has rank M, a valid `other` axis must reside on the half-open interval `[-M, M)`.
|
|
694
|
+
|
|
695
|
+
Returns
|
|
696
|
+
-------
|
|
697
|
+
CompatArray
|
|
698
|
+
A :class:`CompatArray` array containing the tensor contraction whose shape consists of the non-contracted axes (dimensions) of the first array `self`, followed by the non-contracted axes (dimensions) of the second array `other`. The returned array must have a data type determined by Type Promotion Rules.
|
|
699
|
+
"""
|
|
700
|
+
...
|
|
701
|
+
|
|
702
|
+
def matrix_transpose(self) -> CompatArray[TT, DT]:
|
|
703
|
+
"""
|
|
704
|
+
Transposes the matrix (or a stack of matrices) `self`.
|
|
705
|
+
- `self` having shape `(..., M, N)` and whose innermost two dimensions form `MxN` matrices.
|
|
706
|
+
|
|
707
|
+
Returns
|
|
708
|
+
-------
|
|
709
|
+
CompatArray
|
|
710
|
+
A :class:`CompatArray` array containing the transpose for each matrix and having shape `(..., N, M)`.
|
|
711
|
+
The returned array must have the same data type as `self`.
|
|
712
|
+
"""
|
|
713
|
+
...
|
|
714
|
+
|
|
715
|
+
def vecdot(self, other: ArrayLike[Any], /, *, axes: int = -1) -> CompatArray[Any, DT]:
|
|
716
|
+
"""
|
|
717
|
+
Computes the (vector) dot product of two arrays.
|
|
718
|
+
- `self` should have a floating-point data type.
|
|
719
|
+
|
|
720
|
+
Parameters
|
|
721
|
+
----------
|
|
722
|
+
other : ArrayLike
|
|
723
|
+
Must be compatible with `self` for all non-contracted axes.
|
|
724
|
+
The size of the axis over which to compute the dot product must be the same size as the respective axis in `self`.
|
|
725
|
+
Should have a floating-point data type.
|
|
726
|
+
|
|
727
|
+
NOTE: The contracted axis (dimension) must not be broadcasted.
|
|
728
|
+
|
|
729
|
+
axes : int, default to `-1`
|
|
730
|
+
The axis (dimension) of `self` and `other` containing the vectors for which to compute the dot product.
|
|
731
|
+
Should be an integer on the interval `[-N, -1]`, where `N` is min(`self.ndim`, `other.ndim`).
|
|
732
|
+
The function must determine the axis along which to compute the dot product by counting backward from the last dimension (where -1 refers to the last dimension).
|
|
733
|
+
By default, the function must compute the dot product over the last axis.
|
|
734
|
+
|
|
735
|
+
Returns
|
|
736
|
+
-------
|
|
737
|
+
CompatArray
|
|
738
|
+
The returned :class:`CompatArray` array must have a data type determined by Type Promotion Rules.
|
|
739
|
+
- `self` & `other` is `1-D`: A zero-dimensional array containing the dot product as its only element.
|
|
740
|
+
- _others_: A non-zero-dimensional array containing the dot products and having a shape determined according to Broadcasting along the non-contracted axes.
|
|
741
|
+
"""
|
|
742
|
+
|
|
743
|
+
# === Manipulation functions ===
|
|
744
|
+
def expand_dims(self, *, axis: int) -> CompatArray[TT, DT]:
|
|
745
|
+
"""
|
|
746
|
+
Expands the shape of `self` by inserting a new axis (dimension) of size one at the position specified by :param:`axis`.
|
|
747
|
+
|
|
748
|
+
Parameters
|
|
749
|
+
----------
|
|
750
|
+
axis : int
|
|
751
|
+
Axis position (zero-based).
|
|
752
|
+
- `self` has rank (i.e, number of dimensions) `N`: A valid :param:`axis` must reside on the closed-interval `[-N-1, N]`;
|
|
753
|
+
- _negative_: The axis position at which to insert a singleton dimension must be computed as `N + axis + 1`.
|
|
754
|
+
|
|
755
|
+
- `-1`: The resolved axis position must be `N` (i.e., a singleton dimension must be appended to `self`);
|
|
756
|
+
- `-N-1`: The resolved axis position must be `0` (i.e., a singleton dimension must be prepended to `self`).
|
|
757
|
+
|
|
758
|
+
Returns
|
|
759
|
+
-------
|
|
760
|
+
CompatArray
|
|
761
|
+
An expanded output :class:`CompatArray` array having the same data type as `self`.
|
|
762
|
+
|
|
763
|
+
Raises
|
|
764
|
+
------
|
|
765
|
+
IndexError
|
|
766
|
+
If provided an invalid :param:`axis` position.
|
|
767
|
+
"""
|
|
768
|
+
...
|
|
769
|
+
|
|
770
|
+
def flip(self, *, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> CompatArray[TT, DT]:
|
|
771
|
+
"""
|
|
772
|
+
Reverses the order of elements in `self` along the given axis. The shape of `self` must be preserved.
|
|
773
|
+
|
|
774
|
+
Parameters
|
|
775
|
+
----------
|
|
776
|
+
axis : Optional[Union[int, Tuple[int, ...]]], default to `None`
|
|
777
|
+
Axis (or axes) along which to flip.
|
|
778
|
+
- `None`: The function must flip all input array axes;
|
|
779
|
+
- _negative_: The function must count from the last dimension;
|
|
780
|
+
- more than one axis: The function must flip only the specified axes.
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
Returns
|
|
784
|
+
-------
|
|
785
|
+
CompatArray
|
|
786
|
+
An output :class:`CompatArray` array having the same data type and shape as `self` and whose elements, relative to `self`, are reordered.
|
|
787
|
+
"""
|
|
788
|
+
...
|
|
789
|
+
|
|
790
|
+
def moveaxis(
|
|
791
|
+
self,
|
|
792
|
+
source: Union[int, Tuple[int, ...]],
|
|
793
|
+
destination: Union[int, Tuple[int, ...]],
|
|
794
|
+
/
|
|
795
|
+
) -> CompatArray[TT, DT]:
|
|
796
|
+
"""
|
|
797
|
+
Moves `self` axes (dimensions) to new positions, while leaving other axes in their original positions.
|
|
798
|
+
|
|
799
|
+
Parameters
|
|
800
|
+
----------
|
|
801
|
+
source : Union[int, Tuple[int, ...]]
|
|
802
|
+
Axes to move. Provided axes must be unique.
|
|
803
|
+
- `self` has rank (i.e, number of dimensions) `N`: A valid :param:`axis` must reside on the half-open interval `[-N, N)`.
|
|
804
|
+
|
|
805
|
+
destination : Union[int, Tuple[int, ...]]
|
|
806
|
+
Indices defining the desired positions for each respective :param:`source` axis index.
|
|
807
|
+
Provided indices must be unique.
|
|
808
|
+
- `self` has rank (i.e, number of dimensions) `N`: A valid :param:`axis` must reside on the half-open interval `[-N, N)`.
|
|
809
|
+
|
|
810
|
+
Returns
|
|
811
|
+
-------
|
|
812
|
+
CompatArray
|
|
813
|
+
A :class:`CompatArray` array containing reordered axes.
|
|
814
|
+
The returned array must have the same data type as `self`.
|
|
815
|
+
"""
|
|
816
|
+
...
|
|
817
|
+
|
|
818
|
+
def permute_dims(self, axes: Tuple[int, ...]) -> CompatArray[TT, DT]:
|
|
819
|
+
"""
|
|
820
|
+
Permutes the axes (dimensions) of `self`.
|
|
821
|
+
|
|
822
|
+
Parameters
|
|
823
|
+
----------
|
|
824
|
+
axes : Tuple[int, ...]
|
|
825
|
+
Tuple containing a permutation of `(0, 1, ..., N-1)` where `N` is the number of axes (dimensions) of `self`.
|
|
826
|
+
|
|
827
|
+
Returns
|
|
828
|
+
-------
|
|
829
|
+
CompatArray
|
|
830
|
+
A :class:`CompatArray` array containing the axes permutation.
|
|
831
|
+
The returned array must have the same data type as `self`.
|
|
832
|
+
"""
|
|
833
|
+
...
|
|
834
|
+
|
|
835
|
+
def repeat(
|
|
836
|
+
self,
|
|
837
|
+
repeats: Union[int, ArrayLike[Any]],
|
|
838
|
+
/, *,
|
|
839
|
+
axis: Optional[int] = None
|
|
840
|
+
) -> CompatArray[TT, DT]:
|
|
841
|
+
"""
|
|
842
|
+
Repeats each element of `self` a specified number of times on a per-element basis.
|
|
843
|
+
|
|
844
|
+
Parameters
|
|
845
|
+
----------
|
|
846
|
+
repeats : Union[int, ArrayLike[Any]]
|
|
847
|
+
The number of repetitions for each element.
|
|
848
|
+
|
|
849
|
+
If :param:`axis` is `None`, let `N = prod(self.shape)` and
|
|
850
|
+
- _ArrayLike_: :param:`repeats` must be broadcast compatible with the shape `(N,)` (i.e., be a one-dimensional array having shape `(1,)` or `(N,)`);
|
|
851
|
+
- _int_: :param:`repeats` must be broadcasted to the shape `(N,)`.
|
|
852
|
+
|
|
853
|
+
If :param:`axis` is not `None`, let `M = self.shape[axis]` and
|
|
854
|
+
- _ArrayLike_: :param:`repeats` must be broadcast compatible with the shape `(M,)` (i.e., be a one-dimensional array having shape `(1,)` or `(M,)`);
|
|
855
|
+
- _int_: :param:`repeats` must be broadcasted to the shape `(M,)`.
|
|
856
|
+
|
|
857
|
+
If :param:`repeats` is an array, the array must have an integer data type.
|
|
858
|
+
|
|
859
|
+
axis : Optional[int], default to `None`
|
|
860
|
+
The axis along which to repeat elements.
|
|
861
|
+
- `None`: The function must flatten `self` and then repeat elements of the flattened `self` and return the result as a one-dimensional output array. A flattened `self` must be flattened in row-major, C-style order.
|
|
862
|
+
|
|
863
|
+
Returns
|
|
864
|
+
-------
|
|
865
|
+
CompatArray
|
|
866
|
+
An output :class:`CompatArray` array containing repeated elements.
|
|
867
|
+
The returned array must have the same data type as `self`.
|
|
868
|
+
For :param:`axis`:
|
|
869
|
+
- `None`: the returned array must be a one-dimensional array;
|
|
870
|
+
- _others_: the returned array must have the same shape as `self`, except for the axis (dimension) along which elements were repeated.
|
|
871
|
+
"""
|
|
872
|
+
...
|
|
873
|
+
|
|
874
|
+
def reshape(
|
|
875
|
+
self,
|
|
876
|
+
shape: Tuple[int, ...],
|
|
877
|
+
*,
|
|
878
|
+
copy: Optional[bool] = None
|
|
879
|
+
) -> CompatArray[TT, DT]:
|
|
880
|
+
"""
|
|
881
|
+
Reshapes `self` without changing its data.
|
|
882
|
+
|
|
883
|
+
Parameters
|
|
884
|
+
----------
|
|
885
|
+
shape : Tuple[int, ...]
|
|
886
|
+
A new shape compatible with the original shape. One shape dimension is allowed to be -1.
|
|
887
|
+
When a shape dimension is -1, the corresponding output array shape dimension must be inferred from the length of `self` and the remaining dimensions.
|
|
888
|
+
|
|
889
|
+
copy : Optional[bool], default to `None`
|
|
890
|
+
Whether or not to copy `self`.
|
|
891
|
+
- `True`: The function must always copy;
|
|
892
|
+
- `False`: The function must never copy;
|
|
893
|
+
- `None`: The function must avoid copying, if possible, and may copy otherwise.
|
|
894
|
+
|
|
895
|
+
Returns
|
|
896
|
+
-------
|
|
897
|
+
CompatArray
|
|
898
|
+
A :class:`CompatArray` output array having the same data type and elements as `self`.
|
|
899
|
+
|
|
900
|
+
Raises
|
|
901
|
+
------
|
|
902
|
+
ValueError
|
|
903
|
+
If :param:`copy` is `False` and a copy would be necessary.
|
|
904
|
+
"""
|
|
905
|
+
...
|
|
906
|
+
|
|
907
|
+
def roll(
|
|
908
|
+
self,
|
|
909
|
+
shift: Union[int, Tuple[int, ...]],
|
|
910
|
+
*,
|
|
911
|
+
axis: Optional[Union[int, Tuple[int, ...]]] = None
|
|
912
|
+
) -> CompatArray[TT, DT]:
|
|
913
|
+
"""
|
|
914
|
+
Rolls `self` elements along a specified axis.
|
|
915
|
+
- Array elements that roll beyond the last position are re-introduced at the first position.
|
|
916
|
+
- Array elements that roll beyond the first position are re-introduced at the last position.
|
|
917
|
+
|
|
918
|
+
Parameters
|
|
919
|
+
----------
|
|
920
|
+
shift : Union[int, Tuple[int, ...]]
|
|
921
|
+
Number of places by which the elements are shifted.
|
|
922
|
+
- _tuple_: :param:`axis` must be a tuple of the same size, and each of the given axes must be shifted by the corresponding element in :param:`shift`;
|
|
923
|
+
- _int_ and :param:`axis` is _tuple_: the same :param:`shift` must be used for all specified axes;
|
|
924
|
+
- _positive_: `self` elements must be shifted positively (toward larger indices) along the dimension of :param:`axis`;
|
|
925
|
+
- _negative_: `self` elements must be shifted negatively (toward smaller indices) along the dimension of :param:`axis`.
|
|
926
|
+
|
|
927
|
+
axis : Optional[Union[int, Tuple[int, ...]]], default to `None`
|
|
928
|
+
Axis (or axes) along which elements to shift.
|
|
929
|
+
- `None`: `self` must be flattened, shifted, and then restored to its original shape.
|
|
930
|
+
|
|
931
|
+
Returns
|
|
932
|
+
-------
|
|
933
|
+
CompatArray
|
|
934
|
+
An output :class:`CompatArray` array having the same data type and shape as `self` and whose elements, relative to `self`, are shifted.
|
|
935
|
+
"""
|
|
936
|
+
...
|
|
937
|
+
|
|
938
|
+
def squeeze(self, axis: Union[int, Tuple[int, ...]]) -> CompatArray[TT, DT]:
|
|
939
|
+
"""
|
|
940
|
+
Removes singleton dimensions (axes) from `self`.
|
|
941
|
+
|
|
942
|
+
Parameters
|
|
943
|
+
----------
|
|
944
|
+
axis : Union[int, Tuple[int, ...]]
|
|
945
|
+
Axis (or axes) to squeeze.
|
|
946
|
+
|
|
947
|
+
Returns
|
|
948
|
+
-------
|
|
949
|
+
CompatArray
|
|
950
|
+
An output :class:`CompatArray` array having the same data type and elements as `self`.
|
|
951
|
+
|
|
952
|
+
Raises
|
|
953
|
+
------
|
|
954
|
+
ValueError
|
|
955
|
+
If a specified axis has a size greater than one (i.e., it is not a singleton dimension).
|
|
956
|
+
"""
|
|
957
|
+
...
|
|
958
|
+
|
|
959
|
+
def tile(self, repetitions: Tuple[int, ...], /) -> CompatArray[TT, DT]:
|
|
960
|
+
"""
|
|
961
|
+
Constructs an array by tiling `self`.
|
|
962
|
+
|
|
963
|
+
Parameters
|
|
964
|
+
----------
|
|
965
|
+
repetitions : Tuple[int, ...]
|
|
966
|
+
Number of repetitions along each axis (dimension).
|
|
967
|
+
Let `N = len(self.shape)` and `M = len(repetitions)`.
|
|
968
|
+
- `N > M`: The function must prepend ones until all axes (dimensions) are specified (e.g., if `self` has shape `(8,6,4,2)` and :param:`repetitions` is the tuple `(3,3)`, then :param:`repetitions` must be treated as `(1,1,3,3)`);
|
|
969
|
+
- `N < M`: The function must prepend singleton axes (dimensions) to `self` until `self` has as many axes (dimensions) as :param:`repetitions` specifies (e.g., if `self` has shape `(4,2)` and :param:`repetitions` is the tuple `(3,3,3,3)`, then `self` must be treated as if it has shape `(1,1,4,2)`).
|
|
970
|
+
|
|
971
|
+
Returns
|
|
972
|
+
-------
|
|
973
|
+
CompatArray
|
|
974
|
+
A tiled output :class:`CompatArray` array.
|
|
975
|
+
The returned array must have the same data type as `self` and must have a rank (i.e., number of dimensions) equal to `max(N, M)`.
|
|
976
|
+
If `S` is the shape of the tiled array after prepending singleton dimensions (if necessary) and `r` is the tuple of repetitions after prepending ones (if necessary), then the number of elements along each axis (dimension) must satisfy `S[i]*r[i]`, where `i` refers to the `i` th axis (dimension).
|
|
977
|
+
"""
|
|
978
|
+
...
|
|
979
|
+
|
|
980
|
+
def unstack(self, *, axis: int = 0) -> Tuple[CompatArray[TT, DT], ...]: ...
|
|
981
|
+
|
|
982
|
+
# === Searching functions ===
|
|
983
|
+
def argmax(
|
|
984
|
+
self, *,
|
|
985
|
+
axis: Optional[int] = None,
|
|
986
|
+
keepdims: bool = False
|
|
987
|
+
) -> CompatArray[int, DT]:
|
|
988
|
+
"""
|
|
989
|
+
Returns the indices of the maximum values along a specified axis.
|
|
990
|
+
|
|
991
|
+
When the maximum value occurs multiple times, only the indices corresponding to the first occurrence are returned.
|
|
992
|
+
|
|
993
|
+
- For backward compatibility, conforming implementations may support complex numbers; however, inequality comparison of complex numbers is unspecified and thus implementation-dependent.
|
|
994
|
+
- `self` should have a real-valued data type.
|
|
995
|
+
|
|
996
|
+
Parameters
|
|
997
|
+
----------
|
|
998
|
+
axis : Optional[int], default to `None`
|
|
999
|
+
Axis along which to search.
|
|
1000
|
+
- `None`: The function must return the index of the maximum value of the flattened `self`.
|
|
1001
|
+
|
|
1002
|
+
keepdims : bool, default to `False`
|
|
1003
|
+
- `True`: The reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with `self`.
|
|
1004
|
+
- `False`: The reduced axes (dimensions) must not be included in the result.
|
|
1005
|
+
|
|
1006
|
+
Returns
|
|
1007
|
+
-------
|
|
1008
|
+
CompatArray
|
|
1009
|
+
The returned :class:`CompatArray` array must have be the default array index data type.
|
|
1010
|
+
For :param:`axis`:
|
|
1011
|
+
- `None`: A zero-dimensional array containing the index of the first occurrence of the maximum value;
|
|
1012
|
+
- _others_: A non-zero-dimensional array containing the indices of the maximum values.
|
|
1013
|
+
"""
|
|
1014
|
+
...
|
|
1015
|
+
|
|
1016
|
+
def argmin(
|
|
1017
|
+
self, *,
|
|
1018
|
+
axis: Optional[int] = None,
|
|
1019
|
+
keepdims: bool = False
|
|
1020
|
+
) -> CompatArray[int, DT]:
|
|
1021
|
+
"""
|
|
1022
|
+
Returns the indices of the minimum values along a specified axis.
|
|
1023
|
+
|
|
1024
|
+
When the minimum value occurs multiple times, only the indices corresponding to the first occurrence are returned.
|
|
1025
|
+
|
|
1026
|
+
- For backward compatibility, conforming implementations may support complex numbers; however, inequality comparison of complex numbers is unspecified and thus implementation-dependent.
|
|
1027
|
+
- `self` should have a real-valued data type.
|
|
1028
|
+
|
|
1029
|
+
Parameters
|
|
1030
|
+
----------
|
|
1031
|
+
axis : Optional[int], default to `None`
|
|
1032
|
+
Axis along which to search.
|
|
1033
|
+
- `None`: The function must return the index of the minimum value of the flattened `self`.
|
|
1034
|
+
|
|
1035
|
+
keepdims : bool, default to `False`
|
|
1036
|
+
- `True`: The reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with `self`.
|
|
1037
|
+
- `False`: The reduced axes (dimensions) must not be included in the result.
|
|
1038
|
+
|
|
1039
|
+
Returns
|
|
1040
|
+
-------
|
|
1041
|
+
CompatArray
|
|
1042
|
+
The returned :class:`CompatArray` array must have be the default array index data type.
|
|
1043
|
+
For :param:`axis`:
|
|
1044
|
+
- `None`: A zero-dimensional array containing the index of the first occurrence of the minimum value;
|
|
1045
|
+
- _others_: A non-zero-dimensional array containing the indices of the minimum values.
|
|
1046
|
+
"""
|
|
1047
|
+
...
|
|
1048
|
+
|
|
1049
|
+
def nonzero(self) -> Tuple[CompatArray[int, DT], ...]: ...
|
|
1050
|
+
|
|
1051
|
+
def count_nonzero(
|
|
1052
|
+
self, *,
|
|
1053
|
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
|
1054
|
+
keepdims: bool = False
|
|
1055
|
+
) -> CompatArray[int, DT]:
|
|
1056
|
+
"""
|
|
1057
|
+
Counts the number of `self` elements which are non-zero.
|
|
1058
|
+
|
|
1059
|
+
Parameters
|
|
1060
|
+
----------
|
|
1061
|
+
axis : Optional[Union[int, Tuple[int, ...]]], default to `None`
|
|
1062
|
+
Axis or axes along which to count non-zero values.
|
|
1063
|
+
- `None`: The number of non-zero values must be computed over the entire `self`;
|
|
1064
|
+
- _Tuple[int, ...]_: The number of non-zero values must be computed over multiple axes.
|
|
1065
|
+
|
|
1066
|
+
keepdims : bool, default to `False`
|
|
1067
|
+
- `True`: The reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with `self`;
|
|
1068
|
+
- `False`: The reduced axes (dimensions) must not be included in the result.
|
|
1069
|
+
|
|
1070
|
+
Returns
|
|
1071
|
+
-------
|
|
1072
|
+
CompatArray
|
|
1073
|
+
The returned :class:`CompatArray` array must have the default array index data type.
|
|
1074
|
+
- computed over the entire `self`: A zero-dimensional array containing the total number of non-zero values;
|
|
1075
|
+
- _others_: A non-zero-dimensional array containing the counts along the specified axes.
|
|
1076
|
+
|
|
1077
|
+
Notes
|
|
1078
|
+
-----
|
|
1079
|
+
- If `self` has a complex floating-point data type, non-zero elements are those elements having at least one component (real or imaginary) which is non-zero;
|
|
1080
|
+
- If `self` has a boolean data type, non-zero elements are those elements which are equal to `True`.
|
|
1081
|
+
"""
|
|
1082
|
+
...
|
|
1083
|
+
|
|
1084
|
+
def searchsorted(
|
|
1085
|
+
self,
|
|
1086
|
+
other: ArrayLike[Any],
|
|
1087
|
+
/, *,
|
|
1088
|
+
side: Literal['left', 'right'] = "left",
|
|
1089
|
+
sorter: Optional[ArrayLike[Any]] = None
|
|
1090
|
+
) -> CompatArray[int, DT]:
|
|
1091
|
+
"""
|
|
1092
|
+
Finds the indices into `self` such that, if the corresponding elements in `other` were inserted before the indices, the order of `self`, when sorted in ascending order, would be preserved.
|
|
1093
|
+
- `self` must be a one-dimensional array. Should have a real-valued data type.
|
|
1094
|
+
- :param:`sorter` is `None`: `self` must be sorted in ascending order;
|
|
1095
|
+
- :param:`sorter` is not `None`: :param:`sorter` must be an array of indices that sort `self` in ascending order.
|
|
1096
|
+
|
|
1097
|
+
Parameters
|
|
1098
|
+
----------
|
|
1099
|
+
other : ArrayLike
|
|
1100
|
+
Array containing search values. Should have a real-valued data type.
|
|
1101
|
+
|
|
1102
|
+
side : Literal["left", "right"], default: "left"
|
|
1103
|
+
Argument controlling which index is returned if a value lands exactly on an edge.
|
|
1104
|
+
Let `v` be an element of `other` given by `v = other[j]`, where `j` refers to a valid index.
|
|
1105
|
+
- `v` < `self[any]`: `out[j]` must be `0`;
|
|
1106
|
+
- `v` > `self[any]`: `out[j]` must be `M`, where `M` is the number of elements in `self`.
|
|
1107
|
+
- _others_: Each returned index `i = out[j]` must satisfy an index condition:
|
|
1108
|
+
|
|
1109
|
+
- :param:`side` == `"left"`: `self[i-1] < v <= self[i]`;
|
|
1110
|
+
- :param:`side` == `"right"`: `self[i-1] <= v < self[i]`.
|
|
1111
|
+
|
|
1112
|
+
sorter : Optional[array], default: `None`
|
|
1113
|
+
Array of indices that sort `self` in ascending order.
|
|
1114
|
+
The array must have the same shape as `self` and have an integer data type.
|
|
1115
|
+
|
|
1116
|
+
Returns
|
|
1117
|
+
-------
|
|
1118
|
+
CompatArray
|
|
1119
|
+
A :class:`CompatArray` array of indices with the same shape as `other`.
|
|
1120
|
+
The returned array must have the default array index data type.
|
|
1121
|
+
|
|
1122
|
+
Notes
|
|
1123
|
+
-----
|
|
1124
|
+
- For real-valued floating-point arrays, the sort order of NaNs and signed zeros is unspecified and thus implementation-dependent. Accordingly, when a real-valued floating-point array contains NaNs and signed zeros, what constitutes ascending order may vary among specification-conforming array libraries.
|
|
1125
|
+
- While behavior for arrays containing NaNs and signed zeros is implementation-dependent, specification-conforming libraries should, however, ensure consistency with :meth:`CompatArray.sort` and :meth:`CompatArray.argsort` (i.e., if a value in `other` is inserted into `self` according to the corresponding index in the output array and sort is invoked on the resultant array, the sorted result should be an array in the same order).
|
|
1126
|
+
"""
|
|
1127
|
+
...
|
|
1128
|
+
|
|
1129
|
+
def where(self, X: ArrayOrAny, Y: ArrayOrAny, /) -> CompatArray[Any, DT]:
|
|
1130
|
+
"""
|
|
1131
|
+
Returns elements chosen from `X` or `Y` depending on condition `self`.
|
|
1132
|
+
- `self` is a condition array. Should have a boolean data type. Must be compatible with `X` and `Y`. For each element in `self`:
|
|
1133
|
+
- `True`: yield `X[i]`;
|
|
1134
|
+
- `False`: yield `Y[i]`.
|
|
1135
|
+
|
|
1136
|
+
Parameters
|
|
1137
|
+
----------
|
|
1138
|
+
X : ArrayOrAny
|
|
1139
|
+
First input array. Must be compatible with `self` and `Y`.
|
|
1140
|
+
|
|
1141
|
+
Y : ArrayOrAny
|
|
1142
|
+
Second input array. Must be compatible with `self` and `X`.
|
|
1143
|
+
|
|
1144
|
+
Returns
|
|
1145
|
+
-------
|
|
1146
|
+
CompatArray
|
|
1147
|
+
A :class:`CompatArray` array with elements from `X` where `self` is `True`, and elements from `Y` elsewhere.
|
|
1148
|
+
The returned array must have a data type determined by Type Promotion Rules rules with the arrays `X` and `Y`.
|
|
1149
|
+
|
|
1150
|
+
Notes
|
|
1151
|
+
- At least one of `X` and `Y` must be an array;
|
|
1152
|
+
- If either `X` or `Y` is a scalar value, the returned array must have a data type determined according to Mixing arrays with Python scalars.
|
|
1153
|
+
"""
|
|
1154
|
+
...
|
|
1155
|
+
|
|
1156
|
+
# === Set functions ===
|
|
1157
|
+
def unique_all(self) -> UniqueAllResult[TT, DT]: ...
|
|
1158
|
+
def unique_counts(self) -> UniqueCountsResult[TT, DT]: ...
|
|
1159
|
+
def unique_inverse(self) -> UniqueInverseResult[TT, DT]: ...
|
|
1160
|
+
|
|
1161
|
+
def unique_values(self) -> CompatArray[TT, DT]:
|
|
1162
|
+
"""
|
|
1163
|
+
Returns the unique elements of an input array `self`.
|
|
1164
|
+
- `self`:
|
|
1165
|
+
- more than one dimension: the function must flatten `self` and return the unique elements of the flattened `self`.
|
|
1166
|
+
|
|
1167
|
+
Returns
|
|
1168
|
+
-------
|
|
1169
|
+
CompatArray
|
|
1170
|
+
A one-dimensional :class:`CompatArray` array containing the set of unique elements in `self`.
|
|
1171
|
+
The returned array must have the same data type as `self`.
|
|
1172
|
+
"""
|
|
1173
|
+
...
|
|
1174
|
+
|
|
1175
|
+
# === Sorting functions ===
|
|
1176
|
+
def argsort(
|
|
1177
|
+
self, *,
|
|
1178
|
+
axis: int = -1,
|
|
1179
|
+
descending: bool = False,
|
|
1180
|
+
stable: bool = True
|
|
1181
|
+
) -> CompatArray[int, DT]:
|
|
1182
|
+
"""
|
|
1183
|
+
Returns the indices that sort `self` along a specified axis.
|
|
1184
|
+
|
|
1185
|
+
Parameters
|
|
1186
|
+
----------
|
|
1187
|
+
axis : int, default to `-1`
|
|
1188
|
+
Axis along which to sort.
|
|
1189
|
+
- `-1`: The function must sort along the last axis.
|
|
1190
|
+
|
|
1191
|
+
descending : bool, default to `False`
|
|
1192
|
+
Sort order.
|
|
1193
|
+
- `True`: The returned indices sort `self` in descending order (by value);
|
|
1194
|
+
- `False`: The returned indices sort `self` in ascending order (by value).
|
|
1195
|
+
|
|
1196
|
+
stable : bool, default to `True`
|
|
1197
|
+
Sort stability.
|
|
1198
|
+
- `True`: The returned indices must maintain the relative order of `self` values which compare as equal;
|
|
1199
|
+
- `False`: The returned indices may or may not maintain the relative order of `self` values which compare as equal (i.e., the relative order of `self` values which compare as equal is implementation-dependent).
|
|
1200
|
+
|
|
1201
|
+
Returns
|
|
1202
|
+
-------
|
|
1203
|
+
CompatArray
|
|
1204
|
+
A :class:`CompatArray` array of indices. The returned array must have the same shape as `self`.
|
|
1205
|
+
The returned array must have the default array index data type.
|
|
1206
|
+
"""
|
|
1207
|
+
...
|
|
1208
|
+
|
|
1209
|
+
def sort(
|
|
1210
|
+
self, *,
|
|
1211
|
+
axis: int = -1,
|
|
1212
|
+
descending: bool = False,
|
|
1213
|
+
stable: bool = True
|
|
1214
|
+
) -> CompatArray[TT, DT]:
|
|
1215
|
+
"""
|
|
1216
|
+
Returns a sorted copy of an input array `self`.
|
|
1217
|
+
|
|
1218
|
+
Parameters
|
|
1219
|
+
----------
|
|
1220
|
+
axis : int, default to `-1`
|
|
1221
|
+
Axis along which to sort.
|
|
1222
|
+
- `-1`: The function must sort along the last axis.
|
|
1223
|
+
|
|
1224
|
+
descending : bool, default to `False`
|
|
1225
|
+
Sort order.
|
|
1226
|
+
- `True`: The returned array must be sorted in descending order (by value);
|
|
1227
|
+
- `False`: The returned array must be sorted in ascending order (by value).
|
|
1228
|
+
|
|
1229
|
+
stable : bool, default to `True`
|
|
1230
|
+
Sort stability.
|
|
1231
|
+
- `True`: The returned array must maintain the relative order of `self` values which compare as equal;
|
|
1232
|
+
- `False`: The returned array may or may not maintain the relative order of `self` values which compare as equal (i.e., the relative order of `self` values which compare as equal is implementation-dependent).
|
|
1233
|
+
|
|
1234
|
+
Returns
|
|
1235
|
+
-------
|
|
1236
|
+
CompatArray
|
|
1237
|
+
A sorted :class:`CompatArray` array. The returned array must have the same data type and shape as `self`.
|
|
1238
|
+
"""
|
|
1239
|
+
...
|
|
1240
|
+
|
|
1241
|
+
# === Statistical functions ===
|
|
1242
|
+
@overload
|
|
1243
|
+
def cumulative_sum(self, *, axis: Optional[int] = ..., dtype: None = ..., include_initial: bool = ...) -> CompatArray[TT, DT]: ...
|
|
1244
|
+
@overload
|
|
1245
|
+
def cumulative_sum(self, *, axis: Optional[int] = ..., dtype: DTypeT, include_initial: bool = ...) -> CompatArray[DTypeT, DT]: ...
|
|
1246
|
+
|
|
1247
|
+
def cumulative_sum(
|
|
1248
|
+
self, *,
|
|
1249
|
+
axis: Optional[int] = None,
|
|
1250
|
+
dtype: Optional[DTypeT] = None,
|
|
1251
|
+
include_initial: bool = False
|
|
1252
|
+
) -> CompatArray[TT, DT]:
|
|
1253
|
+
"""
|
|
1254
|
+
Calculates the cumulative sum of elements in `self`.
|
|
1255
|
+
- `self` should have one or more dimensions (axes). Should have a numeric data type.
|
|
1256
|
+
|
|
1257
|
+
Parameters
|
|
1258
|
+
----------
|
|
1259
|
+
axis : Optional[int], default to `None`
|
|
1260
|
+
Axis along which a cumulative sum must be computed.
|
|
1261
|
+
- _negative_: The function must determine the axis along which to compute a cumulative sum by counting from the last dimension.
|
|
1262
|
+
|
|
1263
|
+
For dimension of `self`:
|
|
1264
|
+
- `1`: Providing an :param:`axis` is optional;
|
|
1265
|
+
- `> 1`: Providing an :param:`axis` is required.
|
|
1266
|
+
|
|
1267
|
+
dtype : Optional[dtype], default to `None`
|
|
1268
|
+
Data type of the returned array.
|
|
1269
|
+
- `None`: The returned array must have the same data type as `self`, unless `self` has an integer data type supporting a smaller range of values than the default integer data type (e.g., `self` has an `int16` or `uint32` data type and the default integer data type is `int64`). In those latter cases:
|
|
1270
|
+
|
|
1271
|
+
- `self` has a signed integer data type (e.g., `int16`): The returned array must have the default integer data type;
|
|
1272
|
+
- `self` has an unsigned integer data type (e.g., `uint16`): The returned array must have an unsigned integer data type having the same number of bits as the default integer data type (e.g., if the default integer data type is `int32`, the returned array must have a `uint32` data type).
|
|
1273
|
+
- `data type` differs from `self`: The input array should be cast to the specified data type before computing the sum (rationale: the dtype keyword argument is intended to help prevent overflows).
|
|
1274
|
+
|
|
1275
|
+
include_initial : bool, default to `False`
|
|
1276
|
+
Boolean indicating whether to include the initial value as the first value in the output.
|
|
1277
|
+
By convention, the initial value must be the additive identity (i.e., `zero`).
|
|
1278
|
+
|
|
1279
|
+
Returns
|
|
1280
|
+
-------
|
|
1281
|
+
CompatArray
|
|
1282
|
+
A :class:`CompatArray` array containing the cumulative sums.
|
|
1283
|
+
The returned array must have a data type as described by the :param:`dtype` above.
|
|
1284
|
+
|
|
1285
|
+
Let `N` be the size of the axis along which to compute the cumulative sum.
|
|
1286
|
+
The returned array must have a shape determined according to the following rules:
|
|
1287
|
+
- :param:`include_initial` is `True`: The returned array must have the same shape as `self`, except the size of the axis along which to compute the cumulative sum must be `N+1`;
|
|
1288
|
+
- :param:`include_initial` is `False`: The returned array must have the same shape as `self`.
|
|
1289
|
+
"""
|
|
1290
|
+
...
|
|
1291
|
+
|
|
1292
|
+
@overload
|
|
1293
|
+
def cumulative_prod(self, *, axis: Optional[int] = ..., dtype: None = ..., include_initial: bool = ...) -> CompatArray[TT, DT]: ...
|
|
1294
|
+
@overload
|
|
1295
|
+
def cumulative_prod(self, *, axis: Optional[int] = ..., dtype: DTypeT, include_initial: bool = ...) -> CompatArray[DTypeT, DT]: ...
|
|
1296
|
+
|
|
1297
|
+
def cumulative_prod(
|
|
1298
|
+
self, *,
|
|
1299
|
+
axis: Optional[int] = None,
|
|
1300
|
+
dtype: Optional[DTypeT] = None,
|
|
1301
|
+
include_initial: bool = False
|
|
1302
|
+
) -> CompatArray[TT, DT]:
|
|
1303
|
+
"""
|
|
1304
|
+
Calculates the cumulative product of elements in `self`.
|
|
1305
|
+
- `self` should have one or more dimensions (axes). Should have a numeric data type.
|
|
1306
|
+
|
|
1307
|
+
Parameters
|
|
1308
|
+
----------
|
|
1309
|
+
axis : Optional[int], default to `None`
|
|
1310
|
+
Axis along which a cumulative product must be computed.
|
|
1311
|
+
- _negative_: The function must determine the axis along which to compute a cumulative product by counting from the last dimension.
|
|
1312
|
+
|
|
1313
|
+
For dimension of `self`:
|
|
1314
|
+
- `1`: Providing an :param:`axis` is optional;
|
|
1315
|
+
- `> 1`: Providing an :param:`axis` is required.
|
|
1316
|
+
|
|
1317
|
+
dtype : Optional[dtype], default to `None`
|
|
1318
|
+
Data type of the returned array.
|
|
1319
|
+
- `None`: The returned array must have the same data type as `self`, unless `self` has an integer data type supporting a smaller range of values than the default integer data type (e.g., `self` has an `int16` or `uint32` data type and the default integer data type is `int64`). In those latter cases:
|
|
1320
|
+
|
|
1321
|
+
- `self` has a signed integer data type (e.g., `int16`): The returned array must have the default integer data type;
|
|
1322
|
+
- `self` has an unsigned integer data type (e.g., `uint16`): The returned array must have an unsigned integer data type having the same number of bits as the default integer data type (e.g., if the default integer data type is `int32`, the returned array must have a `uint32` data type).
|
|
1323
|
+
- `data type` differs from `self`: The input array should be cast to the specified data type before computing the product (rationale: the dtype keyword argument is intended to help prevent overflows).
|
|
1324
|
+
|
|
1325
|
+
include_initial : bool, default to `False`
|
|
1326
|
+
Boolean indicating whether to include the initial value as the first value in the output.
|
|
1327
|
+
By convention, the initial value must be the multiplicative identity (i.e., `one`).
|
|
1328
|
+
|
|
1329
|
+
Returns
|
|
1330
|
+
-------
|
|
1331
|
+
CompatArray
|
|
1332
|
+
A :class:`CompatArray` array containing the cumulative products.
|
|
1333
|
+
The returned array must have a data type as described by the :param:`dtype` above.
|
|
1334
|
+
|
|
1335
|
+
Let `N` be the size of the axis along which to compute the cumulative product.
|
|
1336
|
+
The returned array must have a shape determined according to the following rules:
|
|
1337
|
+
- :param:`include_initial` is `True`: The returned array must have the same shape as `self`, except the size of the axis along which to compute the cumulative product must be `N+1`;
|
|
1338
|
+
- :param:`include_initial` is `False`: The returned array must have the same shape as `self`.
|
|
1339
|
+
"""
|
|
1340
|
+
...
|
|
1341
|
+
|
|
1342
|
+
def max(
|
|
1343
|
+
self, *,
|
|
1344
|
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
|
1345
|
+
keepdims: bool = False
|
|
1346
|
+
) -> CompatArray[TT, DT]:
|
|
1347
|
+
"""
|
|
1348
|
+
Calculates the maximum value of `self`.
|
|
1349
|
+
|
|
1350
|
+
Parameters
|
|
1351
|
+
----------
|
|
1352
|
+
axis : Optional[Union[int, Tuple[int, ...]]], default to `None`
|
|
1353
|
+
Axis or axes along which maximum values must be computed.
|
|
1354
|
+
- `None`: The maximum value must be computed over the entire `self`;
|
|
1355
|
+
- _Tuple[int, ...]_: The maximum value must be computed over multiple axes.
|
|
1356
|
+
|
|
1357
|
+
keepdims : bool, default to `False`
|
|
1358
|
+
- `True`: The reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with `self`;
|
|
1359
|
+
- `False`: The reduced axes (dimensions) must not be included in the result.
|
|
1360
|
+
|
|
1361
|
+
Returns
|
|
1362
|
+
-------
|
|
1363
|
+
CompatArray
|
|
1364
|
+
The returned :class:`CompatArray` array must have the same data type as `self`.
|
|
1365
|
+
- computed over the entire `self`: a zero-dimensional array containing the maximum value;
|
|
1366
|
+
- _others_: a non-zero-dimensional array containing the maximum values.
|
|
1367
|
+
|
|
1368
|
+
Notes
|
|
1369
|
+
-----
|
|
1370
|
+
- For floating-point operands.
|
|
1371
|
+
- `self[any]` is `NaN`: The maximum value is `NaN` (i.e., `NaN` values propagate).
|
|
1372
|
+
"""
|
|
1373
|
+
...
|
|
1374
|
+
|
|
1375
|
+
def mean(
|
|
1376
|
+
self, *,
|
|
1377
|
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
|
1378
|
+
keepdims: bool = False
|
|
1379
|
+
) -> CompatArray[TT, DT]:
|
|
1380
|
+
"""
|
|
1381
|
+
Calculates the arithmetic mean of `self`.
|
|
1382
|
+
|
|
1383
|
+
Parameters
|
|
1384
|
+
----------
|
|
1385
|
+
axis : Optional[Union[int, Tuple[int, ...]]], default to `None`
|
|
1386
|
+
Axis or axes along which arithmetic means must be computed.
|
|
1387
|
+
- `None`: The mean must be computed over the entire `self`;
|
|
1388
|
+
- _Tuple[int, ...]_: The arithmetic mean must be computed over multiple axes.
|
|
1389
|
+
|
|
1390
|
+
keepdims : bool, default to `False`
|
|
1391
|
+
- `True`: The reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with `self`;
|
|
1392
|
+
- `False`: The reduced axes (dimensions) must not be included in the result.
|
|
1393
|
+
|
|
1394
|
+
Returns
|
|
1395
|
+
-------
|
|
1396
|
+
CompatArray
|
|
1397
|
+
The returned :class:`CompatArray` array must have the same data type as `self`.
|
|
1398
|
+
- computed over the entire `self`: a zero-dimensional array containing the arithmetic mean;
|
|
1399
|
+
- _others_: a non-zero-dimensional array containing the arithmetic means.
|
|
1400
|
+
|
|
1401
|
+
Notes
|
|
1402
|
+
-----
|
|
1403
|
+
- Let `N` equal the number of elements over which to compute the arithmetic mean. For real-valued operands,
|
|
1404
|
+
- `N` is `0`: The arithmetic mean is `NaN` (i.e., division by zero results in `NaN`);
|
|
1405
|
+
- `self[any]` is `NaN`: The arithmetic mean is `NaN` (i.e., `NaN` values propagate).
|
|
1406
|
+
- For complex floating-point operands, real-valued floating-point special cases should independently apply to the real and imaginary component operations involving real numbers. For example, let `a = real(x_i) and b = imag(x_i)`, and
|
|
1407
|
+
- `N` is `0`: The arithmetic mean is `NaN + NaN j` (i.e., division by zero results in `NaN` for both the real and imaginary components);
|
|
1408
|
+
- `a` is `NaN`: The real component of the arithmetic mean is `NaN` (i.e., division by zero results in `NaN` for the real component);
|
|
1409
|
+
- `b` is `NaN`: The imaginary component of the arithmetic mean is `NaN` (i.e., division by zero results in `NaN` for the imaginary component).
|
|
1410
|
+
"""
|
|
1411
|
+
...
|
|
1412
|
+
|
|
1413
|
+
def min(
|
|
1414
|
+
self, *,
|
|
1415
|
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
|
1416
|
+
keepdims: bool = False
|
|
1417
|
+
) -> CompatArray[TT, DT]:
|
|
1418
|
+
"""
|
|
1419
|
+
Calculates the minimum value of `self`.
|
|
1420
|
+
|
|
1421
|
+
Parameters
|
|
1422
|
+
----------
|
|
1423
|
+
axis : Optional[Union[int, Tuple[int, ...]]], default to `None`
|
|
1424
|
+
Axis or axes along which minimum values must be computed.
|
|
1425
|
+
- `None`: The minimum value must be computed over the entire `self`;
|
|
1426
|
+
- _Tuple[int, ...]_: The minimum value must be computed over multiple axes.
|
|
1427
|
+
|
|
1428
|
+
keepdims : bool, default to `False`
|
|
1429
|
+
- `True`: The reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with `self`;
|
|
1430
|
+
- `False`: The reduced axes (dimensions) must not be included in the result.
|
|
1431
|
+
|
|
1432
|
+
Returns
|
|
1433
|
+
-------
|
|
1434
|
+
CompatArray
|
|
1435
|
+
The returned :class:`CompatArray` array must have the same data type as `self`.
|
|
1436
|
+
- computed over the entire `self`: a zero-dimensional array containing the minimum value;
|
|
1437
|
+
- _others_: a non-zero-dimensional array containing the minimum values.
|
|
1438
|
+
|
|
1439
|
+
Notes
|
|
1440
|
+
-----
|
|
1441
|
+
- For floating-point operands.
|
|
1442
|
+
- `self[any]` is `NaN`: The minimum value is `NaN` (i.e., `NaN` values propagate).
|
|
1443
|
+
"""
|
|
1444
|
+
...
|
|
1445
|
+
|
|
1446
|
+
@overload
|
|
1447
|
+
def prod(self, *, axis: Optional[Union[int, Tuple[int, ...]]] = ..., dtype: None = ..., keepdims: bool = ...) -> CompatArray[TT, DT]: ...
|
|
1448
|
+
@overload
|
|
1449
|
+
def prod(self, *, axis: Optional[Union[int, Tuple[int, ...]]] = ..., dtype: DTypeT, keepdims: bool = ...) -> CompatArray[DTypeT, DT]: ...
|
|
1450
|
+
|
|
1451
|
+
def prod(
|
|
1452
|
+
self, *,
|
|
1453
|
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
|
1454
|
+
dtype: Optional[DTypeT] = None,
|
|
1455
|
+
keepdims: bool = False
|
|
1456
|
+
) -> CompatArray[TT, DT]:
|
|
1457
|
+
"""
|
|
1458
|
+
Calculates the product of `self` elements.
|
|
1459
|
+
|
|
1460
|
+
Parameters
|
|
1461
|
+
----------
|
|
1462
|
+
axis : Optional[Union[int, Tuple[int, ...]]], default to `None`
|
|
1463
|
+
Axis or axes along which products must be computed.
|
|
1464
|
+
- `None`: The product must be computed over the entire `self`;
|
|
1465
|
+
- _Tuple[int, ...]_: The product must be computed over multiple axes.
|
|
1466
|
+
|
|
1467
|
+
dtype : Optional[dtype], default to `None`
|
|
1468
|
+
Data type of the returned array.
|
|
1469
|
+
- `None`: The returned array must have the same data type as `self`, unless `self` has an integer data type supporting a smaller range of values than the default integer data type (e.g., `self` has an `int16` or `uint32` data type and the default integer data type is `int64`). In those latter cases:
|
|
1470
|
+
|
|
1471
|
+
- `self` has a signed integer data type (e.g., `int16`): The returned array must have the default integer data type;
|
|
1472
|
+
- `self` has an unsigned integer data type (e.g., `uint16`): The returned array must have an unsigned integer data type having the same number of bits as the default integer data type (e.g., if the default integer data type is `int32`, the returned array must have a `uint32` data type).
|
|
1473
|
+
- `data type` differs from `self`: The input array should be cast to the specified data type before computing the product (rationale: the dtype keyword argument is intended to help prevent overflows).
|
|
1474
|
+
|
|
1475
|
+
keepdims : bool, default to `False`
|
|
1476
|
+
- `True`: The reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with `self`;
|
|
1477
|
+
- `False`: The reduced axes (dimensions) must not be included in the result.
|
|
1478
|
+
|
|
1479
|
+
Returns
|
|
1480
|
+
-------
|
|
1481
|
+
CompatArray
|
|
1482
|
+
The returned :class:`CompatArray` array must have a data type as described by the :param:`dtype` above.
|
|
1483
|
+
- computed over the entire `self`: a zero-dimensional array containing the product;
|
|
1484
|
+
- _others_: a non-zero-dimensional array containing the products.
|
|
1485
|
+
|
|
1486
|
+
Notes
|
|
1487
|
+
-----
|
|
1488
|
+
- Let `N` equal the number of elements over which to compute the product.
|
|
1489
|
+
- `N` is `0`: The product is `1` (i.e., the empty product).
|
|
1490
|
+
"""
|
|
1491
|
+
...
|
|
1492
|
+
|
|
1493
|
+
def std(
|
|
1494
|
+
self, *,
|
|
1495
|
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
|
1496
|
+
correction: Union[int, float] = 0,
|
|
1497
|
+
keepdims: bool = False
|
|
1498
|
+
) -> CompatArray[TT, DT]:
|
|
1499
|
+
"""
|
|
1500
|
+
Calculates the standard deviation of `self`.
|
|
1501
|
+
|
|
1502
|
+
Parameters
|
|
1503
|
+
----------
|
|
1504
|
+
axis : Optional[Union[int, Tuple[int, ...]]], default to `None`
|
|
1505
|
+
Axis or axes along which standard deviations must be computed.
|
|
1506
|
+
- `None`: The standard deviation must be computed over the entire `self`;
|
|
1507
|
+
- _Tuple[int, ...]_: The standard deviation must be computed over multiple axes.
|
|
1508
|
+
|
|
1509
|
+
correction : Union[int, float], default to `0`
|
|
1510
|
+
Degrees of freedom adjustment.
|
|
1511
|
+
Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the standard deviation according to `N-c` where `N` corresponds to the total number of elements over which the standard deviation is computed and `c` corresponds to the provided degrees of freedom adjustment.
|
|
1512
|
+
When computing the standard deviation of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population).
|
|
1513
|
+
When computing the corrected sample standard deviation, setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel’s correction).
|
|
1514
|
+
|
|
1515
|
+
keepdims : bool, default to `False`
|
|
1516
|
+
- `True`: The reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with `self`;
|
|
1517
|
+
- `False`: The reduced axes (dimensions) must not be included in the result.
|
|
1518
|
+
|
|
1519
|
+
Returns
|
|
1520
|
+
-------
|
|
1521
|
+
CompatArray
|
|
1522
|
+
The returned :class:`CompatArray` array must have the same data type as `self`.
|
|
1523
|
+
- computed over the entire `self`: a zero-dimensional array containing the standard deviation;
|
|
1524
|
+
- _others_: a non-zero-dimensional array containing the standard deviations.
|
|
1525
|
+
|
|
1526
|
+
Notes
|
|
1527
|
+
-----
|
|
1528
|
+
- Let `N` equal the number of elements over which to compute the standard deviation.
|
|
1529
|
+
- `N - correction <= 0`: The standard deviation is `NaN`;
|
|
1530
|
+
- `self[any]` is `NaN`: The standard deviation is `NaN` (i.e., `NaN` values propagate).
|
|
1531
|
+
"""
|
|
1532
|
+
...
|
|
1533
|
+
|
|
1534
|
+
@overload
|
|
1535
|
+
def sum(self, *, axis: Optional[Union[int, Tuple[int, ...]]] = ..., dtype: None = ..., keepdims: bool = ...) -> CompatArray[TT, DT]: ...
|
|
1536
|
+
@overload
|
|
1537
|
+
def sum(self, *, axis: Optional[Union[int, Tuple[int, ...]]] = ..., dtype: DTypeT, keepdims: bool = ...) -> CompatArray[DTypeT, DT]: ...
|
|
1538
|
+
|
|
1539
|
+
def sum(
|
|
1540
|
+
self, *,
|
|
1541
|
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
|
1542
|
+
dtype: Optional[DTypeT] = None,
|
|
1543
|
+
keepdims: bool = False
|
|
1544
|
+
) -> CompatArray[TT, DT]:
|
|
1545
|
+
"""
|
|
1546
|
+
Calculates the sum of the `self`.
|
|
1547
|
+
|
|
1548
|
+
Parameters
|
|
1549
|
+
----------
|
|
1550
|
+
axis : Optional[Union[int, Tuple[int, ...]]], default to `None`
|
|
1551
|
+
Axis or axes along which sums must be computed.
|
|
1552
|
+
- `None`: The sum must be computed over the entire `self`;
|
|
1553
|
+
- _Tuple[int, ...]_: The sum must be computed over multiple axes.
|
|
1554
|
+
|
|
1555
|
+
dtype : Optional[dtype], default to `None`
|
|
1556
|
+
Data type of the returned array.
|
|
1557
|
+
- `None`: The returned array must have the same data type as `self`, unless `self` has an integer data type supporting a smaller range of values than the default integer data type (e.g., `self` has an `int16` or `uint32` data type and the default integer data type is `int64`). In those latter cases:
|
|
1558
|
+
|
|
1559
|
+
- `self` has a signed integer data type (e.g., `int16`): The returned array must have the default integer data type;
|
|
1560
|
+
- `self` has an unsigned integer data type (e.g., `uint16`): The returned array must have an unsigned integer data type having the same number of bits as the default integer data type (e.g., if the default integer data type is `int32`, the returned array must have a `uint32` data type).
|
|
1561
|
+
- `data type` differs from `self`: The input array should be cast to the specified data type before computing the sum (rationale: the dtype keyword argument is intended to help prevent overflows).
|
|
1562
|
+
|
|
1563
|
+
keepdims : bool, default to `False`
|
|
1564
|
+
- `True`: The reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with `self`;
|
|
1565
|
+
- `False`: The reduced axes (dimensions) must not be included in the result.
|
|
1566
|
+
|
|
1567
|
+
Returns
|
|
1568
|
+
-------
|
|
1569
|
+
CompatArray
|
|
1570
|
+
The returned :class:`CompatArray` array must have a data type as described by the :param:`dtype` above.
|
|
1571
|
+
- computed over the entire `self`: a zero-dimensional array containing the sum;
|
|
1572
|
+
- _others_: a non-zero-dimensional array containing the sums.
|
|
1573
|
+
|
|
1574
|
+
Notes
|
|
1575
|
+
-----
|
|
1576
|
+
- Let `N` equal the number of elements over which to compute the sum.
|
|
1577
|
+
- `N` is `0`: The sum is `0` (i.e., the empty sum).
|
|
1578
|
+
"""
|
|
1579
|
+
...
|
|
1580
|
+
|
|
1581
|
+
def var(
|
|
1582
|
+
self, *,
|
|
1583
|
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
|
1584
|
+
correction: Union[int, float] = 0,
|
|
1585
|
+
keepdims: bool = False
|
|
1586
|
+
) -> CompatArray[TT, DT]:
|
|
1587
|
+
"""
|
|
1588
|
+
Calculates the variance of `self`.
|
|
1589
|
+
|
|
1590
|
+
Parameters
|
|
1591
|
+
----------
|
|
1592
|
+
axis : Optional[Union[int, Tuple[int, ...]]], default to `None`
|
|
1593
|
+
Axis or axes along which variances must be computed.
|
|
1594
|
+
- `None`: The variance must be computed over the entire `self`;
|
|
1595
|
+
- _Tuple[int, ...]_: The variance must be computed over multiple axes.
|
|
1596
|
+
|
|
1597
|
+
correction : Union[int, float], default to `0`
|
|
1598
|
+
Degrees of freedom adjustment.
|
|
1599
|
+
Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the variance according to `N-c` where `N` corresponds to the total number of elements over which the variance is computed and `c` corresponds to the provided degrees of freedom adjustment.
|
|
1600
|
+
When computing the variance of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population).
|
|
1601
|
+
When computing the unbiased sample variance, setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel’s correction).
|
|
1602
|
+
|
|
1603
|
+
keepdims : bool, default to `False`
|
|
1604
|
+
- `True`: The reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with `self`;
|
|
1605
|
+
- `False`: The reduced axes (dimensions) must not be included in the result.
|
|
1606
|
+
|
|
1607
|
+
Returns
|
|
1608
|
+
-------
|
|
1609
|
+
CompatArray
|
|
1610
|
+
The returned :class:`CompatArray` array must have the same data type as `self`.
|
|
1611
|
+
- computed over the entire `self`: a zero-dimensional array containing the variance;
|
|
1612
|
+
- _others_: a non-zero-dimensional array containing the variances.
|
|
1613
|
+
|
|
1614
|
+
Notes
|
|
1615
|
+
-----
|
|
1616
|
+
- Let `N` equal the number of elements over which to compute the variance.
|
|
1617
|
+
- `N - correction <= 0`: The variance is `NaN` (i.e., division by zero results in `NaN`);
|
|
1618
|
+
- `self[any]` is `NaN`: The variance is `NaN` (i.e., `NaN` values propagate).
|
|
1619
|
+
"""
|
|
1620
|
+
...
|
|
1621
|
+
|
|
1622
|
+
# === Utility functions ===
|
|
1623
|
+
def all(
|
|
1624
|
+
self, *,
|
|
1625
|
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
|
1626
|
+
keepdims: bool = False
|
|
1627
|
+
) -> CompatArray[bool, DT]:
|
|
1628
|
+
"""
|
|
1629
|
+
Tests whether all `self` elements evaluate to `True` along a specified axis.
|
|
1630
|
+
- `Positive infinity`, `negative infinity`, and `NaN` must evaluate to `True`;
|
|
1631
|
+
- If `self` is an empty array or the size of the axis (dimension) along which to evaluate elements is `zero`, the test result must be `True`.
|
|
1632
|
+
|
|
1633
|
+
Parameters
|
|
1634
|
+
----------
|
|
1635
|
+
axis : Optional[Union[int, Tuple[int, ...]]], default to `None`
|
|
1636
|
+
Axis or axes along which to perform a `logical AND` reduction.
|
|
1637
|
+
- `None`: A `logical AND` reduction must be performed over the entire array.
|
|
1638
|
+
- _Tuple[int, ...]_: `logical AND` reductions must be performed over multiple axes.
|
|
1639
|
+
A valid :param:`axis` must be an integer on the interval `[-N, N)`, where `N` is the rank (number of dimensions) of `self`. For each axis:
|
|
1640
|
+
- _negative_integer_: The function must determine the axis along which to perform a reduction by counting backward from the last dimension (where `-1` refers to the last dimension);
|
|
1641
|
+
- _invalid_: The function must raise an exception.
|
|
1642
|
+
|
|
1643
|
+
keepdims : bool, default to `False`
|
|
1644
|
+
- `True`: The reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with `self`;
|
|
1645
|
+
- `False`: The reduced axes (dimensions) must not be included in the result.
|
|
1646
|
+
|
|
1647
|
+
Returns
|
|
1648
|
+
-------
|
|
1649
|
+
CompatArray
|
|
1650
|
+
The returned :class:`CompatArray` array must have a data type of `bool`.
|
|
1651
|
+
- computed over the entire `self`: a zero-dimensional array containing the test result;
|
|
1652
|
+
- _others_: a non-zero-dimensional array containing the test results.
|
|
1653
|
+
"""
|
|
1654
|
+
...
|
|
1655
|
+
|
|
1656
|
+
def any(
|
|
1657
|
+
self, *,
|
|
1658
|
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
|
1659
|
+
keepdims: bool = False
|
|
1660
|
+
) -> CompatArray[bool, DT]:
|
|
1661
|
+
"""
|
|
1662
|
+
Tests whether any `self` elements evaluate to `True` along a specified axis.
|
|
1663
|
+
- `Positive infinity`, `negative infinity`, and `NaN` must evaluate to `True`;
|
|
1664
|
+
- If `self` is an empty array or the size of the axis (dimension) along which to evaluate elements is `zero`, the test result must be `False`.
|
|
1665
|
+
|
|
1666
|
+
Parameters
|
|
1667
|
+
----------
|
|
1668
|
+
axis : Optional[Union[int, Tuple[int, ...]]], default to `None`
|
|
1669
|
+
Axis or axes along which to perform a `logical OR` reduction.
|
|
1670
|
+
- `None`: A `logical OR` reduction must be performed over the entire array.
|
|
1671
|
+
- _Tuple[int, ...]_: `logical OR` reductions must be performed over multiple axes.
|
|
1672
|
+
A valid :param:`axis` must be an integer on the interval `[-N, N)`, where `N` is the rank (number of dimensions) of `self`. For each axis:
|
|
1673
|
+
- _negative_integer_: The function must determine the axis along which to perform a reduction by counting backward from the last dimension (where `-1` refers to the last dimension);
|
|
1674
|
+
- _invalid_: The function must raise an exception.
|
|
1675
|
+
|
|
1676
|
+
keepdims : bool, default to `False`
|
|
1677
|
+
- `True`: The reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with `self`;
|
|
1678
|
+
- `False`: The reduced axes (dimensions) must not be included in the result.
|
|
1679
|
+
|
|
1680
|
+
Returns
|
|
1681
|
+
-------
|
|
1682
|
+
CompatArray
|
|
1683
|
+
The returned :class:`CompatArray` array must have a data type of `bool`.
|
|
1684
|
+
- computed over the entire `self`: a zero-dimensional array containing the test result;
|
|
1685
|
+
- _others_: a non-zero-dimensional array containing the test results.
|
|
1686
|
+
"""
|
|
1687
|
+
...
|
|
1688
|
+
|
|
1689
|
+
def diff(
|
|
1690
|
+
self, *,
|
|
1691
|
+
axis: int = -1,
|
|
1692
|
+
n: int = 1,
|
|
1693
|
+
prepend: Optional[ArrayLike[Any]] = None,
|
|
1694
|
+
append: Optional[ArrayLike[Any]] = None
|
|
1695
|
+
) -> CompatArray[TT, DT]:
|
|
1696
|
+
"""
|
|
1697
|
+
Calculates the n-th discrete forward difference along a specified axis.
|
|
1698
|
+
|
|
1699
|
+
Parameters
|
|
1700
|
+
----------
|
|
1701
|
+
axis : Optional[Union[int, Tuple[int, ...]]], default to `None`
|
|
1702
|
+
Axis or axes along which to compute differences.
|
|
1703
|
+
A valid :param:`axis` must be an integer on the interval `[-N, N)`, where `N` is the rank (number of dimensions) of `self`. For each axis:
|
|
1704
|
+
- _negative_integer_: The function must determine the axis along which to perform a reduction by counting backward from the last dimension (where `-1` refers to the last dimension);
|
|
1705
|
+
- _invalid_: The function must raise an exception.
|
|
1706
|
+
|
|
1707
|
+
n : int, default to `1`
|
|
1708
|
+
Number of times to recursively compute differences.
|
|
1709
|
+
|
|
1710
|
+
prepend : Optional[array], default to `None`
|
|
1711
|
+
Values to prepend to a specified axis prior to computing differences.
|
|
1712
|
+
Must have the same shape as `self`, except for the axis specified by :param:`axis` which may have any size. Should have the same data type as `self`.
|
|
1713
|
+
|
|
1714
|
+
append : Optional[array], default to `None`
|
|
1715
|
+
Values to append to a specified axis prior to computing differences.
|
|
1716
|
+
Must have the same shape as `self`, except for the axis specified by :param:`axis` which may have any size. Should have the same data type as `self`.
|
|
1717
|
+
|
|
1718
|
+
Returns
|
|
1719
|
+
-------
|
|
1720
|
+
CompatArray
|
|
1721
|
+
A :class:`CompatArray` array containing the `n`-th differences.
|
|
1722
|
+
Should have the same data type as `self`.
|
|
1723
|
+
Must have the same shape as `self`, except for the axis specified by :param:`axis` which must have a size determined as follows:
|
|
1724
|
+
- Let M be the number of elements along an axis specified by :param:`axis`.
|
|
1725
|
+
- Let N1 be the number of prepended values along an axis specified by :param:`axis`.
|
|
1726
|
+
- Let N2 be the number of appended values along an axis specified by :param:`axis`.
|
|
1727
|
+
|
|
1728
|
+
The final size of the axis specified by :param:`axis` must be `M + N1 + N2 - n`.
|
|
1729
|
+
|
|
1730
|
+
Notes
|
|
1731
|
+
-----
|
|
1732
|
+
- The first-order differences are given by `out[i] = self[i+1] - self[i]` along a specified axis.
|
|
1733
|
+
Higher-order differences must be calculated recursively (e.g., by calling `diff(out, axis=axis, n=n-1)`).
|
|
1734
|
+
- If a conforming implementation chooses to support :param:`prepend` and :param:`append` arrays which have a different data type than `self`, behavior is unspecified and thus implementation-defined.
|
|
1735
|
+
Implementations may choose to type promote (Type Promotion Rules), cast :param:`prepend` and/or :param:`append` to the same data type as `self`, or raise an exception.
|
|
1736
|
+
"""
|
|
1737
|
+
...
|
|
1738
|
+
|
|
1739
|
+
# === Others ===
|
|
1740
|
+
def copy(self) -> CompatArray[TT, DT]: ...
|
|
1741
|
+
|
|
1742
|
+
# === Array attributes ===
|
|
1743
|
+
@property
|
|
1744
|
+
def arr(self) -> ArrayLike[TT]: ...
|
|
1745
|
+
@property
|
|
1746
|
+
def dtype(self) -> TT: ...
|
|
1747
|
+
@property
|
|
1748
|
+
def device(self) -> DT: ...
|
|
1749
|
+
@property
|
|
1750
|
+
def shape(self) -> Tuple[int, ...]: ...
|
|
1751
|
+
@property
|
|
1752
|
+
def ndim(self) -> int: ...
|
|
1753
|
+
@property
|
|
1754
|
+
def size(self) -> Optional[int]: ...
|
|
1755
|
+
@property
|
|
1756
|
+
def T(self) -> CompatArray[TT, DT]: ...
|
|
1757
|
+
@property
|
|
1758
|
+
def mT(self) -> CompatArray[TT, DT]: ...
|
|
1759
|
+
|
|
1760
|
+
def __array__(self) -> NDArray[TT]: ...
|
|
1761
|
+
|
|
1762
|
+
def __len__(self) -> int: ...
|
|
1763
|
+
def __abs__(self) -> CompatArray[TT, DT]: ...
|
|
1764
|
+
def __add__(self, other: ArrayOrScalar, /) -> CompatArray[Any, DT]: ...
|
|
1765
|
+
def __and__(self, other: ArrayOrIntLike, /) -> CompatArray[TT, DT]: ...
|
|
1766
|
+
def __bool__(self) -> bool: ...
|
|
1767
|
+
def __complex__(self) -> complex: ...
|
|
1768
|
+
def __eq__(self, other: ArrayOrAny, /) -> CompatArray[bool, DT]: ...
|
|
1769
|
+
def __float__(self) -> float: ...
|
|
1770
|
+
def __floordiv__(self, other: ArrayOrReal, /) -> CompatArray[TT, DT]: ...
|
|
1771
|
+
def __ge__(self, other: ArrayOrReal, /) -> CompatArray[bool, DT]: ...
|
|
1772
|
+
def __getitem__(self, key: Any, /) -> CompatArray[TT, DT]: ...
|
|
1773
|
+
def __gt__(self, other: ArrayOrReal, /) -> CompatArray[bool, DT]: ...
|
|
1774
|
+
def __index__(self) -> int: ...
|
|
1775
|
+
def __int__(self) -> int: ...
|
|
1776
|
+
def __invert__(self) -> CompatArray[TT, DT]: ...
|
|
1777
|
+
def __le__(self, other: ArrayOrReal, /) -> CompatArray[bool, DT]: ...
|
|
1778
|
+
def __lshift__(self, other: ArrayOrInt, /) -> CompatArray[TT, DT]: ...
|
|
1779
|
+
def __lt__(self, other: ArrayOrReal, /) -> CompatArray[bool, DT]: ...
|
|
1780
|
+
def __matmul__(self, other: ArrayLike[Any], /) -> CompatArray[Any, DT]: ...
|
|
1781
|
+
def __mod__(self, other: ArrayOrReal, /) -> CompatArray[Any, DT]: ...
|
|
1782
|
+
def __mul__(self, other: ArrayOrScalar, /) -> CompatArray[Any, DT]: ...
|
|
1783
|
+
def __ne__(self, other: ArrayOrAny, /) -> CompatArray[bool, DT]: ...
|
|
1784
|
+
def __neg__(self) -> CompatArray[TT, DT]: ...
|
|
1785
|
+
def __or__(self, other: ArrayOrIntLike, /) -> CompatArray[TT, DT]: ...
|
|
1786
|
+
def __pos__(self) -> CompatArray[TT, DT]: ...
|
|
1787
|
+
def __pow__(self, other: ArrayOrScalar, /) -> CompatArray[Any, DT]: ...
|
|
1788
|
+
def __rshift__(self, other: ArrayOrInt, /) -> CompatArray[TT, DT]: ...
|
|
1789
|
+
def __setitem__(self, key: Any, value: Any, /): ...
|
|
1790
|
+
def __sub__(self, other: ArrayOrScalar, /) -> CompatArray[Any, DT]: ...
|
|
1791
|
+
def __truediv__(self, other: ArrayOrScalar, /) -> CompatArray[float, DT]: ...
|
|
1792
|
+
def __xor__(self, other: ArrayOrIntLike, /) -> CompatArray[TT, DT]: ...
|
|
1793
|
+
|
|
1794
|
+
|
|
1795
|
+
@overload
|
|
1796
|
+
def unwrap(obj: CompatArray[dtypeT, Any]) -> ArrayLike[dtypeT]: ...
|
|
1797
|
+
@overload
|
|
1798
|
+
def unwrap(obj: ArrayLike[dtypeT]) -> ArrayLike[dtypeT]: ...
|
|
1799
|
+
@overload
|
|
1800
|
+
def unwrap(obj: T) -> T: ...
|
|
1801
|
+
|
|
1802
|
+
|
|
1803
|
+
def unwrap(obj: Any) -> Any: ...
|
|
1804
|
+
|
|
1805
|
+
|
|
1806
|
+
@overload
|
|
1807
|
+
def wrap_arraylike(arr: NDArray[dtypeT], xp: Optional[object] = ...) -> CompatArray[dtypeT, Literal["cpu"]]: ...
|
|
1808
|
+
@overload
|
|
1809
|
+
def wrap_arraylike(arr: CompatArray[dtypeT, deviceT], xp: Optional[object] = ...) -> CompatArray[dtypeT, deviceT]: ...
|
|
1810
|
+
@overload
|
|
1811
|
+
def wrap_arraylike(arr: ArrayLike[dtypeT], xp: Optional[object] = ...) -> CompatArray[dtypeT, Any]: ...
|
|
1812
|
+
@overload
|
|
1813
|
+
def wrap_arraylike(arr: T, xp: Optional[object] = ...) -> T: ...
|
|
1814
|
+
|
|
1815
|
+
|
|
1816
|
+
def wrap_arraylike(arr: Any, xp: Optional[object] = None) -> Any: ...
|