Function Reference

opt_einsum.contract(subscripts, *operands[, …])

Evaluates the Einstein summation convention on the operands.

opt_einsum.contract_path(*operands, **kwargs)

Find a contraction order ‘path’, without performing the contraction.

opt_einsum.contract_expression(subscripts, …)

Generate a reusable expression for a given contraction with specific shapes, which can, for example, be cached.


Helper class for storing an explicit contraction_list which can then be repeatedly called solely with the array arguments.


A printable object to contain information about a contraction path.

opt_einsum.paths.optimal(inputs, output, …)

Computes all possible pair contractions in a depth-first recursive manner, sieving results based on memory_limit and the best path found so far.

opt_einsum.paths.greedy(inputs, output, …)

Finds the path by a three stage algorithm:

opt_einsum.paths.branch(inputs, output, …)


Get the symbol corresponding to int i - runs through the usual 52 letters before resorting to unicode characters, starting at chr(192).


Context in which contract intermediate results are shared.


Base class for different path optimizers to inherit from.

opt_einsum.paths.BranchBound([nbranch, …])

Explores possible pair contractions in a depth-first recursive manner like the optimal approach, but with extra heuristic early pruning of branches as well sieving by memory_limit and the best path found so far.


Base class for running any random path finder that benefits from repeated calling, possibly in a parallel fashion. Custom random optimizers should subclass this, and the setup method should be implemented with the following signature::.


  • cost_fn (callable, optional) – A function that returns a heuristic ‘cost’ of a potential contraction


Finds the optimal path of pairwise contractions without intermediate outer products based a dynamic programming approach presented in Phys.