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,137 @@
1
+ Metadata-Version: 2.4
2
+ Name: cobra-array
3
+ Version: 0.1.0
4
+ Summary: A backend-agnostic array utility library that unifies array conversion, context control, and cross-library operations across `NumPy`/`PyTorch`-style ecosystems.
5
+ Author-email: Zhen Tian <zhen.tian.cs@gmail.com>
6
+ Project-URL: Homepage, https://github.com/tinchen777/cobra-array.git
7
+ Project-URL: Repository, https://github.com/tinchen777/cobra-array.git
8
+ Project-URL: Issues, https://github.com/tinchen777/cobra-array.git/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: array-api-compat>=1.11.2
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest; extra == "dev"
22
+ Requires-Dist: pytest-cov; extra == "dev"
23
+ Requires-Dist: numpy<2.0,>=1.21; extra == "dev"
24
+ Dynamic: license-file
25
+
26
+ <div align="center">
27
+
28
+ <h2 id="title">
29
+ 🍁 cobra-array 🍁<br>
30
+ <sub>Unified Array Utilities with Python Array API Compatibility</sub>
31
+ </h2>
32
+
33
+ [![PyPI version](https://img.shields.io/pypi/v/cobra-array.svg)](https://pypi.org/project/cobra-array/)
34
+ ![Python](https://img.shields.io/pypi/pyversions/cobra-array?color=brightgreen)
35
+ [![codecov](https://codecov.io/gh/tinchen777/cobra-array/branch/main/graph/badge.svg)](https://codecov.io/gh/tinchen777/cobra-array)
36
+ ![License](https://img.shields.io/github/license/tinchen777/cobra-array.svg)
37
+
38
+ [![Tests](https://github.com/tinchen777/cobra-array/actions/workflows/test.yml/badge.svg)](https://github.com/tinchen777/cobra-array/actions/workflows/test.yml)
39
+ ![Github stars](https://img.shields.io/github/stars/tinchen777/cobra-array.svg)
40
+
41
+ </div>
42
+
43
+ ## About
44
+
45
+ `cobra-array` is a backend-agnostic array utility library that unifies array conversion, context control, and cross-library operations across `NumPy`/`PyTorch`-style ecosystems.
46
+
47
+ - Python: 3.9+
48
+ - Runtime deps: `array-api-compat` (>= 1.11.2)
49
+
50
+ ## Features
51
+
52
+ - 🚀 **Ackend-agnostic API**: Work with different array backends through one consistent interface.
53
+ - 🚀 **Context-driven unification**: Automatically align namespace, dtype, and device via context managers and decorators.
54
+ - 🚀 **Compatibility wrappers**: `CompatArray` and `CompatNamespace` provide a clean, consistent layer over native backend behavior.
55
+
56
+ ## Installation
57
+
58
+ ### Install from PyPI
59
+
60
+ ```bash
61
+ pip install cobra-array
62
+ ```
63
+
64
+ ## Quick Start
65
+
66
+ - Basic conversions:
67
+
68
+ ```python
69
+ import numpy as np
70
+ from cobra_array.convert import to_numpy, to_tensor, to_list
71
+
72
+ data = [[1, 2], [3, 4]]
73
+
74
+ arr_np = to_numpy(data, dtype=np.float32)
75
+ print(type(arr_np), arr_np.dtype) # numpy.ndarray float32
76
+
77
+ arr_torch = to_tensor(data, device="cpu")
78
+ print(type(arr_torch), arr_torch.device)
79
+
80
+ back_to_list = to_list(arr_np)
81
+ print(back_to_list) # [[1.0, 2.0], [3.0, 4.0]]
82
+ ```
83
+
84
+ - Context-based conversion:
85
+
86
+ ```python
87
+ import numpy as np
88
+ from cobra_array import array_context, as_context, context_spec
89
+
90
+ with array_context(xp="numpy", dtype=np.float32, device="cpu"):
91
+ x = as_context([1, 2, 3])
92
+ y = as_context(np.array([4, 5]))
93
+ spec = context_spec()
94
+ print(spec.cxp.xp_name, spec.dtype, spec.device)
95
+ print(x, y)
96
+ ```
97
+
98
+ - Auto-unify function arguments:
99
+
100
+ ```python
101
+ import numpy as np
102
+ from cobra_array import unify_args
103
+
104
+ @unify_args(ref=0, unify_dtype=True, unify_device=True, arraylike_only=True)
105
+ def add_and_mean(a, b):
106
+ c = a + b
107
+ return c.mean()
108
+
109
+ out = add_and_mean(np.array([1, 2, 3]), [4, 5, 6])
110
+ print(out)
111
+ ```
112
+
113
+ - Default backend strategy:
114
+
115
+ ```python
116
+ from cobra_array.default import as_default, default_spec
117
+
118
+ spec = default_spec()
119
+ print(spec.cxp.xp_name, spec.dtype, spec.device)
120
+
121
+ x = as_default([1, 2, 3], unify_dtype=True, unify_device=True)
122
+ print(x, x.dtype)
123
+ ```
124
+
125
+ ## Requirements
126
+
127
+ - Python >= 3.9
128
+ - `array-api-compat` >= 1.11.2
129
+
130
+ ## License
131
+
132
+ See LICENSE in the repository.
133
+
134
+ ## Links
135
+
136
+ - [Homepage/Repo](https://github.com/tinchen777/cobra-array.git)
137
+ - [Issues](https://github.com/tinchen777/cobra-array.git/issues)
@@ -0,0 +1,20 @@
1
+ cobra_array/__init__.py,sha256=mi_D1NpbofsvWVo7KJc3Pcg6TslXJzEYen2diyKNlqc,3324
2
+ cobra_array/_core.py,sha256=xiVvd4cMHjPUcu-i--knNWwGKZ6iM4OKCUqn8Hj5k1I,16576
3
+ cobra_array/_utils.py,sha256=o0BO_FaMtBEyWpPV3vK1IQtm8Gay5eyLclYnn3PdvmI,2309
4
+ cobra_array/array_api.py,sha256=NqeHpUOyRL1abt7YTdOspx_Uv58U1FrAD2Dg0Qm-3Wg,4072
5
+ cobra_array/convert.py,sha256=d6qAB5r_aWFAY1H-ToiQeGKYnO4dWNrJo4iUviy0GB8,12491
6
+ cobra_array/convert.pyi,sha256=raSmXpnziIJzFnaH-zSbW0H-PKFLt3lEwtUmvAsLSY0,3991
7
+ cobra_array/default.py,sha256=rJUMFE0j6ElPd4XwFrYFgej2dzVQPV8UvdH1TKd1gbk,5370
8
+ cobra_array/exceptions.py,sha256=JPQ809F1qSqaDNUhqRB5qIJyID-8iiX_Qt9mtQcNdWY,2217
9
+ cobra_array/types.py,sha256=XTEyAu4Gk16gIjDkY7ykmyO5iHAXaOV2KrqHXMrW5vM,2180
10
+ cobra_array/compat/__init__.py,sha256=q6PYjzqIy_PSO5Xz6_whB4ZcI8duokuEOPC4iH1jpOk,843
11
+ cobra_array/compat/_array.py,sha256=AW32ihYP0t1L6ILBCwldU1pbSm4N7OjF43MFkAefyhc,19439
12
+ cobra_array/compat/_array.pyi,sha256=IxSEQ_KgSscgZlAlIJFguRU9xDqamRjC9nKe_Ub5uJg,87225
13
+ cobra_array/compat/_base.py,sha256=cRqOx92lhZyUyG5ai9n12uyi-qYRcFLPl5mWCtA-fyA,1480
14
+ cobra_array/compat/_namespace.py,sha256=NhPx-1ROztLLmwJeZAMKlL2aubtu9Ro0J0FfvaIjQgQ,11945
15
+ cobra_array/compat/_namespace.pyi,sha256=2d9fE69nnyI-VRr-itKxfh0Tptd1kJw_d1wxxBB7B1k,36051
16
+ cobra_array-0.1.0.dist-info/licenses/LICENSE,sha256=UB1vOlHpp1w6bfzyNq42Ou5m31wc-fPCX4YHR_pSxIw,1066
17
+ cobra_array-0.1.0.dist-info/METADATA,sha256=U3kXDw_mTsnoKUgxkNIYKO_du8IWzxt_mmtkxy67Yek,4364
18
+ cobra_array-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
19
+ cobra_array-0.1.0.dist-info/top_level.txt,sha256=xPYu-vl_DH3zj5zD4ywYNKXcABMb7wBmRrWJyUal7pQ,12
20
+ cobra_array-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Cathie Li
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ cobra_array