HEX
Server: LiteSpeed
System: Linux standart9.isimtescil.net 3.10.0-962.3.2.lve1.5.26.7.el7.x86_64 #1 SMP Wed Oct 2 07:53:12 EDT 2019 x86_64
User: karalev (5310)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //opt/alt/python37/lib64/python3.7/site-packages/numpy/core/__pycache__/einsumfunc.cpython-37.pyc
B

<�Fd͊�@s�dZddlmZmZmZddlmZddlmZm	Z	m
Z
ddgZdZe
e�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�ZdS)z&
Implementation of optimized einsum.

�)�division�absolute_import�print_function)�c_einsum)�asarray�
asanyarray�result_type�einsum�einsum_pathZ4abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZcCs"d}x|D]}|||9}q
W|S)a�
    Computes the product of the elements in indices based on the dictionary
    idx_dict.

    Parameters
    ----------
    indices : iterable
        Indices to base the product on.
    idx_dict : dictionary
        Dictionary of index sizes

    Returns
    -------
    ret : int
        The resulting product.

    Examples
    --------
    >>> _compute_size_by_dict('abbc', {'a': 2, 'b':3, 'c':5})
    90

    ��)�indices�idx_dictZret�irr�H/opt/alt/python37/lib64/python3.7/site-packages/numpy/core/einsumfunc.py�_compute_size_by_dicts
rc
Csrt�}|��}g}x8t|�D],\}}||kr6||O}q|�|�||O}qW||@}||}	|�|�|||	|fS)a

    Finds the contraction for a given set of input and output sets.

    Parameters
    ----------
    positions : iterable
        Integer positions of terms used in the contraction.
    input_sets : list
        List of sets that represent the lhs side of the einsum subscript
    output_set : set
        Set that represents the rhs side of the overall einsum subscript

    Returns
    -------
    new_result : set
        The indices of the resulting contraction
    remaining : list
        List of sets that have not been contracted, the new set is appended to
        the end of this list
    idx_removed : set
        Indices removed from the entire contraction
    idx_contraction : set
        The indices used in the current contraction

    Examples
    --------

    # A simple dot product test case
    >>> pos = (0, 1)
    >>> isets = [set('ab'), set('bc')]
    >>> oset = set('ac')
    >>> _find_contraction(pos, isets, oset)
    ({'a', 'c'}, [{'a', 'c'}], {'b'}, {'a', 'b', 'c'})

    # A more complex case with additional terms in the contraction
    >>> pos = (0, 2)
    >>> isets = [set('abd'), set('ac'), set('bdc')]
    >>> oset = set('ac')
    >>> _find_contraction(pos, isets, oset)
    ({'a', 'c'}, [{'a', 'c'}, {'a', 'c'}], {'b', 'd'}, {'a', 'b', 'c', 'd'})
    )�set�copy�	enumerate�append)
�	positions�
input_sets�
output_set�idx_contractZ
idx_remain�	remaining�ind�value�
new_result�idx_removedrrr�_find_contraction-s+


rcCs<dg|fg}x�tt|�d�D]�}g}g}xFtt|�|�D]2}x,t|dt|�|�D]}	|�||	f�qXWq<Wx�|D]�}
|
\}}}
xp|D]h}t||
|�}|\}}}}t||�}||kr�q�t||�}|r�|d9}||7}||g}|�|||f�q�WqxW|}qWt|�dk�r$ttt|���gSt|dd�d�d}|S)a�
    Computes all possible pair contractions, sieves the results based
    on ``memory_limit`` and returns the lowest cost path. This algorithm
    scales factorial with respect to the elements in the list ``input_sets``.

    Parameters
    ----------
    input_sets : list
        List of sets that represent the lhs side of the einsum subscript
    output_set : set
        Set that represents the rhs side of the overall einsum subscript
    idx_dict : dictionary
        Dictionary of index sizes
    memory_limit : int
        The maximum number of elements in a temporary array

    Returns
    -------
    path : list
        The optimal contraction order within the memory limit constraint.

    Examples
    --------
    >>> isets = [set('abd'), set('ac'), set('bdc')]
    >>> oset = set('')
    >>> idx_sizes = {'a': 1, 'b':2, 'c':3, 'd':4}
    >>> _path__optimal_path(isets, oset, idx_sizes, 5000)
    [(0, 2), (0, 1)]
    rr�cSs|dS)Nrr)�xrrr�<lambda>��z_optimal_path.<locals>.<lambda>)�key)�range�lenrrr�tuple�min)rrr�memory_limitZfull_results�	iterationZiter_results�	comb_iterr!�yZcurr�costrrZconZcontr�new_input_setsrrZnew_sizeZnew_costZnew_pos�pathrrr�
