AnyTensor
Portable tensor ops across NumPy, JAX, PyTorch, and TensorFlow, with a focus on segment / GNN primitives.
Write a helper once; run it on whatever tensor the caller already has. Ordinary math uses the Python Array API via array-api-compat. Segment reductions stay on thin input-adaptive backends.
Docs (motivation, GAT-style case study, design, API): https://swamidass.github.io/anytensor/ — or uv run --group docs mkdocs serve from a checkout (docs/).
We follow Semantic Versioning: breaking changes require a major bump. Portability is backed by cross-backend / symbolic fuzz, a coverage gate, and pytest-run docs examples (Design).
Install
pip install "anytensor @ git+https://github.com/swamidass/anytensor.git"
# optional backends (NumPy is a core dependency)
pip install "anytensor[jax]" "anytensor[torch]" "anytensor[tensorflow]"
# or
pip install "anytensor[all]"
Requires Python ≥3.10. Backend floors: NumPy ≥1.24, JAX ≥0.4.32, PyTorch ≥2.1, TensorFlow ≥2.13.
Quick start
import anytensor as at
import numpy as np
x = np.arange(12.0).reshape(3, 4)
seg_ids = np.array([0, 0, 1])
y = at.segment_sum(x, seg_ids, num_segments=2)
The same call works on JAX / Torch / TF tensors. num_segments is required (JAX convention).
anytensor.jraph is a portable jraph:
GraphsTuple, batching/padding, and GraphNetwork on any backend. Nested
feature trees use anytensor.tree (jax.tree API; pure Python, NumPy is the
only binary dep). See the docs
Jraph and Tree sections.
Read next:
- Home / motivation — why AnyTensor, GAT neighbor-softmax case study across four backends
- Jraph — portable GraphsTuple / GraphNetwork
- Tree — nest helpers (pure Python + NumPy) for graphs and any structured record
- Design — principles, edge cases, testing as contract, SemVer
- Usage — promotion, segment helpers,
torch.compile, typing - Surprising differences — NaN / ±inf / graph / GPU gotchas from fuzz
- API reference — generated from docstrings
- Contributing — tests, fuzz, docs build
Docs / tests (checkout)
uv sync --extra all --group dev --group docs
uv run mkdocs serve
uv run pytest -m "not fuzz" --cov=anytensor --cov-report=term-missing
License
MIT. Backend dispatch patterns adapted from einops; see NOTICE.
Release files for anytensor 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| anytensor-1.1.0.tar.gz | 106.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| anytensor-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 158.8 kB
Release files / anytensor-1.1.0.tar.gz
| Download URL | anytensor-1.1.0.tar.gz |
|---|---|
| Size | 106.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b440ea714e92229ca4b3cef26417616fac535786227f7d8b25fcb2888d0a86aa
|
|
BLAKE2b-256 checksum How to use checksums |
8a960c1d506b7d080f560f1221ac3a33a25ea7f2c44427c89c54e9ceb78a5e2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.
Transparency logRelease files / anytensor-1.1.0-py3-none-any.whl
| Download URL | anytensor-1.1.0-py3-none-any.whl |
|---|---|
| Size | 52.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d97cf7813ec2c080a03317f41cb65a6bb512ba1d3b33f00836c4c250b097482d
|
|
BLAKE2b-256 checksum How to use checksums |
326fa0e349d390ed384a21765c4962b71890b6135741c932e402166f7627082e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.
Transparency log