MCPcopy Index your code
hub / github.com/numpy/numpy / einsum_path

Function einsum_path

numpy/_core/einsumfunc.py:635–920  ·  view source on GitHub ↗

einsum_path(subscripts, *operands, optimize='greedy') Evaluates the lowest cost contraction order for an einsum expression by considering the creation of intermediate arrays. Parameters ---------- subscripts : str Specifies the subscripts for summation. *operan

(*operands, optimize='greedy', einsum_call=False)

Source from the content-addressed store, hash-verified

633
634@array_function_dispatch(_einsum_path_dispatcher, module='numpy')
635def einsum_path(*operands, optimize='greedy', einsum_call=False):
636 """
637 einsum_path(subscripts, *operands, optimize='greedy')
638
639 Evaluates the lowest cost contraction order for an einsum expression by
640 considering the creation of intermediate arrays.
641
642 Parameters
643 ----------
644 subscripts : str
645 Specifies the subscripts for summation.
646 *operands : list of array_like
647 These are the arrays for the operation.
648 optimize : {bool, list, tuple, 'greedy', 'optimal'}
649 Choose the type of path. If a tuple is provided, the second argument is
650 assumed to be the maximum intermediate size created. If only a single
651 argument is provided the largest input or output array size is used
652 as a maximum intermediate size.
653
654 * if a list is given that starts with ``einsum_path``, uses this as the
655 contraction path
656 * if False no optimization is taken
657 * if True defaults to the 'greedy' algorithm
658 * 'optimal' An algorithm that combinatorially explores all possible
659 ways of contracting the listed tensors and chooses the least costly
660 path. Scales exponentially with the number of terms in the
661 contraction.
662 * 'greedy' An algorithm that chooses the best pair contraction
663 at each step. Effectively, this algorithm searches the largest inner,
664 Hadamard, and then outer products at each step. Scales cubically with
665 the number of terms in the contraction. Equivalent to the 'optimal'
666 path for most contractions.
667
668 Default is 'greedy'.
669
670 Returns
671 -------
672 path : list of tuples
673 A list representation of the einsum path.
674 string_repr : str
675 A printable representation of the einsum path.
676
677 Notes
678 -----
679 The resulting path indicates which terms of the input contraction should be
680 contracted first, the result of this contraction is then appended to the
681 end of the contraction list. This list can then be iterated over until all
682 intermediate contractions are complete.
683
684 See Also
685 --------
686 einsum, linalg.multi_dot
687
688 Examples
689 --------
690
691 We can begin with a chain dot example. In this case, it is optimal to
692 contract the ``b`` and ``c`` tensors first as represented by the first

Callers 1

einsumFunction · 0.85

Calls 12

_parse_einsum_inputFunction · 0.85
_compute_size_by_dictFunction · 0.85
_greedy_pathFunction · 0.85
_optimal_pathFunction · 0.85
_find_contractionFunction · 0.85
_flop_countFunction · 0.85
sumFunction · 0.85
splitMethod · 0.80
replaceMethod · 0.80
joinMethod · 0.80
maxFunction · 0.70
keysMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…