_optimal_pathis4





r0cCs,t|�dkrdgSg}�xtt|�d�D]�}g}g}x>tt|��D].}x(t|dt|��D]}	|�||	f�q\WqDWxb|D]Z}
t|
||�}|\}}
}}t||�|kr�q|t||�}t||�}||f}|�||
|
g�q|Wt|�dkr�|�ttt|����Pt|dd�d�}|�|d�|d}q*W|S)a�
    Finds the path by contracting the best pair until the input list is
    exhausted. The best pair is found by minimizing the tuple
    ``(-prod(indices_removed), cost)``.  What this amounts to is prioritizing
    matrix multiplication or inner product operations, then Hadamard like
    operations, and finally outer operations. Outer products are limited by
    ``memory_limit``. This algorithm scales cubically with respect to the
    number of elements in the list ``input_sets``.

    Parameters
    ----------
    input_sets : list
        List of sets that represent the lhs side of the einsum subscript
    output_set : set
        Set that represents the rhs side of the overall einsum subscript
    idx_dict : dictionary
        Dictionary of index sizes
    memory_limit_limit : int
        The maximum number of elements in a temporary array

    Returns
    -------
    path : list
        The greedy contraction order within the memory limit constraint.

    Examples
    --------
    >>> isets = [set('abd'), set('ac'), set('bdc')]
    >>> oset = set('')
    >>> idx_sizes = {'a': 1, 'b':2, 'c':3, 'd':4}
    >>> _path__greedy_path(isets, oset, idx_sizes, 5000)
    [(0, 2), (0, 1)]
    r)rrcSs|dS)Nrr)r!rrrr"�r#z_greedy_path.<locals>.<lambda>)r$r )r&r%rrrr'r()rrrr)r/r*Ziteration_resultsr+r!r,r�contract�
idx_resultr.rrZremoved_sizer-�sortZbestrrr�_greedy_path�s2#



r4cCs�t|�dkrtd��t|dt�rx|d�dd�}dd�|dd�D�}x*|D]"}|d	kr\qN|tkrNtd
|��qNW�n@t|�}g}g}x8tt|�d�D]$}|�|�	d��|�|�	d��q�Wt|�r�|dnd}d
d�|D�}d}t|�d}xjt
|�D]^\}	}
xD|
D]<}|tk�r$|d7}n"t|t��r>|t|7}nt
d���qW|	|kr�|d7}q�W|dk	�r�|d7}xD|D]<}|tk�r�|d7}n"t|t��r�|t|7}nt
d���qxWd|k�s�d|k�r|�d�dk�p�|�d�dk}|�s|�d�dk�rtd��d|k�r"|�dd��dd��dd�}ttt|��}
d�|
�}d}d|k�rt|�d�\}}|�d�}d}n|�d�}d}x�t
|�D]�\}	}
d|
k�r�|
�d�dk�s�|
�d�dk�r�td��||	jdk�r�d}n t||	jd�}|t|
�d8}||k�r
|}|dk�rtd��n:|dk�r:|
�dd�||	<n||d�}|
�d|�||	<�q�Wd�|�}|dk�rxd}n||d�}|�r�|d|�d|�7}n�d}|�dd�}xDtt|��D]4}|tk�r�td
|��|�|�dk�r�||7}�q�Wd�tt|�t|���}|d||7}d|k�r<|�d�\}}nZ|}|�dd�}d}xDtt|��D]4}|tk�rxtd
|��|�|�dk�r^||7}�q^Wx$|D]}||k�r�td|���q�Wt|�d��t|�k�r�td��|||fS)aj
    A reproduction of einsum c side einsum parsing in python.

    Returns
    -------
    input_strings : str
        Parsed input strings
    output_string : str
        Parsed output string
    operands : list of array_like
        The operands to use in the numpy contraction

    Examples
    --------
    The operand list is simplified to reduce printing:

    >>> a = np.random.rand(4, 4)
    >>> b = np.random.rand(4, 4, 4)
    >>> __parse_einsum_input(('...a,...a->...', a, b))
    ('za,xza', 'xz', [a, b])

    >>> __parse_einsum_input((a, [Ellipsis, 0], b, [Ellipsis, 0]))
    ('za,xza', 'xz', [a, b])
    rzNo input operands� �cSsg|]}t|��qSr)r)�.0�vrrr�
