About
cobra-array is a backend-agnostic array utility library that unifies array conversion, context control, and cross-library operations across NumPy/PyTorch-style ecosystems.
- Python: 3.9+
- Runtime deps:
array-api-compat(>= 1.11.2)
Features
- 🚀 Ackend-agnostic API: Work with different array backends through one consistent interface.
- 🚀 Context-driven unification: Automatically align namespace, dtype, and device via context managers and decorators.
- 🚀 Compatibility wrappers:
CompatArrayandCompatNamespaceprovide a clean, consistent layer over native backend behavior.
Installation
Install from PyPI
pip install cobra-array
Quick Start
-
Basic conversions:
import numpy as np from cobra_array.convert import to_numpy, to_tensor, to_list data = [[1, 2], [3, 4]] arr_np = to_numpy(data, dtype=np.float32) # numpy.ndarray float32 arr_torch = to_tensor(data, device="cpu") back_to_list = to_list(arr_np) # [[1.0, 2.0], [3.0, 4.0]]
-
Context-based conversion:
import numpy as np from cobra_array import array_context, as_context, context_spec with array_context(xp="numpy", dtype=np.float32, device="cpu"): x = as_context([1, 2, 3]) y = as_context(np.array([4, 5])) spec = context_spec()
-
Auto-unify function arguments:
import numpy as np from cobra_array import unify_args @unify_args(ref=0, unify_dtype=True, unify_device=True, arraylike_only=True) def add_and_mean(a, b): c = a + b return c.mean() out = add_and_mean(np.array([1, 2, 3]), [4, 5, 6])
-
Default backend strategy:
from cobra_array.default import as_default, default_spec spec = default_spec() x = as_default([1, 2, 3], unify_dtype=True, unify_device=True)
Requirements
- Python >= 3.9
array-api-compat>= 1.11.2
License
See LICENSE in the repository.
Links
Metadata
Release files for cobra-array 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cobra_array-0.2.2.tar.gz | 49.3 kB | Without provenance | Details for cobra_array-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cobra_array-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for cobra_array-0.2.2-py3-none-any.whl |
Total release size: 98.5 kB
Release files / cobra_array-0.2.2.tar.gz
| Download URL | cobra_array-0.2.2.tar.gz |
|---|---|
| Size | 49.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
43bbed2a27442e0fb435f5f341ef2153654a8e96552464b00687bb100468d510
|
|
BLAKE2b-256 checksum How to use checksums |
20af2feff5ce69841d9330cbe2f4386a01d2a72683c4374fca55d63d690dea16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.10
|
Release files / cobra_array-0.2.2-py3-none-any.whl
| Download URL | cobra_array-0.2.2-py3-none-any.whl |
|---|---|
| Size | 49.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6f8a60503fa6eae5f62482ef2980c128854034b8e24ada77362e704c24ef176
|
|
BLAKE2b-256 checksum How to use checksums |
0229660067c0027fce1a818f2187116c056e75e38053c46c4c548e03deae52e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.10
|
Security for cobra-array 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.