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

[question]: compute contraction order and provide order at future call #184

Closed rohany closed 2 years ago

rohany commented 2 years ago

Hi, I was looking through the documentation and some issues and wanted to know if the following was possible:

I want to perform the search for a contract plan ahead of time, and then provide the plan to a contract call at some time in the future to avoid overhead from the search at the time that it is called. Is such a thing possible?

jcmgray commented 2 years ago

Hi @rohany, yes that is very much possible, e.g.:

expr = oe.contract_expression(eq, *shapes, optimize=opt)

x1 = expr(*arrays1)
x2 = expr(*arrays2)

or if you just want to keep the more compact path representation:

path, info = oe.contract_path(eq, *arrays, optimize=opt)

x1 = oe.contract(eq, *arrays1, optimize=path)
x2 = oe.contract(eq, *arrays2, optimize=path)

let us know if there is some specific way the docs are not clear about this at the moment!

rohany commented 2 years ago

Thanks for the quick response! I think that I just didn't know what to look for / what to search to find it.