{"id":17176284,"url":"https://github.com/evhub/better_einsum","last_synced_at":"2025-04-13T17:07:38.387Z","repository":{"id":62591715,"uuid":"496378351","full_name":"evhub/better_einsum","owner":"evhub","description":"np.einsum but better","archived":false,"fork":false,"pushed_at":"2022-10-21T06:45:57.000Z","size":29,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T17:07:19.055Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evhub.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}},"created_at":"2022-05-25T20:20:33.000Z","updated_at":"2023-02-10T23:23:45.000Z","dependencies_parsed_at":"2022-11-04T07:50:18.495Z","dependency_job_id":null,"html_url":"https://github.com/evhub/better_einsum","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evhub%2Fbetter_einsum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evhub%2Fbetter_einsum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evhub%2Fbetter_einsum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evhub%2Fbetter_einsum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evhub","download_url":"https://codeload.github.com/evhub/better_einsum/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248750109,"owners_count":21155686,"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":[],"created_at":"2024-10-14T23:59:48.187Z","updated_at":"2025-04-13T17:07:38.360Z","avatar_url":"https://github.com/evhub.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `better_einsum`\n\n_[`np.einsum`](https://numpy.org/doc/stable/reference/generated/numpy.einsum.html) but better:_\n\n- better syntax (`\"C[i,k] = A[i,j] B[j,k]\"` instead of `\"ij, jk -\u003e ik\"`),\n- names and indices can be arbitrary variable names not just single letters,\n- support for keyword arguments (`einsum(\"C = A[i] B[i]\", A=..., B=...)`),\n- warnings on common bugs, and\n- an `einsum.exec` method for executing the einsum assignment in the calling scope.\n\n`pip install better_einsum` then:\n\n```pycon\n\u003e\u003e\u003e import numpy as np\n\u003e\u003e\u003e from better_einsum import einsum\n\n\u003e\u003e\u003e A = np.array([[1, 2], [3, 4]])\n\u003e\u003e\u003e B = np.array([[5, 6], [7, 8]])\n\n\u003e\u003e\u003e einsum(\"C[i,k] = A[i,j] * B[j,k]\", A=A, B=B)  # equivalent to A.dot(B)\narray([[19, 22],\n       [43, 50]])\n\n\u003e\u003e\u003e einsum(\"C = A[i,j] * B[i,j]\", A=A, B=B)  # equivalent to np.sum(A * B)\n70\n\n\u003e\u003e\u003e einsum(\"C[...] = A[i,...] * B[i,...]\", A=A, B=B)  # equivalent to np.sum(A * B, axis=0)\narray([26, 44])\n\n\u003e\u003e\u003e einsum(\"C[i,k] = A[i,j] B[j,k]\", A, B)  # * is optional; positional args are also supported\narray([[19, 22],\n       [43, 50]])\n\n\u003e\u003e\u003e einsum(\"C[i,k] = A[i,j] * B[j,k]\", A, A)  # better_einsum will catch common mistakes for you\nbetter_einsum.py: UserWarning: better_einsum: variable 'B' in calling scope points to a different object than was passed in; this usually denotes an error\narray([[ 7, 10],\n       [15, 22]])\n\n\u003e\u003e\u003e einsum(\"_[i,k] = _[i,j] * _[j,k]\", A, B)  # use placeholders if you don't want to name your variables\narray([[19, 22],\n       [43, 50]])\n\n\u003e\u003e\u003e einsum.exec(\"C[i,k] = A[i,j] * B[j,k]\")  # directly assigns to C and looks up A and B\narray([[19, 22],\n       [43, 50]])\n\u003e\u003e\u003e C\narray([[19, 22],\n       [43, 50]])\n\n\u003e\u003e\u003e import jax.numpy as jnp\n\u003e\u003e\u003e from functools import partial\n\u003e\u003e\u003e jnp_einsum = partial(einsum, base_einsum_func=jnp.einsum)  # better_einsum for JAX\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevhub%2Fbetter_einsum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevhub%2Fbetter_einsum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevhub%2Fbetter_einsum/lists"}