This commit is contained in:
2026-05-06 19:47:31 +07:00
parent 94d8682530
commit 12dbb7731b
9963 changed files with 2747894 additions and 0 deletions
@@ -0,0 +1,117 @@
Metadata-Version: 2.3
Name: opt_einsum
Version: 3.4.0
Summary: Path optimization of einsum functions.
Author-email: Daniel Smith <dgasmith@icloud.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
# Optimized Einsum
[![Tests](https://github.com/dgasmith/opt_einsum/actions/workflows/Tests.yml/badge.svg)](https://github.com/dgasmith/opt_einsum/actions/workflows/Tests.yml)
[![codecov](https://codecov.io/gh/dgasmith/opt_einsum/branch/master/graph/badge.svg)](https://codecov.io/gh/dgasmith/opt_einsum)
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/opt_einsum/badges/version.svg)](https://anaconda.org/conda-forge/opt_einsum)
[![PyPI](https://img.shields.io/pypi/v/opt_einsum.svg)](https://pypi.org/project/opt-einsum/#description)
[![PyPIStats](https://img.shields.io/pypi/dm/opt_einsum)](https://pypistats.org/packages/opt-einsum)
[![Documentation Status](https://github.com/dgasmith/opt_einsum/actions/workflows/Docs.yaml/badge.svg)](https://dgasmith.github.io/opt_einsum/)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.00753/status.svg)](https://doi.org/10.21105/joss.00753)
## Optimized Einsum: A tensor contraction order optimizer
Optimized einsum can significantly reduce the overall execution time of einsum-like expressions (e.g.,
[`np.einsum`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.einsum.html),
[`dask.array.einsum`](https://docs.dask.org/en/latest/array-api.html#dask.array.einsum),
[`pytorch.einsum`](https://pytorch.org/docs/stable/torch.html#torch.einsum),
[`tensorflow.einsum`](https://www.tensorflow.org/api_docs/python/tf/einsum),
)
by optimizing the expression's contraction order and dispatching many
operations to canonical BLAS, cuBLAS, or other specialized routines.
Optimized
einsum is agnostic to the backend and can handle NumPy, Dask, PyTorch,
Tensorflow, CuPy, Sparse, Theano, JAX, and Autograd arrays as well as potentially
any library which conforms to a standard API. See the
[**documentation**](https://dgasmith.github.io/opt_einsum/) for more
information.
## Example usage
The [`opt_einsum.contract`](https://dgasmith.github.io/opt_einsum/api_reference#opt_einsumcontract)
function can often act as a drop-in replacement for `einsum`
functions without further changes to the code while providing superior performance.
Here, a tensor contraction is performed with and without optimization:
```python
import numpy as np
from opt_einsum import contract
N = 10
C = np.random.rand(N, N)
I = np.random.rand(N, N, N, N)
%timeit np.einsum('pi,qj,ijkl,rk,sl->pqrs', C, C, I, C, C)
1 loops, best of 3: 934 ms per loop
%timeit contract('pi,qj,ijkl,rk,sl->pqrs', C, C, I, C, C)
1000 loops, best of 3: 324 us per loop
```
In this particular example, we see a ~3000x performance improvement which is
not uncommon when compared against unoptimized contractions. See the [backend
examples](https://dgasmith.github.io/opt_einsum/getting_started/backends)
for more information on using other backends.
## Features
The algorithms found in this repository often power the `einsum` optimizations
in many of the above projects. For example, the optimization of `np.einsum`
has been passed upstream and most of the same features that can be found in
this repository can be enabled with `np.einsum(..., optimize=True)`. However,
this repository often has more up to date algorithms for complex contractions.
The following capabilities are enabled by `opt_einsum`:
* Inspect [detailed information](https://dgasmith.github.io/opt_einsum/paths/introduction) about the path chosen.
* Perform contractions with [numerous backends](https://dgasmith.github.io/opt_einsum/getting_started/backends), including on the GPU and with libraries such as [TensorFlow](https://www.tensorflow.org) and [PyTorch](https://pytorch.org).
* Generate [reusable expressions](https://dgasmith.github.io/opt_einsum/getting_started/reusing_paths), potentially with [constant tensors](https://dgasmith.github.io/opt_einsum/getting_started/reusing_paths#specifying-constants), that can be compiled for greater performance.
* Use an arbitrary number of indices to find contractions for [hundreds or even thousands of tensors](https://dgasmith.github.io/opt_einsum/examples/large_expr_with_greedy).
* Share [intermediate computations](https://dgasmith.github.io/opt_einsum/getting_started/sharing_intermediates) among multiple contractions.
* Compute gradients of tensor contractions using [autograd](https://github.com/HIPS/autograd) or [jax](https://github.com/google/jax)
Please see the [documentation](https://dgasmith.github.io/opt_einsum/index) for more features!
## Installation
`opt_einsum` can either be installed via `pip install opt_einsum` or from conda `conda install opt_einsum -c conda-forge`.
See the installation [documentation](https://dgasmith.github.io/opt_einsum/getting_started/install) for further methods.
## Citation
If this code has benefited your research, please support us by citing:
Daniel G. A. Smith and Johnnie Gray, opt_einsum - A Python package for optimizing contraction order for einsum-like expressions. *Journal of Open Source Software*, **2018**, 3(26), 753
DOI: <https://doi.org/10.21105/joss.00753>
## Contributing
All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.
A detailed overview on how to contribute can be found in the [contributing guide](https://github.com/dgasmith/opt_einsum/blob/master/.github/CONTRIBUTING.md).
@@ -0,0 +1,61 @@
opt_einsum-3.4.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
opt_einsum-3.4.0.dist-info/METADATA,sha256=n2eRFAxeG-TxsYk2XmMS1xGh6q6zmbXdZ0H3pL2Z0Ds,6345
opt_einsum-3.4.0.dist-info/RECORD,,
opt_einsum-3.4.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
opt_einsum-3.4.0.dist-info/licenses/LICENSE,sha256=eyZpGnyO5Ir0JaU8uuqryao6hOouk_5HoezFUMHedts,1080
opt_einsum/__init__.py,sha256=LPIPWo9YglJpU7soEk8We_APdsvZX4p5DfDzXmbC3f8,834
opt_einsum/__pycache__/__init__.cpython-312.pyc,,
opt_einsum/__pycache__/_version.cpython-312.pyc,,
opt_einsum/__pycache__/blas.cpython-312.pyc,,
opt_einsum/__pycache__/contract.cpython-312.pyc,,
opt_einsum/__pycache__/helpers.cpython-312.pyc,,
opt_einsum/__pycache__/parser.cpython-312.pyc,,
opt_einsum/__pycache__/path_random.cpython-312.pyc,,
opt_einsum/__pycache__/paths.cpython-312.pyc,,
opt_einsum/__pycache__/sharing.cpython-312.pyc,,
opt_einsum/__pycache__/testing.cpython-312.pyc,,
opt_einsum/__pycache__/typing.cpython-312.pyc,,
opt_einsum/_version.py,sha256=YWGqQYvejjlymmjzg4jncyBgDC760jlRmyon_Rd-2uQ,411
opt_einsum/backends/__init__.py,sha256=bEAsIERI4AgTwEKxwzGQFDabNnIqiqGpJkenGm4mSQw,614
opt_einsum/backends/__pycache__/__init__.cpython-312.pyc,,
opt_einsum/backends/__pycache__/cupy.cpython-312.pyc,,
opt_einsum/backends/__pycache__/dispatch.cpython-312.pyc,,
opt_einsum/backends/__pycache__/jax.cpython-312.pyc,,
opt_einsum/backends/__pycache__/object_arrays.cpython-312.pyc,,
opt_einsum/backends/__pycache__/tensorflow.cpython-312.pyc,,
opt_einsum/backends/__pycache__/theano.cpython-312.pyc,,
opt_einsum/backends/__pycache__/torch.cpython-312.pyc,,
opt_einsum/backends/cupy.py,sha256=ha9l1kZxL84zOtAAgv4idI5wQv9a1HOlnadMVcy855g,950
opt_einsum/backends/dispatch.py,sha256=MR_8pzT0i9HdwKn-eklIk43seLUQbnvWM9otF4JTuto,4887
opt_einsum/backends/jax.py,sha256=4YFucG53tR-QrzbKO_N47yn2Kc1xPp_9jLjZIU_lRUc,1085
opt_einsum/backends/object_arrays.py,sha256=W91g6HfwDAHFAG8nIsLsjJAy75UuBno9AMeSb8wYF-0,2016
opt_einsum/backends/tensorflow.py,sha256=OgbLpjGyDxeFUcYjJUoVFb8bSyihDjPM0kUV6uEniJA,3891
opt_einsum/backends/theano.py,sha256=fBJaL2FOnx9_B7js4o0gXy3g6dzOdr_fT9kqXkSCCJM,1698
opt_einsum/backends/torch.py,sha256=3v1033W8XyjI4OIqCMvJKZsSP1xKHR-8-_RJRXVUAvI,3583
opt_einsum/blas.py,sha256=sn3kevdTgN6xYUxLo0QBQqXZ47tUYAQgMEeHJt0GN_c,3500
opt_einsum/contract.py,sha256=pCrV7YPgkD7pRY0KiXOYbGuywSCY-cYMyyj57Hr58PI,40341
opt_einsum/helpers.py,sha256=Y1PHxBEu49BEStlym3u8ak8xU3ycwBVu4CUFZ7qiwAA,4270
opt_einsum/parser.py,sha256=PoUJF5YtYlS-C53CH74ewXJ6pla7KWinnSqjOnBQtYU,13269
opt_einsum/path_random.py,sha256=2vkE2oshUXHlW6gtq8bcnflfVfHVaxBSYvkA9wTDvUI,14356
opt_einsum/paths.py,sha256=xqvuBrXX7Xwe22D7L1OmhUt8WUmgh4ZFdvSRPwXMzMw,51711
opt_einsum/sharing.py,sha256=PvWhN59XlvtKbQI6ziYK5lha2HTIvPzypzUxkxi5kHw,6914
opt_einsum/testing.py,sha256=MYJcR1qrEyqIkXRSdIalpu5B53cSAR59Ue2-JMnsfJg,6352
opt_einsum/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
opt_einsum/tests/__pycache__/__init__.cpython-312.pyc,,
opt_einsum/tests/__pycache__/test_backends.cpython-312.pyc,,
opt_einsum/tests/__pycache__/test_blas.cpython-312.pyc,,
opt_einsum/tests/__pycache__/test_contract.cpython-312.pyc,,
opt_einsum/tests/__pycache__/test_edge_cases.cpython-312.pyc,,
opt_einsum/tests/__pycache__/test_input.cpython-312.pyc,,
opt_einsum/tests/__pycache__/test_parser.cpython-312.pyc,,
opt_einsum/tests/__pycache__/test_paths.cpython-312.pyc,,
opt_einsum/tests/__pycache__/test_sharing.cpython-312.pyc,,
opt_einsum/tests/test_backends.py,sha256=XcL6ifV4mxUzVAcqg0Yaxi3fY-LhvDXH2caiPVTmkKQ,15562
opt_einsum/tests/test_blas.py,sha256=r598QtkCxqXIk93eZQvvoWDMM2qgsWY4hT9_iAryU7o,3590
opt_einsum/tests/test_contract.py,sha256=Gti0GrEWdUg-DSCr2BTZNgYMHDcg5FdXmpjps95IYmE,8589
opt_einsum/tests/test_edge_cases.py,sha256=2zMNMK3YqOhEYxQu937qk_csKxUCZEzEXeW_fdcieZQ,5283
opt_einsum/tests/test_input.py,sha256=KlWo7SSfFsqymeTVpUQ2PsPqbIudccmkFsOSELNNqmI,8275
opt_einsum/tests/test_parser.py,sha256=t0oqBfPEHuVEiQHcjJJDYeTwiwmUVF-Vs3pgi9Mu8T8,2085
opt_einsum/tests/test_paths.py,sha256=aSKPJgABCjc0bX76dGwVoIwPHKMr-_iJD3by3wiFdEE,19461
opt_einsum/tests/test_sharing.py,sha256=hj3PBxbqW8TYzuxNgodpgbPvj3mwB9uCycTyxQbdef4,13125
opt_einsum/typing.py,sha256=Bsc-mCCegpgRSRuMARt4F3fPlhCRhvgg5RGaINYuVR0,937
@@ -0,0 +1,4 @@
Wheel-Version: 1.0
Generator: hatchling 1.25.0
Root-Is-Purelib: true
Tag: py3-none-any
@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2014 Daniel Smith
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.