dgasmith / opt_einsum

⚡️Optimizing einsum functions in NumPy, Tensorflow, Dask, and more with contraction order optimization.
https://dgasmith.github.io/opt_einsum/
MIT License
863 stars 68 forks source link

[WIP] add a preprocessor #207

Closed jcmgray closed 1 year ago

jcmgray commented 2 years ago

Description

This adds a potential preprocessor that takes an equation and converts it into a minimal form with the following simplifications:

along with a function, that transforms input arrays into the inputs for the new simplified eq. It is a function so that it could be part of a contract 'expression'.

This would address (#114, #99, #112, #167, #189, ...).

Example from the docstring:

eq = ',ab,abee,,cd,cd,dd->ac'
arrays = helpers.build_views(eq)
new_eq, simplifier = make_simplifier(eq)
new_eq
# 'ab,cd,d->ac'
sarrays = simplifier(arrays)
oe.contract(new_eq, *sarrays)
# array([[0.65245661, 0.14684493, 0.42543411, 0.32350895],
#        [0.38357005, 0.08632807, 0.25010672, 0.19018636]])

Todos

Notable points that this PR has either accomplished or will accomplish.

Status

codecov[bot] commented 2 years ago

Codecov Report

Merging #207 (d155c1f) into master (4c7eb61) will decrease coverage by 6.18%. The diff coverage is 0.00%.