# eins
## One tensor operation is all you need
[![PyPI - Version](https://img.shields.io/pypi/v/eins.svg)](https://pypi.org/project/eins)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/eins.svg)](https://pypi.org/project/eins)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)
What if most of your machine learning model code could be replaced by a single operation? Eins gives
you a powerful language to describe array manipulation, making it a one-stop shop for all of your AI
needs.
Let's say you want to compute batched pairwise distance between two batches of arrays of points:
```python
from eins import EinsOp
EinsOp('batch n1 d, batch n2 d -> batch n1 n2',
combine='add', reduce='l2_norm')(pts1, -pts2)
```
If you're more interested in deep learning, here is [the patch embedding from a vision
transformer](https://nn.labml.ai/transformers/vit/index.html#PatchEmbeddings). That means breaking
up an image into patches and then linearly embedding each patch.
```python
from eins import EinsOp
patchify = EinsOp('''b (n_p patch) (n_p patch) c, (patch patch c) emb -> b (n_p n_p) emb''')
patches = patchify(images, kernel)
```
You input the shapes and Eins will figure out what to do.
If you've used [`einops`](https://github.com/arogozhnikov/einops), then think of Eins as `einops`
with a more ambitious goal—being the only operation you should need for your next deep learning
project.
Interested? Check out the [tutorial](https://nicholas-miklaucic.github.io/eins/tutorial/), which
walks you through the highlights of Eins with examples of how Eins can make the array operations you
know and love more readable, portable, and robust.
To learn more, consult the [documentation](https://nicholas-miklaucic.github.io/eins/) or
the [examples](examples/README.md).
## Installation
```console
pip install eins
```
Eins works with anything that implements the [Array
API](https://data-apis.org/array-api/latest/index.html), and Eins explicitly promises to support
NumPy, PyTorch, and JAX—including full differentiability. You will need one of those libraries to
actually use Eins operations.
## Features
- 🧩 A solver that can handle duplicate axes, named constants, and constraints
- 🚀 Compilation and optimization for high performance without sacrificing readability
- Split, concatenate, stack, flatten, transpose, normalize, reduce, broadcast, and more
- Works across frameworks
- A composable set of unified array operations for portable softmax, power normalization, and more
## Roadmap
Eins is still in heavy development. Here's a sense of where we're headed.
### Near-Term (weeks)
- [ ] Updating indexing syntax to match `eindex`
- [ ] Unit array to indicate zero-dimensional tensors
- [ ] `...` for batching over dynamic numbers of batch axes
- [ ] Specifying intermediate results to control the order of reduction
- [ ] Support `-` and `/`
- [ ] Better error reporting
- [ ] Ways of visualizing and inspecting the computation graph
- [ ] Typo checking in errors about axes
- [ ] Multiple outputs, either through arrows or commas
### Long-Term (months)
- [ ] Layers for popular ML frameworks
- [ ] Automatically optimizing the execution of a specific EinsOp for a specific
computer and input size
- [ ] Completing full support for tensor indexing
- [ ] Static typing support
- [ ] Tabulating the model FLOPs/memory usage as a function of named axes
- [ ] Functionality akin to `pack` and `unpack`
## Acknowledgements
The excellent [`einops`](https://github.com/arogozhnikov/einops) library
inspired this project and its syntax. After working on my own extension to
handle indexing, I realized that
[`eindex`](https://github.com/arogozhnikov/eindex) already had a more coherent
vision for what indexing can look like, and so much of that syntax in this
library borrows from that one.
## Contributing
Any contributions to Eins are welcomed and appreciated! If you're interested
in making serious changes or extensions to the syntax of operations, consider
reaching out first to make sure we're on the same page. For any code changes, do
make sure you're using the project Ruff settings.
## License
Eins is distributed under the terms of the
[MIT](https://spdx.org/licenses/MIT.html) license.
Raw data
{
"_id": null,
"home_page": null,
"name": "eins",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "array manipulation, artificial intelligence, deep learning, einops, machine learning, neural networks, scientific computing, tensor manipulation",
"author": null,
"author_email": "Nicholas Miklaucic <nicholas.miklaucic@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/59/3b/c4a03b8ff9beaf5bd142e609ef1dd17f531ede0ba50de49a4fbb5ae4e294/eins-0.1.1.tar.gz",
"platform": null,
"description": "# eins\n\n## One tensor operation is all you need\n\n[![PyPI - Version](https://img.shields.io/pypi/v/eins.svg)](https://pypi.org/project/eins)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/eins.svg)](https://pypi.org/project/eins)\n[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)\n\nWhat if most of your machine learning model code could be replaced by a single operation? Eins gives\nyou a powerful language to describe array manipulation, making it a one-stop shop for all of your AI\nneeds.\n\nLet's say you want to compute batched pairwise distance between two batches of arrays of points:\n\n```python\nfrom eins import EinsOp\nEinsOp('batch n1 d, batch n2 d -> batch n1 n2',\n combine='add', reduce='l2_norm')(pts1, -pts2)\n```\n\nIf you're more interested in deep learning, here is [the patch embedding from a vision\ntransformer](https://nn.labml.ai/transformers/vit/index.html#PatchEmbeddings). That means breaking\nup an image into patches and then linearly embedding each patch.\n\n```python\nfrom eins import EinsOp\npatchify = EinsOp('''b (n_p patch) (n_p patch) c, (patch patch c) emb -> b (n_p n_p) emb''')\npatches = patchify(images, kernel)\n```\n\nYou input the shapes and Eins will figure out what to do.\n\nIf you've used [`einops`](https://github.com/arogozhnikov/einops), then think of Eins as `einops`\nwith a more ambitious goal\u2014being the only operation you should need for your next deep learning\nproject.\n\nInterested? Check out the [tutorial](https://nicholas-miklaucic.github.io/eins/tutorial/), which\nwalks you through the highlights of Eins with examples of how Eins can make the array operations you\nknow and love more readable, portable, and robust.\n\nTo learn more, consult the [documentation](https://nicholas-miklaucic.github.io/eins/) or\nthe [examples](examples/README.md).\n\n## Installation\n\n```console\npip install eins\n```\n\nEins works with anything that implements the [Array\nAPI](https://data-apis.org/array-api/latest/index.html), and Eins explicitly promises to support\nNumPy, PyTorch, and JAX\u2014including full differentiability. You will need one of those libraries to\nactually use Eins operations.\n\n## Features\n\n- \ud83e\udde9 A solver that can handle duplicate axes, named constants, and constraints\n- \ud83d\ude80 Compilation and optimization for high performance without sacrificing readability\n- Split, concatenate, stack, flatten, transpose, normalize, reduce, broadcast, and more\n- Works across frameworks\n- A composable set of unified array operations for portable softmax, power normalization, and more\n\n## Roadmap\n\nEins is still in heavy development. Here's a sense of where we're headed.\n\n### Near-Term (weeks)\n\n- [ ] Updating indexing syntax to match `eindex`\n- [ ] Unit array to indicate zero-dimensional tensors\n- [ ] `...` for batching over dynamic numbers of batch axes\n- [ ] Specifying intermediate results to control the order of reduction\n- [ ] Support `-` and `/`\n- [ ] Better error reporting\n- [ ] Ways of visualizing and inspecting the computation graph\n- [ ] Typo checking in errors about axes\n- [ ] Multiple outputs, either through arrows or commas\n\n### Long-Term (months)\n\n- [ ] Layers for popular ML frameworks\n- [ ] Automatically optimizing the execution of a specific EinsOp for a specific\n computer and input size\n- [ ] Completing full support for tensor indexing\n- [ ] Static typing support\n- [ ] Tabulating the model FLOPs/memory usage as a function of named axes\n- [ ] Functionality akin to `pack` and `unpack`\n\n## Acknowledgements\n\nThe excellent [`einops`](https://github.com/arogozhnikov/einops) library\ninspired this project and its syntax. After working on my own extension to\nhandle indexing, I realized that\n[`eindex`](https://github.com/arogozhnikov/eindex) already had a more coherent\nvision for what indexing can look like, and so much of that syntax in this\nlibrary borrows from that one.\n\n## Contributing\n\nAny contributions to Eins are welcomed and appreciated! If you're interested\nin making serious changes or extensions to the syntax of operations, consider\nreaching out first to make sure we're on the same page. For any code changes, do\nmake sure you're using the project Ruff settings.\n\n## License\n\nEins is distributed under the terms of the\n[MIT](https://spdx.org/licenses/MIT.html) license.",
"bugtrack_url": null,
"license": null,
"summary": "One tensor operation is all you need",
"version": "0.1.1",
"project_urls": {
"Documentation": "https://github.com/nicholas-miklaucic/eins#readme",
"Issues": "https://github.com/nicholas-miklaucic/eins/issues",
"Source": "https://github.com/nicholas-miklaucic/eins"
},
"split_keywords": [
"array manipulation",
" artificial intelligence",
" deep learning",
" einops",
" machine learning",
" neural networks",
" scientific computing",
" tensor manipulation"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "bae0ea03efcebfd1e47528c1474b2dfa1e09269372114bdeeffcabbd8eb7d242",
"md5": "a61e1842172d2f0655c8baf08eaa0cf6",
"sha256": "d23302b85aadf5a30d28f3285e955914d3c1dea1eb12573717bc2b2492247b2f"
},
"downloads": -1,
"filename": "eins-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a61e1842172d2f0655c8baf08eaa0cf6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 37493,
"upload_time": "2024-04-20T19:35:12",
"upload_time_iso_8601": "2024-04-20T19:35:12.639388Z",
"url": "https://files.pythonhosted.org/packages/ba/e0/ea03efcebfd1e47528c1474b2dfa1e09269372114bdeeffcabbd8eb7d242/eins-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "593bc4a03b8ff9beaf5bd142e609ef1dd17f531ede0ba50de49a4fbb5ae4e294",
"md5": "05884028d248c190c128b82063dbc10a",
"sha256": "f52e5de0c55660df8fafea6fa72821198176651f2998ee56ab1bea38658fb672"
},
"downloads": -1,
"filename": "eins-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "05884028d248c190c128b82063dbc10a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 646590,
"upload_time": "2024-04-20T19:35:11",
"upload_time_iso_8601": "2024-04-20T19:35:11.185506Z",
"url": "https://files.pythonhosted.org/packages/59/3b/c4a03b8ff9beaf5bd142e609ef1dd17f531ede0ba50de49a4fbb5ae4e294/eins-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-20 19:35:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "nicholas-miklaucic",
"github_project": "eins#readme",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "eins"
}