{"id":16669392,"url":"https://github.com/lgeiger/mypy-einsum","last_synced_at":"2026-05-09T03:32:49.859Z","repository":{"id":211494428,"uuid":"720913804","full_name":"lgeiger/mypy-einsum","owner":"lgeiger","description":"MyPy Type Checking for NumPy/Jax/PyTorch Einsum Operations","archived":false,"fork":false,"pushed_at":"2023-12-08T23:16:35.000Z","size":21,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-11T20:47:04.476Z","etag":null,"topics":["deep-learning","einsum","jax","mypy","mypy-plugins","numpy","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lgeiger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-20T00:31:54.000Z","updated_at":"2024-10-10T21:52:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"47f294bb-92c2-41be-9130-ec89bcba977c","html_url":"https://github.com/lgeiger/mypy-einsum","commit_stats":null,"previous_names":["lgeiger/mypy-einsum"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lgeiger%2Fmypy-einsum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lgeiger%2Fmypy-einsum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lgeiger%2Fmypy-einsum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lgeiger%2Fmypy-einsum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lgeiger","download_url":"https://codeload.github.com/lgeiger/mypy-einsum/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247278534,"owners_count":20912753,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","einsum","jax","mypy","mypy-plugins","numpy","pytorch"],"created_at":"2024-10-12T11:32:24.127Z","updated_at":"2025-09-23T10:36:14.960Z","avatar_url":"https://github.com/lgeiger.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MyPy Type Checking for NumPy/Jax/PyTorch Einsum Operations\n\n`mypy_einsum` is a [Mypy](https://mypy.readthedocs.io/) plugin for type checking [`np.einsum`](https://numpy.org/doc/stable/reference/generated/numpy.einsum.html), [`jax.numpy.einsum`](https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.einsum.html), and [`torch.einsum`](https://pytorch.org/docs/stable/generated/torch.einsum.html) operations.\n\nThe Einstein summation convention can be used to compute many multi-dimensional, linear algebraic array operations. `einsum` provides a succinct way of representing these.\n\nHowever, since `einsum` equations are passed as a string, it is very easy to overlook typos or other bugs as linters are unable to help.\n`mypy_einsum` is a [Mypy](https://mypy.readthedocs.io/) plugin that that is able to statically verify the correctness of `einsum` equations with needing to execute the code.\n\n## Installation\n\n`mypy_einsum` can be installed with [`pip`](https://pip.pypa.io/):\n\n```shell\npip install mypy-einsum\n```\n\n## Setup\n\nTo enable the plugin, add it to you projects [Mypy configuration file](https://mypy.readthedocs.io/en/stable/config_file.html).\nUsually `mypy.ini`:\n\n```ini\n[mypy]\nplugins = mypy_einsum\n```\n\nor `pyproject.toml`:\n\n```toml\n[tool.mypy]\nplugins = [\"mypy_einsum\"]\n```\n\n## Example\n\nCan you spot the 🐛 without running the code?\n\n```python\nimport numpy as np\n\na = np.arange(9).reshape(3, 3)\n\nnp.einsum(\"ik,kj-\u003eij\", a)\n```\n\n`mypy_einsum` will catch it for you:\n\n```shell\n❯ mypy example.py --pretty\nexample.py:5: error: Number of einsum subscripts must be equal to the\nnumber of operands.  [einsum]\n    np.einsum(\"ik,kj-\u003eij\", a)\n              ^~~~~~~~~~~\nFound 1 error in 1 file (checked 1 source file)\n```\n\nAfter fixing it `mypy` will succeed 🎉:\n\n```python\nnp.einsum(\"ik,kj-\u003eij\", a, a)\n```\n\n```bash\n❯ mypy example.py\nSuccess: no issues found in 1 source file\n```\n\n## Supported Operations\n\n- [`np.einsum`](https://numpy.org/doc/stable/reference/generated/numpy.einsum.html)\n- [`np.einsum_path`](https://numpy.org/doc/stable/reference/generated/numpy.einsum_path.html)\n- [`jax.numpy.einsum`](https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.einsum.html)\n- [`jax.numpy.einsum_path`](https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.einsum_path.html)\n- [`torch.einsum`](https://pytorch.org/docs/stable/generated/torch.einsum.html)\n\n## Reporting Issues and Contributing\n\n`mypy_einsum` aims to never raise warnings for valid `einsum` operations. If you encounter a warning that you believe is incorrect, or think `mypy_einsum` is not reporting an error please let us know. Contributions are very welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flgeiger%2Fmypy-einsum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flgeiger%2Fmypy-einsum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flgeiger%2Fmypy-einsum/lists"}