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.
@@ -0,0 +1,833 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Python version: 3.9
3
+ # @TianZhen
4
+
5
+ from __future__ import annotations
6
+ from numpy.typing import NDArray
7
+ from typing import (Union, List, Tuple, Optional, Any, Literal, overload)
8
+
9
+ from ._base import Compat
10
+ from ._array import CompatArray
11
+ from ..types import (
12
+ DTypeT, DeviceT, dtypeT, DType, Device,
13
+ ValueT, Value, ArrayLike, ArrayOrAny
14
+ )
15
+
16
+
17
+ class CompatNamespace(Compat):
18
+ def __new__(cls, xp: object, /): ...
19
+
20
+ # === Creation functions ===
21
+ @overload
22
+ def asarray(self, obj: NDArray[dtypeT], /, *, dtype: None = ..., device: Optional[Device] = ..., copy: Optional[bool] = ...) -> CompatArray[dtypeT, Literal["cpu"]]: ...
23
+ @overload
24
+ def asarray(self, obj: ArrayLike[dtypeT], /, *, dtype: None = ..., device: None = ..., copy: Optional[bool] = ...) -> CompatArray[dtypeT, Any]: ...
25
+ @overload
26
+ def asarray(self, obj: object, /, *, dtype: None = ..., device: None = ..., copy: Optional[bool] = ...) -> CompatArray[Any, Any]: ...
27
+ @overload
28
+ def asarray(self, obj: object, /, *, dtype: None = ..., device: DeviceT, copy: Optional[bool] = ...) -> CompatArray[Any, DeviceT]: ...
29
+ @overload
30
+ def asarray(self, obj: NDArray[Any], /, *, dtype: DTypeT, device: Optional[Device] = ..., copy: Optional[bool] = ...) -> CompatArray[DTypeT, Literal["cpu"]]: ...
31
+ @overload
32
+ def asarray(self, obj: object, /, *, dtype: DTypeT, device: None = ..., copy: Optional[bool] = ...) -> CompatArray[DTypeT, Any]: ...
33
+ @overload
34
+ def asarray(self, obj: object, /, *, dtype: DTypeT, device: DeviceT, copy: Optional[bool] = ...) -> CompatArray[DTypeT, DeviceT]: ...
35
+
36
+ def asarray(
37
+ self,
38
+ obj: object,
39
+ /, *,
40
+ dtype: Optional[DType] = None,
41
+ device: Optional[Device] = None,
42
+ copy: Optional[bool] = None
43
+ ) -> CompatArray[Any, Any]:
44
+ """
45
+ Convert the input to a :class:`CompatArray` array.
46
+
47
+ Parameters
48
+ ----------
49
+ obj : object
50
+ Object to be converted to a :class:`CompatArray` array.
51
+ May be a Python scalar, a (possibly nested) sequence of Python scalars, or an object supporting the Python buffer protocol.
52
+
53
+ dtype : Optional[DType], default to `None`
54
+ Output array data type.
55
+ - `None`: The output array data type must be inferred from the data type(s) in obj.
56
+ If all input values are Python scalars, then, in order of precedence:
57
+ 1. If all values are of type `bool`, the output data type must be `bool`;
58
+ 2. If all values are of type `int` or are a mixture of `bool` and `int`, the output data type must be the default `integer` data type;
59
+ 3. If one or more values are `complex` numbers, the output data type must be the default `complex` floating-point data type;
60
+ 4. If one or more values are `floats`, the output data type must be the default real-valued floating-point data type.
61
+
62
+ device : Optional[Device], default to `None`
63
+ Device on which to place the created array.
64
+ - `None`: If :param:`obj` is an array, the output array device must be inferred from :param:`obj`.
65
+
66
+ copy : Optional[bool], default to `None`
67
+ Boolean indicating whether or not to copy the input.
68
+ - `True`: The function must always copy (see Copy keyword argument behavior);
69
+ - `False`: The function must never copy for input which supports the buffer protocol and must raise a ValueError in case a copy would be necessary;
70
+ - `None`: The function must reuse existing memory buffer if possible and copy otherwise.
71
+
72
+ Returns
73
+ -------
74
+ CompatArray
75
+ A :class:`CompatArray` array containing the data from :param:`obj`.
76
+ """
77
+ ...
78
+
79
+ @overload
80
+ def arange(self, start: int, /, stop: Optional[int] = ..., step: int = ..., *, dtype: None = ..., device: None = ...) -> CompatArray[int, Literal["cpu"]]: ...
81
+ @overload
82
+ def arange(self, start: Union[int, float], /, stop: Optional[Union[int, float]] = ..., step: Union[int, float] = ..., *, dtype: None = ..., device: None = ...) -> CompatArray[float, Literal["cpu"]]: ...
83
+ @overload
84
+ def arange(self, start: int, /, stop: Optional[int] = ..., step: int = ..., *, dtype: None = ..., device: DeviceT) -> CompatArray[int, DeviceT]: ...
85
+ @overload
86
+ def arange(self, start: Union[int, float], /, stop: Optional[Union[int, float]] = ..., step: Union[int, float] = ..., *, dtype: None = ..., device: DeviceT) -> CompatArray[float, DeviceT]: ...
87
+ @overload
88
+ def arange(self, start: Union[int, float], /, stop: Optional[Union[int, float]] = ..., step: Union[int, float] = ..., *, dtype: DTypeT, device: None = ...) -> CompatArray[DTypeT, Literal["cpu"]]: ...
89
+ @overload
90
+ def arange(self, start: Union[int, float], /, stop: Optional[Union[int, float]] = ..., step: Union[int, float] = ..., *, dtype: DTypeT, device: Device) -> CompatArray[DTypeT, Device]: ...
91
+
92
+ def arange(
93
+ self,
94
+ start: Union[int, float],
95
+ /,
96
+ stop: Optional[Union[int, float]] = None,
97
+ step: Union[int, float] = 1,
98
+ *,
99
+ dtype: Optional[DType] = None,
100
+ device: Optional[Device] = None
101
+ ) -> CompatArray[Any, Any]:
102
+ """
103
+ Returns evenly spaced values within the half-open interval `[start, stop)` as a one-dimensional :class:`CompatArray` array.
104
+
105
+ Parameters
106
+ ----------
107
+ start : Union[int, float]
108
+ - :param:`stop` is specified: the start of interval (inclusive);
109
+ - :param:`stop` is not specified: the end of the interval (exclusive), and the default is `0`.
110
+
111
+ stop : Optional[Union[int, float]], default to `None`
112
+ The end of the interval.
113
+
114
+ step : Union[int, float], default to `1`
115
+ The distance between two adjacent elements (`out[i+1] - out[i]`).
116
+ Must not be `0`; may be `negative`, this results in an empty array if :param:`stop` >= :param:`start`.
117
+
118
+ dtype : Optional[DType], default to `None`
119
+ Output array data type.
120
+ - `None`: The output array data type must be inferred from :param:`start`, :param:`stop` and :param:`step`. For :param:`start`, :param:`stop` and :param:`step`:
121
+
122
+ - all integers: the output data type must be the default `integer` data type;
123
+ - one or more floats: the output data type must be the default real-valued floating-point data type.
124
+
125
+ device : Optional[Device], default to `None`
126
+ Device on which to place the created array.
127
+
128
+ Returns
129
+ -------
130
+ CompatArray
131
+ A one-dimensional :class:`CompatArray` array containing evenly spaced values.
132
+ The length of the output array must be `ceil((stop-start)/step)` if `stop - start` and :param:`step` have the same sign, and length `0` otherwise.
133
+ """
134
+ ...
135
+
136
+ @overload
137
+ def empty(self, shape: Union[int, Tuple[int, ...]], *, dtype: None = ..., device: None = ...) -> CompatArray[float, Literal["cpu"]]: ...
138
+ @overload
139
+ def empty(self, shape: Union[int, Tuple[int, ...]], *, dtype: None = ..., device: DeviceT) -> CompatArray[float, DeviceT]: ...
140
+ @overload
141
+ def empty(self, shape: Union[int, Tuple[int, ...]], *, dtype: DTypeT, device: None = ...) -> CompatArray[DTypeT, Literal["cpu"]]: ...
142
+ @overload
143
+ def empty(self, shape: Union[int, Tuple[int, ...]], *, dtype: DTypeT, device: DeviceT) -> CompatArray[DTypeT, DeviceT]: ...
144
+
145
+ def empty(
146
+ self,
147
+ shape: Union[int, Tuple[int, ...]],
148
+ *,
149
+ dtype: Optional[DType] = None,
150
+ device: Optional[Device] = None
151
+ ) -> CompatArray[Any, Any]:
152
+ """
153
+ Returns an uninitialized :class:`CompatArray` array having a specified shape.
154
+
155
+ Parameters
156
+ ----------
157
+ shape : Union[int, Tuple[int, ...]]
158
+ Output array shape.
159
+
160
+ dtype : Optional[DType], default to `None`
161
+ Output array data type.
162
+ - `None`: The output array data type must be the default real-valued floating-point data type.
163
+
164
+ device : Optional[Device], default to `None`
165
+ Device on which to place the created array.
166
+
167
+ Returns
168
+ -------
169
+ CompatArray
170
+ a :class:`CompatArray` array containing uninitialized data.
171
+ """
172
+ ...
173
+
174
+ @overload
175
+ def empty_like(self, x: NDArray[dtypeT], /, *, dtype: None = ..., device: Optional[Device] = ...) -> CompatArray[dtypeT, Literal["cpu"]]: ...
176
+ @overload
177
+ def empty_like(self, x: ArrayLike[dtypeT], /, *, dtype: None = ..., device: None = ...) -> CompatArray[dtypeT, Any]: ...
178
+ @overload
179
+ def empty_like(self, x: ArrayLike[dtypeT], /, *, dtype: None = ..., device: DeviceT) -> CompatArray[dtypeT, DeviceT]: ...
180
+ @overload
181
+ def empty_like(self, x: ArrayLike[Any], /, *, dtype: DTypeT, device: None = ...) -> CompatArray[DTypeT, Any]: ...
182
+ @overload
183
+ def empty_like(self, x: ArrayLike[Any], /, *, dtype: DTypeT, device: DeviceT) -> CompatArray[DTypeT, DeviceT]: ...
184
+
185
+ def empty_like(
186
+ self,
187
+ x: ArrayLike[Any],
188
+ /, *,
189
+ dtype: Optional[DType] = None,
190
+ device: Optional[Device] = None
191
+ ) -> CompatArray[Any, Any]:
192
+ """
193
+ Returns an uninitialized :class:`CompatArray` array with the same shape as an input array :param:`x`.
194
+
195
+ Parameters
196
+ ----------
197
+ x : ArrayLike
198
+ Input array from which to derive the output array shape.
199
+
200
+ dtype : Optional[DType], default to `None`
201
+ Output array data type.
202
+ - `None`: The output array data type must be inferred from :param:`x`.
203
+
204
+ device : Optional[Device], default to `None`
205
+ Device on which to place the created array.
206
+ - `None`: The output array device must be inferred from :param:`x`.
207
+
208
+ Returns
209
+ -------
210
+ CompatArray
211
+ a :class:`CompatArray` array having the same shape as :param:`x` and containing uninitialized data.
212
+ """
213
+ ...
214
+
215
+ @overload
216
+ def eye(self, n_rows: int, n_cols: Optional[int] = ..., /, *, k: int = ..., dtype: None = ..., device: None = ...) -> CompatArray[float, Literal["cpu"]]: ...
217
+ @overload
218
+ def eye(self, n_rows: int, n_cols: Optional[int] = ..., /, *, k: int = ..., dtype: None = ..., device: DeviceT) -> CompatArray[float, DeviceT]: ...
219
+ @overload
220
+ def eye(self, n_rows: int, n_cols: Optional[int] = ..., /, *, k: int = ..., dtype: DTypeT, device: None = ...) -> CompatArray[DTypeT, Literal["cpu"]]: ...
221
+ @overload
222
+ def eye(self, n_rows: int, n_cols: Optional[int] = ..., /, *, k: int = ..., dtype: DTypeT, device: DeviceT) -> CompatArray[DTypeT, DeviceT]: ...
223
+
224
+ def eye(
225
+ self,
226
+ n_rows: int,
227
+ n_cols: Optional[int] = None,
228
+ /, *,
229
+ k: int = 0,
230
+ dtype: Optional[DType] = None,
231
+ device: Optional[Device] = None
232
+ ) -> CompatArray[Any, Any]:
233
+ """
234
+ Returns a two-dimensional :class:`CompatArray` array with ones on the :param:`k`th diagonal and zeros elsewhere.
235
+
236
+ Parameters
237
+ ----------
238
+ n_rows : int
239
+ Number of rows in the output array.
240
+
241
+ n_cols : Optional[int], default to `None`
242
+ Number of columns in the output array.
243
+ - `None`: The default number of columns in the output array is equal to :param:`n_rows`.
244
+
245
+ k : int, default to `0`
246
+ Index of the diagonal.
247
+ - _positive_: Upper diagonal;
248
+ - _negative_: Lower diagonal;
249
+ - `0`: Main diagonal.
250
+
251
+ dtype : Optional[DType], default to `None`
252
+ Output array data type.
253
+ - `None`: The output array data type must be the default real-valued floating-point data type.
254
+
255
+ device : Optional[Device], default to `None`
256
+ Device on which to place the created array.
257
+
258
+ Returns
259
+ -------
260
+ CompatArray
261
+ A :class:`CompatArray` array where all elements are equal to zero, except for the kth diagonal, whose values are equal to one.
262
+ """
263
+ ...
264
+
265
+ @overload
266
+ def from_dlpack(self, x: NDArray[dtypeT], /, *, device: None = ..., copy: Optional[bool] = ...) -> CompatArray[dtypeT, Literal["cpu"]]: ...
267
+ @overload
268
+ def from_dlpack(self, x: ArrayLike[dtypeT], /, *, device: None = ..., copy: Optional[bool] = ...) -> CompatArray[dtypeT, Any]: ...
269
+ @overload
270
+ def from_dlpack(self, x: object, /, *, device: None = ..., copy: Optional[bool] = ...) -> CompatArray[Any, Any]: ...
271
+ @overload
272
+ def from_dlpack(self, x: ArrayLike[dtypeT], /, *, device: DeviceT, copy: Optional[bool] = ...) -> CompatArray[dtypeT, DeviceT]: ...
273
+ @overload
274
+ def from_dlpack(self, x: object, /, *, device: DeviceT, copy: Optional[bool] = ...) -> CompatArray[Any, DeviceT]: ...
275
+
276
+ def from_dlpack(
277
+ self,
278
+ x: object,
279
+ /, *,
280
+ device: Optional[Device] = None,
281
+ copy: Optional[bool] = None
282
+ ) -> CompatArray[Any, Any]:
283
+ """
284
+ Returns a new :class:`CompatArray` array containing the data from another (array) object with a `__dlpack__` method.
285
+
286
+ Parameters
287
+ ----------
288
+ x : object
289
+ Input (array) object.
290
+
291
+ device : Optional[Device], default to `None`
292
+ Device on which to place the created array.
293
+ - `None`: If :param:`x` supports `DLPack`, the output array must be on the same device as :param:`x`.
294
+
295
+ copy : Optional[bool], default to `None`
296
+ Boolean indicating whether or not to copy the input.
297
+ - `True`: The function must always copy;
298
+ - `False`: The function must never copy, and raise `BufferError` in case a copy is deemed necessary (e.g. if a cross-device data movement is requested, and it is not possible without a copy);
299
+ - `None`: The function must reuse existing memory buffer if possible and copy otherwise.
300
+
301
+ Returns
302
+ -------
303
+ CompatArray
304
+ A :class:`CompatArray` array containing the data in :param:`x`.
305
+ """
306
+ ...
307
+
308
+ @overload
309
+ def full(self, shape: Union[int, Tuple[int, ...]], fill_value: ValueT, *, dtype: None = ..., device: None = ...) -> CompatArray[ValueT, Literal["cpu"]]: ...
310
+ @overload
311
+ def full(self, shape: Union[int, Tuple[int, ...]], fill_value: ValueT, *, dtype: None = ..., device: DeviceT) -> CompatArray[ValueT, DeviceT]: ...
312
+ @overload
313
+ def full(self, shape: Union[int, Tuple[int, ...]], fill_value: Value, *, dtype: DTypeT, device: None = ...) -> CompatArray[DTypeT, Literal["cpu"]]: ...
314
+ @overload
315
+ def full(self, shape: Union[int, Tuple[int, ...]], fill_value: Value, *, dtype: DTypeT, device: DeviceT) -> CompatArray[DTypeT, DeviceT]: ...
316
+
317
+ def full(
318
+ self,
319
+ shape: Union[int, Tuple[int, ...]],
320
+ fill_value: Value,
321
+ *,
322
+ dtype: Optional[DType] = None,
323
+ device: Optional[Device] = None
324
+ ) -> CompatArray[Any, Any]:
325
+ """
326
+ Returns a new :class:`CompatArray` array having a specified :param:`shape` and filled with :param:`fill_value`.
327
+
328
+ Parameters
329
+ ----------
330
+ shape : Union[int, Tuple[int, ...]]
331
+ Output array shape.
332
+
333
+ fill_value : Value
334
+ Fill value.
335
+
336
+ dtype : Optional[DType], default to `None`
337
+ Output array data type.
338
+ - `None`: The output array data type must be inferred from :param:`fill_value` according to the following rules, for :param:`fill_value`:
339
+
340
+ - _int_: The output array data type must be the default `integer` data type;
341
+ - _float_: The output array data type must be the default real-valued floating-point data type;
342
+ - _complex_: The output array data type must be the default `complex` floating-point data type;
343
+ - _bool_: The output array data type must be `bool`.
344
+
345
+ device : Optional[Device], default to `None`
346
+ Device on which to place the created array.
347
+
348
+ Returns
349
+ -------
350
+ CompatArray
351
+ A :class:`CompatArray` array where every element is equal to :param:`fill_value`.
352
+ """
353
+ ...
354
+
355
+ @overload
356
+ def full_like(self, x: NDArray[dtypeT], /, fill_value: Value, *, dtype: None = ..., device: Optional[Device] = ...) -> CompatArray[dtypeT, Literal["cpu"]]: ...
357
+ @overload
358
+ def full_like(self, x: ArrayLike[dtypeT], /, fill_value: Value, *, dtype: None = ..., device: None = ...) -> CompatArray[dtypeT, Any]: ...
359
+ @overload
360
+ def full_like(self, x: ArrayLike[dtypeT], /, fill_value: Value, *, dtype: None = ..., device: DeviceT) -> CompatArray[dtypeT, DeviceT]: ...
361
+ @overload
362
+ def full_like(self, x: ArrayLike[Any], /, fill_value: Value, *, dtype: DTypeT, device: None = ...) -> CompatArray[DTypeT, Any]: ...
363
+ @overload
364
+ def full_like(self, x: ArrayLike[Any], /, fill_value: Value, *, dtype: DTypeT, device: DeviceT) -> CompatArray[DTypeT, DeviceT]: ...
365
+
366
+ def full_like(
367
+ self,
368
+ x: ArrayLike[Any],
369
+ /,
370
+ fill_value: Value,
371
+ *,
372
+ dtype: Optional[DType] = None,
373
+ device: Optional[Device] = None
374
+ ) -> CompatArray[Any, Any]:
375
+ """
376
+ Returns a :class:`CompatArray` array with the same shape as an input array :param:`x` and filled with :param:`fill_value`.
377
+
378
+ Parameters
379
+ ----------
380
+ x : ArrayLike
381
+ Input array from which to derive the output array shape.
382
+
383
+ fill_value : Value
384
+ Fill value.
385
+
386
+ dtype : Optional[DType], default to `None`
387
+ Output array data type.
388
+ - `None`: The output array data type must be inferred from :param:`x`.
389
+
390
+ device : Optional[Device], default to `None`
391
+ Device on which to place the created array.
392
+ - `None`: The output array device must be inferred from :param:`x`.
393
+
394
+ Returns
395
+ -------
396
+ CompatArray
397
+ a :class:`CompatArray` array having the same shape as :param:`x` and where every element is equal to :param:`fill_value`.
398
+ """
399
+ ...
400
+
401
+ @overload
402
+ def linspace(self, start: Union[int, float, complex], stop: Union[int, float, complex], /, num: int, *, dtype: None = ..., device: None = ..., endpoint: bool = ...) -> CompatArray[float, Literal["cpu"]]: ...
403
+ @overload
404
+ def linspace(self, start: Union[int, float, complex], stop: Union[int, float, complex], /, num: int, *, dtype: None = ..., device: DeviceT, endpoint: bool = ...) -> CompatArray[float, DeviceT]: ...
405
+ @overload
406
+ def linspace(self, start: Union[int, float, complex], stop: Union[int, float, complex], /, num: int, *, dtype: DTypeT, device: None = ..., endpoint: bool = ...) -> CompatArray[DTypeT, Literal["cpu"]]: ...
407
+ @overload
408
+ def linspace(self, start: Union[int, float, complex], stop: Union[int, float, complex], /, num: int, *, dtype: DTypeT, device: DeviceT, endpoint: bool = ...) -> CompatArray[DTypeT, DeviceT]: ...
409
+
410
+ def linspace(
411
+ self,
412
+ start: Union[int, float, complex],
413
+ stop: Union[int, float, complex],
414
+ /,
415
+ num: int,
416
+ *,
417
+ dtype: Optional[DType] = None,
418
+ device: Optional[Device] = None,
419
+ endpoint: bool = True
420
+ ) -> CompatArray[Any, Any]:
421
+ """
422
+ Returns evenly spaced numbers over a specified interval.
423
+
424
+ Parameters
425
+ ----------
426
+ start : Union[int, float, complex]
427
+ The start of the interval.
428
+
429
+ stop : Union[int, float, complex]
430
+ The end of the interval.
431
+ - :param:`endpoint` is `False`: The function must generate a sequence of `num+1` evenly spaced numbers starting with :param:`start` and ending with :param:`stop` and exclude the :param:`stop` from the returned array such that the returned array consists of evenly spaced numbers over the half-open interval `[start, stop)`;
432
+ - :param:`endpoint` is `True`: The output array must consist of evenly spaced numbers over the closed interval `[start, stop]`.
433
+
434
+ NOTE: The step size changes when endpoint is False.
435
+
436
+ num : int
437
+ Number of samples.
438
+ Must be a nonnegative `integer` value.
439
+
440
+ dtype : Optional[DType], default to `None`
441
+ Output array data type. Should be a floating-point data type.
442
+ - `None`: For :param:`start` and :param:`stop`:
443
+
444
+ - either one or both are `complex` numbers: The output data type must be the default `complex` floating-point data type;
445
+ - both are real-valued: The output data type must be the default real-valued floating-point data type.
446
+
447
+ device : Optional[Device], default to `None`
448
+ The device on which to place the output array.
449
+
450
+ endpoint : bool, default to `True`
451
+ Boolean indicating whether to include :param:`stop` in the interval.
452
+
453
+ Returns
454
+ -------
455
+ CompatArray
456
+ A one-dimensional :class:`CompatArray` array containing evenly spaced values.
457
+ """
458
+ ...
459
+
460
+ def meshgrid(self, *arrays: ArrayLike[Any], indexing: Literal["xy", "ij"] = "xy") -> List[CompatArray[Any, Any]]: ...
461
+
462
+ @overload
463
+ def ones(self, shape: Union[int, Tuple[int, ...]], *, dtype: None = ..., device: None = ...) -> CompatArray[float, Literal["cpu"]]: ...
464
+ @overload
465
+ def ones(self, shape: Union[int, Tuple[int, ...]], *, dtype: None = ..., device: DeviceT) -> CompatArray[float, DeviceT]: ...
466
+ @overload
467
+ def ones(self, shape: Union[int, Tuple[int, ...]], *, dtype: DTypeT, device: None = ...) -> CompatArray[DTypeT, Literal["cpu"]]: ...
468
+ @overload
469
+ def ones(self, shape: Union[int, Tuple[int, ...]], *, dtype: DTypeT, device: DeviceT) -> CompatArray[DTypeT, DeviceT]: ...
470
+
471
+ def ones(
472
+ self,
473
+ shape: Union[int, Tuple[int, ...]],
474
+ *,
475
+ dtype: Optional[DType] = None,
476
+ device: Optional[Device] = None
477
+ ) -> CompatArray[Any, Any]:
478
+ """
479
+ Returns a :class:`CompatArray` array having a specified shape and filled with ones.
480
+
481
+ Parameters
482
+ ----------
483
+ shape : Union[int, Tuple[int, ...]]
484
+ Output array shape.
485
+
486
+ dtype : Optional[DType], default to `None`
487
+ Output array data type.
488
+ - `None`: The output array data type must be the default real-valued floating-point data type.
489
+
490
+ device : Optional[Device], default to `None`
491
+ Device on which to place the created array.
492
+
493
+ Returns
494
+ -------
495
+ CompatArray
496
+ a :class:`CompatArray` array containing ones.
497
+ """
498
+ ...
499
+
500
+ @overload
501
+ def ones_like(self, x: NDArray[dtypeT], /, *, dtype: None = ..., device: Optional[Device] = ...) -> CompatArray[dtypeT, Literal["cpu"]]: ...
502
+ @overload
503
+ def ones_like(self, x: ArrayLike[dtypeT], /, *, dtype: None = ..., device: None = ...) -> CompatArray[dtypeT, Any]: ...
504
+ @overload
505
+ def ones_like(self, x: ArrayLike[dtypeT], /, *, dtype: None = ..., device: DeviceT) -> CompatArray[dtypeT, DeviceT]: ...
506
+ @overload
507
+ def ones_like(self, x: ArrayLike[Any], /, *, dtype: DTypeT, device: None = ...) -> CompatArray[DTypeT, Any]: ...
508
+ @overload
509
+ def ones_like(self, x: ArrayLike[Any], /, *, dtype: DTypeT, device: DeviceT) -> CompatArray[DTypeT, DeviceT]: ...
510
+
511
+ def ones_like(
512
+ self,
513
+ x: ArrayLike[Any],
514
+ /, *,
515
+ dtype: Optional[DType] = None,
516
+ device: Optional[Device] = None
517
+ ) -> CompatArray[Any, Any]:
518
+ """
519
+ Returns a :class:`CompatArray` array filled with ones with the same shape as an input array :param:`x`.
520
+
521
+ Parameters
522
+ ----------
523
+ x : ArrayLike
524
+ Input array from which to derive the output array shape.
525
+
526
+ dtype : Optional[DType], default to `None`
527
+ Output array data type.
528
+ - `None`: The output array data type must be inferred from :param:`x`.
529
+
530
+ device : Optional[Device], default to `None`
531
+ Device on which to place the created array.
532
+ - `None`: The output array device must be inferred from :param:`x`.
533
+
534
+ Returns
535
+ -------
536
+ CompatArray
537
+ a :class:`CompatArray` array having the same shape as :param:`x` and containing ones.
538
+ """
539
+ ...
540
+
541
+ @overload
542
+ def tril(self, x: NDArray[dtypeT], /, *, k: int = 0) -> CompatArray[dtypeT, Literal["cpu"]]: ...
543
+ @overload
544
+ def tril(self, x: ArrayLike[dtypeT], /, *, k: int = 0) -> CompatArray[dtypeT, Any]: ...
545
+
546
+ def tril(self, x: ArrayLike[Any], /, *, k: int = 0) -> CompatArray[Any, Any]:
547
+ """
548
+ Returns the lower triangular part of a matrix (or a stack of matrices) :param:`x`.
549
+
550
+ Parameters
551
+ ----------
552
+ x : ArrayLike
553
+ Input array. Must have a shape of `(..., M, N)`, and whose innermost two dimensions form `MxN` matrices.
554
+
555
+ k : int, default to `0`
556
+ Diagonal above which to zero elements.
557
+ - `k = 0`: Main diagonal;
558
+ - `k < 0`: The diagonal is below the main diagonal;
559
+ - `k > 0`: The diagonal is above the main diagonal.
560
+
561
+ Returns
562
+ -------
563
+ CompatArray
564
+ a :class:`CompatArray` array containing the lower triangular part(s).
565
+ The returned array must have the same shape and data type as :param:`x`.
566
+ All elements above the specified diagonal :param:`k` must be zeroed.
567
+ The returned array should be allocated on the same device as :param:`x`.
568
+ """
569
+ ...
570
+
571
+ @overload
572
+ def triu(self, x: NDArray[dtypeT], /, *, k: int = 0) -> CompatArray[dtypeT, Literal["cpu"]]: ...
573
+ @overload
574
+ def triu(self, x: ArrayLike[dtypeT], /, *, k: int = 0) -> CompatArray[dtypeT, Any]: ...
575
+
576
+ def triu(
577
+ self,
578
+ x: ArrayLike[Any],
579
+ /, *,
580
+ k: int = 0
581
+ ) -> CompatArray[Any, Any]:
582
+ """
583
+ Returns the upper triangular part of a matrix (or a stack of matrices) :param:`x`.
584
+
585
+ Parameters
586
+ ----------
587
+ x : ArrayLike
588
+ Input array. Must have a shape of `(..., M, N)`, and whose innermost two dimensions form `MxN` matrices.
589
+
590
+ k : int, default to `0`
591
+ Diagonal above which to zero elements.
592
+ - `k = 0`: Main diagonal;
593
+ - `k < 0`: The diagonal is below the main diagonal;
594
+ - `k > 0`: The diagonal is above the main diagonal.
595
+
596
+ Returns
597
+ -------
598
+ CompatArray
599
+ a :class:`CompatArray` array containing the upper triangular part(s).
600
+ The returned array must have the same shape and data type as :param:`x`.
601
+ All elements above the specified diagonal :param:`k` must be zeroed.
602
+ The returned array should be allocated on the same device as :param:`x`.
603
+ """
604
+ ...
605
+
606
+ @overload
607
+ def zeros(self, shape: Union[int, Tuple[int, ...]], *, dtype: None = ..., device: None = ...) -> CompatArray[float, Literal["cpu"]]: ...
608
+ @overload
609
+ def zeros(self, shape: Union[int, Tuple[int, ...]], *, dtype: None = ..., device: DeviceT) -> CompatArray[float, DeviceT]: ...
610
+ @overload
611
+ def zeros(self, shape: Union[int, Tuple[int, ...]], *, dtype: DTypeT, device: None = ...) -> CompatArray[DTypeT, Literal["cpu"]]: ...
612
+ @overload
613
+ def zeros(self, shape: Union[int, Tuple[int, ...]], *, dtype: DTypeT, device: DeviceT) -> CompatArray[DTypeT, DeviceT]: ...
614
+
615
+ def zeros(
616
+ self,
617
+ shape: Union[int, Tuple[int, ...]],
618
+ *,
619
+ dtype: Optional[DType] = None,
620
+ device: Optional[Device] = None
621
+ ) -> CompatArray[Any, Any]:
622
+ """
623
+ Returns a :class:`CompatArray` array having a specified shape and filled with zeros.
624
+
625
+ Parameters
626
+ ----------
627
+ shape : Union[int, Tuple[int, ...]]
628
+ Output array shape.
629
+
630
+ dtype : Optional[DType], default to `None`
631
+ Output array data type.
632
+ - `None`: The output array data type must be the default real-valued floating-point data type.
633
+
634
+ device : Optional[Device], default to `None`
635
+ Device on which to place the created array.
636
+
637
+ Returns
638
+ -------
639
+ CompatArray
640
+ a :class:`CompatArray` array containing zeros.
641
+ """
642
+ ...
643
+
644
+ @overload
645
+ def zeros_like(self, x: NDArray[dtypeT], /, *, dtype: None = ..., device: Optional[Device] = ...) -> CompatArray[dtypeT, Literal["cpu"]]: ...
646
+ @overload
647
+ def zeros_like(self, x: ArrayLike[dtypeT], /, *, dtype: None = ..., device: None = ...) -> CompatArray[dtypeT, Any]: ...
648
+ @overload
649
+ def zeros_like(self, x: ArrayLike[dtypeT], /, *, dtype: None = ..., device: DeviceT) -> CompatArray[dtypeT, DeviceT]: ...
650
+ @overload
651
+ def zeros_like(self, x: ArrayLike[Any], /, *, dtype: DTypeT, device: None = ...) -> CompatArray[DTypeT, Any]: ...
652
+ @overload
653
+ def zeros_like(self, x: ArrayLike[Any], /, *, dtype: DTypeT, device: DeviceT) -> CompatArray[DTypeT, DeviceT]: ...
654
+
655
+ def zeros_like(
656
+ self,
657
+ x: ArrayLike[Any],
658
+ /, *,
659
+ dtype: Optional[DType] = None,
660
+ device: Optional[Device] = None
661
+ ) -> CompatArray[Any, Any]:
662
+ """
663
+ Returns a :class:`CompatArray` array filled with zeros with the same shape as an input array :param:`x`.
664
+
665
+ Parameters
666
+ ----------
667
+ x : ArrayLike
668
+ Input array from which to derive the output array shape.
669
+
670
+ dtype : Optional[DType], default to `None`
671
+ Output array data type.
672
+ - `None`: The output array data type must be inferred from :param:`x`.
673
+
674
+ device : Optional[Device], default to `None`
675
+ Device on which to place the created array.
676
+ - `None`: The output array device must be inferred from :param:`x`.
677
+
678
+ Returns
679
+ -------
680
+ CompatArray
681
+ a :class:`CompatArray` array having the same shape as :param:`x` and containing zeros.
682
+ """
683
+ ...
684
+
685
+ # === Data Type functions ===
686
+ def can_cast(self, from_: Union[DType, ArrayLike[Any]], to: DType, /) -> bool: ...
687
+
688
+ def finfo(self, type_: Union[DType, ArrayLike[Any]], /) -> Any: ...
689
+
690
+ def iinfo(self, type_: Union[DType, ArrayLike[Any]], /) -> Any: ...
691
+
692
+ def isdtype(
693
+ self,
694
+ dtype: DType,
695
+ kind: Union[str, DType, Tuple[Union[str, DType], ...]]
696
+ ) -> bool: ...
697
+
698
+ def result_type(self, *arrays_and_dtypes: Union[ArrayOrAny, DType]) -> DType: ...
699
+
700
+ # === Manipulation functions ===
701
+ def broadcast_arrays(self, *arrays: ArrayLike[Any]) -> List[CompatArray[Any, Any]]: ...
702
+
703
+ @overload
704
+ def broadcast_to(self, x: NDArray[dtypeT], shape: Tuple[int, ...]) -> CompatArray[dtypeT, Literal["cpu"]]: ...
705
+ @overload
706
+ def broadcast_to(self, x: ArrayLike[dtypeT], shape: Tuple[int, ...]) -> CompatArray[dtypeT, Any]: ...
707
+
708
+ def broadcast_to(self, x: ArrayLike[Any], shape: Tuple[int, ...]) -> CompatArray[Any, Any]:
709
+ """
710
+ Broadcasts an array to a specified shape.
711
+
712
+ Parameters
713
+ ----------
714
+ x : ArrayLike
715
+ Array to broadcast.
716
+ Must be capable of being broadcast to the specified shape (see Broadcasting).
717
+ If the array is incompatible with the specified shape, the function must raise an exception.
718
+
719
+ shape : Tuple[int, ...]
720
+ The shape to broadcast to.
721
+
722
+ Returns
723
+ -------
724
+ CompatArray
725
+ A :class:`CompatArray` array having the specified shape.
726
+ Must have the same data type as :param:`x`.
727
+ """
728
+ ...
729
+
730
+ def concat(
731
+ self,
732
+ arrays: Union[Tuple[ArrayLike[Any], ...], List[ArrayLike[Any]]],
733
+ /, *,
734
+ axis: Optional[int] = 0
735
+ ) -> CompatArray[Any, Any]:
736
+ """
737
+ Joins a sequence of arrays along an existing axis.
738
+
739
+ Parameters
740
+ ----------
741
+ arrays : Union[Tuple[ArrayLike[Any], ...], List[ArrayLike[Any]]]
742
+ Input arrays to join.
743
+ The arrays must have the same shape, except in the dimension specified by axis.
744
+
745
+ axis : int, default to `0`
746
+ Axis along which the arrays will be joined.
747
+ - `None`: Arrays must be flattened before concatenation;
748
+ - _negative_: The function must determine the axis along which to join by counting from the last dimension.
749
+
750
+ Returns
751
+ -------
752
+ CompatArray
753
+ A :class:`CompatArray` output array containing the concatenated values.
754
+ """
755
+ ...
756
+
757
+ def stack(
758
+ self,
759
+ arrays: Union[Tuple[ArrayLike[Any], ...], List[ArrayLike[Any]]],
760
+ /, *,
761
+ axis: int = 0
762
+ ) -> CompatArray[Any, Any]:
763
+ """
764
+ Joins a sequence of arrays along a new axis.
765
+
766
+ Parameters
767
+ ----------
768
+ arrays : Union[Tuple[ArrayLike[Any], ...], List[ArrayLike[Any]]]
769
+ Input arrays to join.
770
+ Each array must have the same shape.
771
+
772
+ axis : int, default to `0`
773
+ Axis along which the arrays will be joined.
774
+ Providing an :param:`axis` specifies the index of the new axis in the dimensions of the result.
775
+ For example,
776
+ - `0`: The new axis will be the first dimension and the output array will have shape `(N, A, B, C)`;
777
+ - `1`: The new new axis will be the second dimension and the output array will have shape `(A, N, B, C)`;
778
+ - `-1`: new axis will be the last dimension and the output array will have shape `(A, B, C, N)`.
779
+
780
+ A valid axis must be on the interval `[-N, N)`, where `N` is the rank (number of dimensions) of `x`.
781
+ If provided an axis outside of the required interval, the function must raise an exception.
782
+
783
+ Returns
784
+ -------
785
+ CompatArray
786
+ An output array having rank `N+1`, where `N` is the rank (number of dimensions) of `x`.
787
+ If the input arrays have different data types, normal Type Promotion Rules must apply.
788
+ If the input arrays have the same data type, the output array must have the same data type as the input arrays.
789
+ """
790
+ ...
791
+
792
+ # === Constants ===
793
+ @property
794
+ def e(self) -> float: ...
795
+ @property
796
+ def pi(self) -> float: ...
797
+ @property
798
+ def inf(self) -> float: ...
799
+ @property
800
+ def nan(self) -> float: ...
801
+ @property
802
+ def newaxis(self) -> None: ...
803
+
804
+ # === Data type ===
805
+ @property
806
+ def int8(self) -> DType: ...
807
+ @property
808
+ def int16(self) -> DType: ...
809
+ @property
810
+ def int32(self) -> DType: ...
811
+ @property
812
+ def int64(self) -> DType: ...
813
+ @property
814
+ def uint8(self) -> DType: ...
815
+ @property
816
+ def uint16(self) -> DType: ...
817
+ @property
818
+ def uint32(self) -> DType: ...
819
+ @property
820
+ def uint64(self) -> DType: ...
821
+ @property
822
+ def float32(self) -> DType: ...
823
+ @property
824
+ def float64(self) -> DType: ...
825
+ @property
826
+ def complex64(self) -> DType: ...
827
+ @property
828
+ def complex128(self) -> DType: ...
829
+ @property
830
+ def bool(self) -> DType: ...
831
+
832
+ @property
833
+ def __name__(self) -> str: ...