cobra-array 0.1.0__tar.gz → 0.1.1__tar.gz

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.
Files changed (31) hide show
  1. {cobra_array-0.1.0/src/cobra_array.egg-info → cobra_array-0.1.1}/PKG-INFO +1 -1
  2. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/__init__.py +1 -1
  3. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/_core.py +8 -12
  4. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/compat/_array.py +1 -1
  5. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/compat/_array.pyi +24 -17
  6. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/compat/_namespace.pyi +122 -70
  7. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/convert.pyi +13 -13
  8. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/default.py +10 -10
  9. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/types.py +17 -15
  10. {cobra_array-0.1.0 → cobra_array-0.1.1/src/cobra_array.egg-info}/PKG-INFO +1 -1
  11. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array.egg-info/SOURCES.txt +2 -0
  12. cobra_array-0.1.1/tests/test_compat.py +253 -0
  13. cobra_array-0.1.1/tests/test_compat_namespace.py +122 -0
  14. {cobra_array-0.1.0 → cobra_array-0.1.1}/LICENSE +0 -0
  15. {cobra_array-0.1.0 → cobra_array-0.1.1}/README.md +0 -0
  16. {cobra_array-0.1.0 → cobra_array-0.1.1}/pyproject.toml +0 -0
  17. {cobra_array-0.1.0 → cobra_array-0.1.1}/setup.cfg +0 -0
  18. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/_utils.py +0 -0
  19. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/array_api.py +0 -0
  20. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/compat/__init__.py +0 -0
  21. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/compat/_base.py +0 -0
  22. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/compat/_namespace.py +0 -0
  23. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/convert.py +0 -0
  24. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array/exceptions.py +0 -0
  25. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array.egg-info/dependency_links.txt +0 -0
  26. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array.egg-info/requires.txt +0 -0
  27. {cobra_array-0.1.0 → cobra_array-0.1.1}/src/cobra_array.egg-info/top_level.txt +0 -0
  28. {cobra_array-0.1.0 → cobra_array-0.1.1}/tests/test_backend.py +0 -0
  29. {cobra_array-0.1.0 → cobra_array-0.1.1}/tests/test_convert.py +0 -0
  30. {cobra_array-0.1.0 → cobra_array-0.1.1}/tests/test_default.py +0 -0
  31. {cobra_array-0.1.0 → cobra_array-0.1.1}/tests/test_wrap.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cobra-array
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: A backend-agnostic array utility library that unifies array conversion, context control, and cross-library operations across `NumPy`/`PyTorch`-style ecosystems.
5
5
  Author-email: Zhen Tian <zhen.tian.cs@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/tinchen777/cobra-array.git
@@ -91,7 +91,7 @@ from ._utils import (
91
91
  )
92
92
 
93
93
  __author__ = "Zhen Tian"
94
- __version__ = "0.1.0"
94
+ __version__ = "0.1.1"
95
95
 
