MCPcopy Create free account
hub / github.com/numpy/numpy / einsum_path

Function einsum_path

numpy/core/einsumfunc.py:707–998  ·  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

705
706@array_function_dispatch(_einsum_path_dispatcher, module='numpy')
707def einsum_path(*operands, optimize='greedy', einsum_call=False):
708 """
709 einsum_path(subscripts, *operands, optimize='greedy')
710
711 Evaluates the lowest cost contraction order for an einsum expression by
712 considering the creation of intermediate arrays.
713
714 Parameters
715 ----------
716 subscripts : str
717 Specifies the subscripts for summation.
718 *operands : list of array_like
719 These are the arrays for the operation.
720 optimize : {bool, list, tuple, 'greedy', 'optimal'}
721 Choose the type of path. If a tuple is provided, the second argument is
722 assumed to be the maximum intermediate size created. If only a single
723 argument is provided the largest input or output array size is used
724 as a maximum intermediate size.
725
726 * if a list is given that starts with ``einsum_path``, uses this as the
727 contraction path
728 * if False no optimization is taken
729 * if True defaults to the 'greedy' algorithm
730 * 'optimal' An algorithm that combinatorially explores all possible
731 ways of contracting the listed tensors and chooses the least costly
732 path. Scales exponentially with the number of terms in the
733 contraction.
734 * 'greedy' An algorithm that chooses the best pair contraction
735 at each step. Effectively, this algorithm searches the largest inner,
736 Hadamard, and then outer products at each step. Scales cubically with
737 the number of terms in the contraction. Equivalent to the 'optimal'
738 path for most contractions.
739
740 Default is 'greedy'.
741
742 Returns
743 -------
744 path : list of tuples
745 A list representation of the einsum path.
746 string_repr : str
747 A printable representation of the einsum path.
748
749 Notes
750 -----
751 The resulting path indicates which terms of the input contraction should be
752 contracted first, the result of this contraction is then appended to the
753 end of the contraction list. This list can then be iterated over until all
754 intermediate contractions are complete.
755
756 See Also
757 --------
758 einsum, linalg.multi_dot
759
760 Examples
761 --------
762
763 We can begin with a chain dot example. In this case, it is optimal to
764 contract the ``b`` and ``c`` tensors first as represented by the first

Callers 1

einsumFunction · 0.85

Calls 13

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

Tested by

no test coverage detected