<listcomp>"sz'_parse_einsum_input.<locals>.<listcomp>rNz.,->z#Character %s is not a valid symbol.r ���cSsg|]}t|��qSr)r)r7r8rrrr94sz...z=For this input type lists must contain either int or Ellipsis�,z->�-�>z%Subscripts can only contain one '->'.�.TF�zInvalid Ellipses.rzEllipses lengths do not match.z/Output character %s did not appear in the inputzDNumber of einsum subscripts must be equal to the number of operands.)r&�
ValueError�
isinstance�str�replace�einsum_symbols�listr%r�popr�Ellipsis�int�	TypeError�count�einsum_symbols_setr�join�split�shape�max�ndim�sorted)�operands�
subscripts�s�tmp_operandsZoperand_listZsubscript_list�pZoutput_listZlast�num�subZinvalidZusedZunusedZellipse_indsZlongestZ	input_tmpZ
output_subZsplit_subscriptsZout_subZ
ellipse_countZrep_indsZout_ellipse�output_subscriptZtmp_subscriptsZnormal_inds�input_subscripts�charrrr�_parse_einsum_inputs�













 










r\c5s@ddg��fdd�|��D�}t|�r2td|��|�dd�}|dkrJd}|d	krVd}d	}|dks�t|t�rnnht|�r�|d
dkr�nRt|�dkr�t|d
t�r�t|d
ttf�r�t|d
�}|d
}ntdt|���|�dd�}t|�\}}}|d|}|�	d�}	dd�|	D�}
t
|�}t
|�dd��}i�x�t|	�D]�\}
}||
j
}t|�t|�k�rntd||
|
��xPt|�D]D\}}||}|���k�r��||k�r�td||
��n|�|<�qxW�q:Wg}x$|	|gD]}|�t|����q�Wt|�}|d	k�r|}n|}t|��}|�dd�}tt|	�d
d
�}t|�tt
|���rR|d9}||9}|dk�s|t|	�dk�s|||k�r�ttt|	���g}nd|dk�r�t||�}t|
|�|�}n@|dk�r�t|
|�|�}n&|d
dk�r�|d
d	�}n
td|��ggggf\}}}}�x$t|�D�]\}}ttt|�dd��}t||
|�}|\}}
} }!t|!��}"| �rb|"d9}"|�|"�|�t|!��|�t|���g}#x|D]}$|#�|	�|$���q�W|t|�dk�r�|}%n*�fdd�|D�}&d�dd�t|&�D��}%|	�|%�d�|#�d|%}'|| |'|	d	d	�f}(|�|(��qWt|�d
})|�rJ||fS|d|}*d}+||)},t|�}-d|*}.|.dt|�7}.|.dt|�7}.|.d |7}.|.d!|)7}.|.d"|,7}.|.d#|-7}.|.d$7}.|.d%|+7}.|.d&7}.xNt|�D]B\}/}(|(\}0}1}'}2d�|2�d|}3||/|'|3f}4|.d'|47}.�q�Wdg|}||.fS)(a�
    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.
    *operands : list of array_like
        These are the arrays for the operation.
    optimize : {bool, list, tuple, 'greedy', 'optimal'}
        Choose the type of path. If a tuple is provided, the second argument is
        assumed to be the maximum intermediate size created. If only a single
        argument is provided the largest input or output array size is used
        as a maximum intermediate size.

        * if a list is given that starts with ``einsum_path``, uses this as the
          contraction path
        * if False no optimization is taken
        * if True defaults to the 'greedy' algorithm
        * 'optimal' An algorithm that combinatorially explores all possible
          ways of contracting the listed tensors and choosest the least costly
          path. Scales exponentially with the number of terms in the
          contraction.
        * 'greedy' An algorithm that chooses the best pair contraction
          at each step. Effectively, this algorithm searches the largest inner,
          Hadamard, and then outer products at each step. Scales cubically with
          the number of terms in the contraction. Equivalent to the 'optimal'
          path for most contractions.

        Default is 'greedy'.

    Returns
    -------
    path : list of tuples
        A list representation of the einsum path.
    string_repr : str
        A printable representation of the einsum path.

    Notes
    -----
    The resulting path indicates which terms of the input contraction should be
    contracted first, the result of this contraction is then appended to the
    end of the contraction list. This list can then be iterated over until all
    intermediate contractions are complete.

    See Also
    --------
    einsum, linalg.multi_dot

    Examples
    --------

    We can begin with a chain dot example. In this case, it is optimal to
    contract the ``b`` and ``c`` tensors first as reprsented by the first
    element of the path ``(1, 2)``. The resulting tensor is added to the end
    of the contraction and the remaining contraction ``(0, 1)`` is then
    completed.

    >>> a = np.random.rand(2, 2)
    >>> b = np.random.rand(2, 5)
    >>> c = np.random.rand(5, 2)
    >>> path_info = np.einsum_path('ij,jk,kl->il', a, b, c, optimize='greedy')
    >>> print(path_info[0])
    ['einsum_path', (1, 2), (0, 1)]
    >>> print(path_info[1])
      Complete contraction:  ij,jk,kl->il
             Naive scaling:  4
         Optimized scaling:  3
          Naive FLOP count:  1.600e+02
      Optimized FLOP count:  5.600e+01
       Theoretical speedup:  2.857
      Largest intermediate:  4.000e+00 elements
    -------------------------------------------------------------------------
    scaling                  current                                remaining
    -------------------------------------------------------------------------
       3                   kl,jk->jl                                ij,jl->il
       3                   jl,ij->il                                   il->il


    A more complex index transformation example.

    >>> I = np.random.rand(10, 10, 10, 10)
    >>> C = np.random.rand(10, 10)
    >>> path_info = np.einsum_path('ea,fb,abcd,gc,hd->efgh', C, C, I, C, C,
                                   optimize='greedy')

    >>> print(path_info[0])
    ['einsum_path', (0, 2), (0, 3), (0, 2), (0, 1)]
    >>> print(path_info[1])
      Complete contraction:  ea,fb,abcd,gc,hd->efgh
             Naive scaling:  8
         Optimized scaling:  5
          Naive FLOP count:  8.000e+08
      Optimized FLOP count:  8.000e+05
       Theoretical speedup:  1000.000
      Largest intermediate:  1.000e+04 elements
    --------------------------------------------------------------------------
    scaling                  current                                remaining
    --------------------------------------------------------------------------
       5               abcd,ea->bcde                      fb,gc,hd,bcde->efgh
       5               bcde,fb->cdef                         gc,hd,cdef->efgh
       5               cdef,gc->defg                            hd,defg->efgh
       5               defg,hd->efgh                               efgh->efgh
    �optimize�einsum_callcsg|]\}}|�kr|�qSrr)r7�kr8)�valid_contract_kwargsrrr9szeinsum_path.<locals>.<listcomp>z+Did not understand the following kwargs: %sFTZgreedyNrr