96
96
  __all__ = [
97
97
  "array_spec",
@@ -22,7 +22,7 @@ from .exceptions import (
22
22
  if TYPE_CHECKING:
23
23
  from numpy.typing import NDArray
24
24
  from .compat import CompatArray
25
- from .types import (T, dtypeT, DType, Device, ArrayLike, ArrayLibraryName)
25
+ from .types import (T, dtypeT, DType, AnyDevice, ArrayLike, ArrayLibraryName)
26
26
 
27
27
 
28
28
  def array_spec(
@@ -85,10 +85,6 @@ def array_spec(
85
85
  If `ref` is not `None`, a string, or an integer.
86
86
  NotArrayAPIObjectError
87
87
  If the reference array determined by `ref` is not an array API compatible array object.
88
-
89
- Examples
90
- --------
91
-
92
88
  """
93
89
  kw_arrays = kw_arrays or {}
94
90
 
@@ -197,11 +193,11 @@ def context_spec() -> ArraySpec:
197
193
  @overload
198
194
  def as_context(obj: NDArray[dtypeT], /, *, unify_dtype: Literal[False], unify_device: bool = ..., copy: bool = ..., arraylike_only: bool = ...) -> CompatArray[dtypeT, Literal["cpu"]]: ...
199
195
  @overload
200
- def as_context(obj: ArrayLike[dtypeT], /, *, unify_dtype: Literal[False], unify_device: bool = ..., copy: bool = ..., arraylike_only: bool = ...) -> CompatArray[dtypeT, Any]: ...
196
+ def as_context(obj: ArrayLike[dtypeT], /, *, unify_dtype: Literal[False], unify_device: bool = ..., copy: bool = ..., arraylike_only: bool = ...) -> CompatArray[dtypeT, AnyDevice]: ...
201
197
  @overload
202
- def as_context(obj: ArrayLike[Any], /, *, unify_dtype: Literal[True] = ..., unify_device: bool = ..., copy: bool = ..., arraylike_only: bool = ...) -> CompatArray[Any, Any]: ...
198
+ def as_context(obj: ArrayLike[Any], /, *, unify_dtype: Literal[True] = ..., unify_device: bool = ..., copy: bool = ..., arraylike_only: bool = ...) -> CompatArray[Any, AnyDevice]: ...
203
199
  @overload
204
- def as_context(obj: object, /, *, unify_dtype: bool = ..., unify_device: bool = ..., copy: bool = ..., arraylike_only: Literal[False] = ...) -> CompatArray[Any, Any]: ...
200
+ def as_context(obj: object, /, *, unify_dtype: bool = ..., unify_device: bool = ..., copy: bool = ..., arraylike_only: Literal[False] = ...) -> CompatArray[Any, AnyDevice]: ...
205
201
  @overload
206
202
  def as_context(obj: T, /, *, unify_dtype: bool = ..., unify_device: bool = ..., copy: bool = ..., arraylike_only: Literal[True]) -> T: ...
207
203
 
@@ -236,7 +232,7 @@ def as_context(
236
232
 
237
233
  Returns
238
234
  -------
239
- CompatArray[Any, Any]
235
+ CompatArray[Any, AnyDevice]
240
236
  The converted array representation of the object in the current context `compatibility namespace`, with the current context `dtype` and `device` if specified.
241
237
  object
242
238
  If :param:`arraylike_only` is `True` and the object is not array-like.
@@ -275,7 +271,7 @@ class array_context:
275
271
  self,
276
272
  xp: Optional[Union[object, ArrayLibraryName]] = None,
277
273
  dtype: Optional[DType] = None,
278
- device: Optional[Device] = None
274
+ device: Optional[AnyDevice] = None
279
275
  ):
280
276
  """
281
277
  Initialize the context manager with the specified `array namespace`, `dtype` and `device`.
@@ -286,11 +282,11 @@ class array_context:
286
282
  The target `array namespace` or array library name for the context.
287
283
  - `None`: Use the `compatibility namespace` from the context;
288
284
 
289
- dtype : Optional[DTypeT], default to `None`
285
+ dtype : Optional[DType], default to `None`
290
286
  The target `dtype` for the context.
291
287
  - `None`: Use the `dtype` from the context.
292
288
 
293
- device : Optional[DeviceT], default to `None`
289
+ device : Optional[AnyDevice], default to `None`
294
290
  The target `device` for the context.
295
291
  - `None`: Use the `device` from the context.
296
292
  """
@@ -103,7 +103,7 @@ class CompatArray(Compat):
103
103
 
104
104
  Parameters
105
105
  ----------
106
- device : Device
106
+ device : AnyDevice
107
107
  A device object or name.
108
108
 
109
109
  stream : Optional[Union[int, Any]], default to `None`
@@ -9,14 +9,14 @@ from typing import (Union, List, Tuple, Optional, Any, Sequence, Generic, TypeVa
9
9
 
10
10
  from ._base import Compat
11
11
  from ..types import (
12
- T, DTypeT, DeviceT, dtypeT, deviceT, DType, Device,
12
+ T, DTypeT, DeviceT, dtypeT, deviceT, DType, AnyDevice,
13
13
  ArrayLike, ArrayLibraryName,
14
14
  ArrayOrAny, ArrayOrScalar, ArrayOrReal, ArrayOrIntLike, ArrayOrInt, ArrayOrbool,
15
15
  UniqueAllResult, UniqueCountsResult, UniqueInverseResult
16
16
  )
17
17
 
18
18
  TT = TypeVar("TT", bound=DType)
19
- DT = TypeVar("DT", bound=Device)
19
+ DT = TypeVar("DT", bound=AnyDevice)
20
20
 
21
21
 
22
22
  class CompatArray(Compat, Generic[TT, DT]):
@@ -31,47 +31,54 @@ class CompatArray(Compat, Generic[TT, DT]):
31
31
  def from_other(cls, obj: object, /, xp: Literal["numpy"]) -> CompatArray[Any, Literal["cpu"]]: ...
32
32
  @overload
33
33
  @classmethod
34
- def from_other(cls, obj: NDArray[dtypeT], /, xp: Union[object, ArrayLibraryName]) -> CompatArray[dtypeT, Any]: ...
34
+ def from_other(cls, obj: NDArray[dtypeT], /, xp: Union[object, ArrayLibraryName]) -> CompatArray[dtypeT, AnyDevice]: ...
35
35
  @overload
36
36
  @classmethod
37
- def from_other(cls, obj: ArrayLike[dtypeT], /, xp: Union[object, ArrayLibraryName]) -> CompatArray[dtypeT, Any]: ...
37
+ def from_other(cls, obj: ArrayLike[dtypeT], /, xp: Union[object, ArrayLibraryName]) -> CompatArray[dtypeT, AnyDevice]: ...
38
38
  @overload
39
39
  @classmethod
40
- def from_other(cls, obj: object, /, xp: Union[object, ArrayLibraryName]) -> CompatArray[Any, Any]: ...
40
+ def from_other(cls, obj: object, /, xp: Union[object, ArrayLibraryName]) -> CompatArray[Any, AnyDevice]: ...
41
41
  @classmethod
42
- def from_other(cls, obj: object, /, xp: Union[object, ArrayLibraryName]) -> CompatArray[Any, Any]: ...
42
+ def from_other(cls, obj: object, /, xp: Union[object, ArrayLibraryName]) -> CompatArray[Any, AnyDevice]: ...
43
43
 
44
44
  @overload
45
45
  def __new__(cls, arr: NDArray[dtypeT], /, **kwargs) -> CompatArray[dtypeT, Literal["cpu"]]: ...
46
46
  @overload
47
- def __new__(cls, arr: Tensor, /, **kwargs) -> CompatArray[Any, Any]: ...
47
+ def __new__(cls, arr: Tensor, /, **kwargs) -> CompatArray[Any, AnyDevice]: ...
48
48
  @overload
49
49
  def __new__(cls, arr: CompatArray[dtypeT, deviceT], /, **kwargs) -> CompatArray[dtypeT, deviceT]: ...
50
50
  @overload
51
- def __new__(cls, arr: ArrayLike[dtypeT], /, **kwargs) -> CompatArray[dtypeT, Any]: ...
52
- def __new__(cls, arr: ArrayLike[Any], /, **kwargs) -> CompatArray[Any, Any]: ...
51
+ def __new__(cls, arr: ArrayLike[dtypeT], /, **kwargs) -> CompatArray[dtypeT, AnyDevice]: ...
52
+ def __new__(cls, arr: ArrayLike[Any], /, **kwargs) -> CompatArray[Any, AnyDevice]: ...
53
53
 
54
54
  # === Conversion functions ===
55
55
  def to_numpy(self, *, copy: bool = False) -> NDArray[TT]: ...
56
- def to_tensor(self, *, device: Optional[DeviceT] = None, copy: bool = False) -> Tensor: ...
56
+ def to_tensor(self, *, device: Optional[AnyDevice] = None, copy: bool = False) -> Tensor: ...
57
57
  def to_list(self, *, copy: bool = False) -> List[TT]: ...
58
58
 
59
59
  # === Device functions ===
60
+ @overload
60
61
  def to_device(self, device: DeviceT, /, *, stream: Optional[Any] = None) -> CompatArray[TT, DeviceT]: ...
62
+ @overload
63
+ def to_device(self, device: AnyDevice, /, *, stream: Optional[Any] = None) -> CompatArray[TT, AnyDevice]: ...
64
+
65
+ def to_device(self, device: AnyDevice, /, *, stream: Optional[Any] = None) -> CompatArray[Any, AnyDevice]: ...
61
66
 
62
67
  # === Data type functions ===
63
68
  @overload
64
- def astype(self, dtype: DTypeT, /, *, copy: bool = ...) -> CompatArray[DTypeT, DT]: ...
69
+ def astype(self, dtype: DTypeT, /, *, copy: bool = ..., device: None = ...) -> CompatArray[DTypeT, DT]: ...
65
70
  @overload
66
71
  def astype(self, dtype: DTypeT, /, *, copy: bool = ..., device: DeviceT) -> CompatArray[DTypeT, DeviceT]: ...
72
+ @overload
73
+ def astype(self, dtype: DTypeT, /, *, copy: bool = ..., device: AnyDevice) -> CompatArray[DTypeT, AnyDevice]: ...
67
74
 
68
75
  def astype(
69
76
  self,
70
77
  dtype: DType,
71
78
  /, *,
72
79
  copy: bool = True,
73
- device: Optional[Device] = None
74
- ) -> CompatArray[Any, Any]:
80
+ device: Optional[AnyDevice] = None
81
+ ) -> CompatArray[Any, AnyDevice]:
75
82
  """
76
83
  Copies `self` to a specified data type irrespective of Type Promotion Rules rules.
77
84
 
@@ -88,8 +95,8 @@ class CompatArray(Compat, Generic[TT, DT]):
88
95
  - `True`: `self` must be returned;
89
96
  - `False`: A newly allocated array must be returned.
90
97
 
91
- device : Optional[DeviceT], default to `None`
92
- DeviceT on which to place the returned array.
98
+ device : Optional[AnyDevice], default to `None`
99
+ Device on which to place the returned array.
93
100
  - `None`: The output array device must be inferred from `self`.
94
101
 
95
102
  Returns
@@ -1793,7 +1800,7 @@ class CompatArray(Compat, Generic[TT, DT]):
1793
1800
 
1794
1801
 
1795
1802
  @overload
1796
- def unwrap(obj: CompatArray[dtypeT, Any]) -> ArrayLike[dtypeT]: ...
1803
+ def unwrap(obj: CompatArray[dtypeT, AnyDevice]) -> ArrayLike[dtypeT]: ...
1797
1804
  @overload
1798
1805
  def unwrap(obj: ArrayLike[dtypeT]) -> ArrayLike[dtypeT]: ...
1799
1806
  @overload
@@ -1808,7 +1815,7 @@ def wrap_arraylike(arr: NDArray[dtypeT], xp: Optional[object] = ...) -> CompatAr
1808
1815
  @overload
1809
1816
  def wrap_arraylike(arr: CompatArray[dtypeT, deviceT], xp: Optional[object] = ...) -> CompatArray[dtypeT, deviceT]: ...
1810
1817
  @overload
1811
- def wrap_arraylike(arr: ArrayLike[dtypeT], xp: Optional[object] = ...) -> CompatArray[dtypeT, Any]: ...
1818
+ def wrap_arraylike(arr: ArrayLike[dtypeT], xp: Optional[object] = ...) -> CompatArray[dtypeT, AnyDevice]: ...
1812
1819
  @overload
1813
1820
  def wrap_arraylike(arr: T, xp: Optional[object] = ...) -> T: ...
1814
1821