File: //home/arjun/.local/lib/python3.10/site-packages/numpy/core/__pycache__/einsumfunc.cpython-310.pyc
o
���g�� � @ s� d Z ddlZddlZddlmZ ddlmZmZ ddlm Z ddgZ
dZee�Z
d d
� Zdd� Zd
d� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zddd�dd�Ze edd�d d!d�d"d��Zddd#�d$d%�Ze edd�dd!d#�d&d��ZdS )'z&
Implementation of optimized einsum.
� N)�c_einsum)�
asanyarray� tensordot)�array_function_dispatch�einsum�einsum_path�4abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZc C s, t | |�}td|d �}|r|d7 }|| S )a�
Computes the number of FLOPS in the contraction.
Parameters
----------
idx_contraction : iterable
The indices involved in the contraction
inner : bool
Does this contraction require an inner product?
num_terms : int
The number of terms in a contraction
size_dictionary : dict
The size of each of the indices in idx_contraction
Returns
-------
flop_count : int
The total number of FLOPS required for the contraction.
Examples
--------
>>> _flop_count('abc', False, 1, {'a': 2, 'b':3, 'c':5})
30
>>> _flop_count('abc', True, 2, {'a': 2, 'b':3, 'c':5})
60
� )�_compute_size_by_dict�max)�idx_contraction�inner� num_terms�size_dictionary�overall_size� op_factor� r �H/home/arjun/.local/lib/python3.10/site-packages/numpy/core/einsumfunc.py�_flop_count s
r c C s d}| D ]}||| 9 }q|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
r r )�indices�idx_dict�ret�ir r r r
8 s r
c
C sn t � }|�� }g }t|�D ]\}}|| v r||O }q
|�|� ||O }q
||@ }|| } |�|� ||| |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_contract�
idx_remain� remaining�ind�value�
new_result�idx_removedr r r �_find_contractionU s +
r'