r rzDid not understand the path: %sz->r;cSsg|]}t|��qSr)r)r7r!rrrr9Csr6zXEinstein sum subscript %s does not contain the correct number of indices for operand %d.z@Size of label '%s' for operand %d does not match previous terms.)rr ZoptimalzPath name %s not found)�reverser:csg|]}�||f�qSrr)r7r)�dimension_dictrrr9�scSsg|]}|d�qS)rr)r7r!rrrr9�s)ZscalingZcurrentrz  Complete contraction:  %s
z         Naive scaling:  %d
z     Optimized scaling:  %d
z      Naive FLOP count:  %.3e
z  Optimized FLOP count:  %.3e
z   Theoretical speedup:  %3.3f
z'  Largest intermediate:  %.3e elements
zK--------------------------------------------------------------------------
z%6s %24s %40s
zJ--------------------------------------------------------------------------z
%4d    %24s %40s)�itemsr&rIrFrArBrH�floatr\rMrrCrrNr@�keysrrrOr'r%r(r4r0�KeyErrorrQrErrL�sum)5rR�kwargs�unknown_kwargs�	path_typer)Zeinsum_call_argrZrYrSZ
input_listrrr
ZtnumZtermZshZcnumr[ZdimZ	size_listZmax_sizeZ
memory_argZ
naive_costZindices_in_inputZmultr/Z	cost_listZ
scale_list�contraction_listZ
contract_indsr1Zout_indsrrr-Z
tmp_inputsr!r2Zsort_result�
einsum_str�contractionZopt_costZoverall_contraction�headerZspeedupZmax_iZ
path_print�n�inds�idx_rmrZ
remaining_strZpath_runr)rbr`rr
�s�n





"








cs<|�dd�}|dkrt||�Sddddg��fdd�|��D�}dg���fd	d
�|��D�}t|�rttd|��d}|�dd�}|dk	r�d
}t||d
d��\}}x�t|�D]t\}}	|	\}
}}}
g}x|
D]}|�|�|��q�W|�r|dt|�k�r||d<t|f|�|�}|�|�~~q�W|�r0|S|dSdS)aM!
    einsum(subscripts, *operands, out=None, dtype=None, order='K',
           casting='safe', optimize=False)

    Evaluates the Einstein summation convention on the operands.

    Using the Einstein summation convention, many common multi-dimensional
    array operations can be represented in a simple fashion.  This function
    provides a way to compute such summations. The best way to understand this
    function is to try the examples below, which show how many common NumPy
    functions can be implemented as calls to `einsum`.

    Parameters
    ----------
    subscripts : str
        Specifies the subscripts for summation.
    operands : list of array_like
        These are the arrays for the operation.
    out : {ndarray, None}, optional
        If provided, the calculation is done into this array.
    dtype : {data-type, None}, optional
        If provided, forces the calculation to use the data type specified.
        Note that you may have to also give a more liberal `casting`
        parameter to allow the conversions. Default is None.
    order : {'C', 'F', 'A', 'K'}, optional
        Controls the memory layout of the output. 'C' means it should
        be C contiguous. 'F' means it should be Fortran contiguous,
        'A' means it should be 'F' if the inputs are all 'F', 'C' otherwise.
        'K' means it should be as close to the layout as the inputs as
        is possible, including arbitrarily permuted axes.
        Default is 'K'.
    casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
        Controls what kind of data casting may occur.  Setting this to
        'unsafe' is not recommended, as it can adversely affect accumulations.

          * 'no' means the data types should not be cast at all.
          * 'equiv' means only byte-order changes are allowed.
          * 'safe' means only casts which can preserve values are allowed.
          * 'same_kind' means only safe casts or casts within a kind,
            like float64 to float32, are allowed.
          * 'unsafe' means any data conversions may be done.

        Default is 'safe'.
    optimize : {False, True, 'greedy', 'optimal'}, optional
        Controls if intermediate optimization should occur. No optimization
        will occur if False and True will default to the 'greedy' algorithm.
        Also accepts an explicit contraction list from the ``np.einsum_path``
        function. See ``np.einsum_path`` for more details. Default is False.

    Returns
    -------
    output : ndarray
        The calculation based on the Einstein summation convention.

    See Also
    --------
    einsum_path, dot, inner, outer, tensordot, linalg.multi_dot

    Notes
    -----
    .. versionadded:: 1.6.0

    The subscripts string is a comma-separated list of subscript labels,
    where each label refers to a dimension of the corresponding operand.
    Repeated subscripts labels in one operand take the diagonal.  For example,
    ``np.einsum('ii', a)`` is equivalent to ``np.trace(a)``.

    Whenever a label is repeated, it is summed, so ``np.einsum('i,i', a, b)``
    is equivalent to ``np.inner(a,b)``.  If a label appears only once,
    it is not summed, so ``np.einsum('i', a)`` produces a view of ``a``
    with no changes.

    The order of labels in the output is by default alphabetical.  This
    means that ``np.einsum('ij', a)`` doesn't affect a 2D array, while
    ``np.einsum('ji', a)`` takes its transpose.

    The output can be controlled by specifying output subscript labels
    as well.  This specifies the label order, and allows summing to
    be disallowed or forced when desired.  The call ``np.einsum('i->', a)``
    is like ``np.sum(a, axis=-1)``, and ``np.einsum('ii->i', a)``
    is like ``np.diag(a)``.  The difference is that `einsum` does not
    allow broadcasting by default.

    To enable and control broadcasting, use an ellipsis.  Default
    NumPy-style broadcasting is done by adding an ellipsis
    to the left of each term, like ``np.einsum('...ii->...i', a)``.
    To take the trace along the first and last axes,
    you can do ``np.einsum('i...i', a)``, or to do a matrix-matrix
    product with the left-most indices instead of rightmost, you can do
    ``np.einsum('ij...,jk...->ik...', a, b)``.

    When there is only one operand, no axes are summed, and no output
    parameter is provided, a view into the operand is returned instead
    of a new array.  Thus, taking the diagonal as ``np.einsum('ii->i', a)``
    produces a view.

    An alternative way to provide the subscripts and operands is as
    ``einsum(op0, sublist0, op1, sublist1, ..., [sublistout])``. The examples
    below have corresponding `einsum` calls with the two parameter methods.

    .. versionadded:: 1.10.0

    Views returned from einsum are now writeable whenever the input array
    is writeable. For example, ``np.einsum('ijk...->kji...', a)`` will now
    have the same effect as ``np.swapaxes(a, 0, 2)`` and
    ``np.einsum('ii->i', a)`` will return a writeable view of the diagonal
    of a 2D array.

    .. versionadded:: 1.12.0

    Added the ``optimize`` argument which will optimize the contraction order
    of an einsum expression. For a contraction with three or more operands this
    can greatly increase the computational efficiency at the cost of a larger
    memory footprint during computation.

    See ``np.einsum_path`` for more details.

    Examples
    --------
    >>> a = np.arange(25).reshape(5,5)
    >>> b = np.arange(5)
    >>> c = np.arange(6).reshape(2,3)

    >>> np.einsum('ii', a)
    60
    >>> np.einsum(a, [0,0])
    60
    >>> np.trace(a)
    60

    >>> np.einsum('ii->i', a)
    array([ 0,  6, 12, 18, 24])
    >>> np.einsum(a, [0,0], [0])
    array([ 0,  6, 12, 18, 24])
    >>> np.diag(a)
    array([ 0,  6, 12, 18, 24])

    >>> np.einsum('ij,j', a, b)
    array([ 30,  80, 130, 180, 230])
    >>> np.einsum(a, [0,1], b, [1])
    array([ 30,  80, 130, 180, 230])
    >>> np.dot(a, b)
    array([ 30,  80, 130, 180, 230])
    >>> np.einsum('...j,j', a, b)
    array([ 30,  80, 130, 180, 230])

    >>> np.einsum('ji', c)
    array([[0, 3],
           [1, 4],
           [2, 5]])
    >>> np.einsum(c, [1,0])
    array([[0, 3],
           [1, 4],
           [2, 5]])
    >>> c.T
    array([[0, 3],
           [1, 4],
           [2, 5]])

    >>> np.einsum('..., ...', 3, c)
    array([[ 0,  3,  6],
           [ 9, 12, 15]])
    >>> np.einsum(',ij', 3, C)
    array([[ 0,  3,  6],
           [ 9, 12, 15]])
    >>> np.einsum(3, [Ellipsis], c, [Ellipsis])
    array([[ 0,  3,  6],
           [ 9, 12, 15]])
    >>> np.multiply(3, c)
    array([[ 0,  3,  6],
           [ 9, 12, 15]])

    >>> np.einsum('i,i', b, b)
    30
    >>> np.einsum(b, [0], b, [0])
    30
    >>> np.inner(b,b)
    30

    >>> np.einsum('i,j', np.arange(2)+1, b)
    array([[0, 1, 2, 3, 4],
           [0, 2, 4, 6, 8]])
    >>> np.einsum(np.arange(2)+1, [0], b, [1])
    array([[0, 1, 2, 3, 4],
           [0, 2, 4, 6, 8]])
    >>> np.outer(np.arange(2)+1, b)
    array([[0, 1, 2, 3, 4],
           [0, 2, 4, 6, 8]])

    >>> np.einsum('i...->...', a)
    array([50, 55, 60, 65, 70])
    >>> np.einsum(a, [0,Ellipsis], [Ellipsis])
    array([50, 55, 60, 65, 70])
    >>> np.sum(a, axis=0)
    array([50, 55, 60, 65, 70])

    >>> a = np.arange(60.).reshape(3,4,5)
    >>> b = np.arange(24.).reshape(4,3,2)
    >>> np.einsum('ijk,jil->kl', a, b)
    array([[ 4400.,  4730.],
           [ 4532.,  4874.],
           [ 4664.,  5018.],
           [ 4796.,  5162.],
           [ 4928.,  5306.]])
    >>> np.einsum(a, [0,1,2], b, [1,0,3], [2,3])
    array([[ 4400.,  4730.],
           [ 4532.,  4874.],
           [ 4664.,  5018.],
           [ 4796.,  5162.],
           [ 4928.,  5306.]])
    >>> np.tensordot(a,b, axes=([1,0],[0,1]))
    array([[ 4400.,  4730.],
           [ 4532.,  4874.],
           [ 4664.,  5018.],
           [ 4796.,  5162.],
           [ 4928.,  5306.]])

    >>> a = np.arange(6).reshape((3,2))
    >>> b = np.arange(12).reshape((4,3))
    >>> np.einsum('ki,jk->ij', a, b)
    array([[10, 28, 46, 64],
           [13, 40, 67, 94]])
    >>> np.einsum('ki,...k->i...', a, b)
    array([[10, 28, 46, 64],
           [13, 40, 67, 94]])
    >>> np.einsum('k...,jk', a, b)
    array([[10, 28, 46, 64],
           [13, 40, 67, 94]])

    >>> # since version 1.10.0
    >>> a = np.zeros((3, 3))
    >>> np.einsum('ii->i', a)[:] = 1
    >>> a
    array([[ 1.,  0.,  0.],
           [ 0.,  1.,  0.],
           [ 0.,  0.,  1.]])

    r]F�outZdtype�orderZcastingcsi|]\}}|�kr||�qSrr)r7r_r8)�valid_einsum_kwargsrr�
<dictcomp>�szeinsum.<locals>.<dictcomp>csg|]\}}|�kr|�qSrr)r7r_r8)r`rrr9�szeinsum.<locals>.<listcomp>z+Did not understand the following kwargs: %sNT)r]r^rr)rFrrcr&rIr
rr)rRrhZoptimize_argZ
einsum_kwargsriZ
specified_outZ	out_arrayrkrWrmrprqrlrrUr!Znew_viewr)r`rtrr	�s<r



N)�__doc__Z
__future__rrrZnumpy.core.multiarrayrZnumpy.core.numericrrr�__all__rDrrKrrr0r4r\r
r	rrrr�<module>s <KO)