§
    %P„j®  ã                   ó´  — d Z ddlmZmZmZmZmZmZmZm	Z	 ddl
mZmZ g d¢ZdZg d¢Z e eee¦  «        ¦  «        Ze	dee         dee         d	efd
„¦   «         Ze	dee         deeef         d	efd„¦   «         Zdeded	efd„Zdee         dee         ded	eee         ee         eef         fd„Zdee         dededeeef         d	ef
d„Zded	efd„ZdS )z9Contains helper functions for opt_einsum testing scripts.é    )ÚAnyÚ
CollectionÚDictÚ	FrozenSetÚIterableÚListÚTupleÚoverload)ÚArrayIndexTypeÚ	ArrayType)Úcompute_size_by_dictÚfind_contractionÚ
flop_countÚabcdefghijklmopqABC)é   é   é   é   r   r   r   é   r   r   r   r   r   é   r   r   r   r   r   ÚindicesÚidx_dictÚreturnc                 ó   — d S ©N© ©r   r   s     úW/root/disk_3tb/conda_envs/Huy-visual/lib/python3.11/site-packages/opt_einsum/helpers.pyr   r      s   € ØNQÈcó    c                 ó   — d S r   r   r   s     r   r   r      s   € ØUXÐUXr   c                 ó*   — d}| D ]}|||         z  }Œ|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   r   ÚretÚis       r   r   r      s-   € ð, €CØð ð ˆØˆx˜Œ{ÑˆˆØ€Jr   Ú	positionsÚ
input_setsÚ
output_setc                 óÖ   ‡— t          |¦  «        Šˆfd„t          | d¬¦  «        D ¦   «         }t          j        |Ž } |j        ‰Ž }||z  }||z
  }‰                     |¦  «         |‰||fS )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'})
    c              3   óB   •K  — | ]}‰                      |¦  «        V — Œd S r   )Úpop)Ú.0r$   Ú	remainings     €r   ú	<genexpr>z#find_contraction.<locals>.<genexpr>_   s/   øè è € ÐHÐH 1ˆi�mŠm˜AÑÔÐHÐHÐHÐHÐHÐHr   T)Úreverse)ÚlistÚsortedÚ	frozensetÚunionÚappend)	r%   r&   r'   ÚinputsÚidx_contractÚ
idx_remainÚ
new_resultÚidx_removedr,   s	           @r   r   r   2   s‹   ø€ õX �ZÑ Ô €IØHÐHÐHÐH­¨yÀ$Ð(GÑ(GÔ(GÐHÑHÔH€FÝ”? FÐ+€LØ!�Ô! 9Ð-€Jà˜lÑ*€JØ Ñ+€KØ×Ò�ZÑ Ô Ð à�y +¨|Ð;Ð;r   Úidx_contractionÚinnerÚ	num_termsÚsize_dictionaryc                 ó`   — t          | |¦  «        }t          d|dz
  ¦  «        }|r|dz  }||z  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

    r"   )r   Úmax)r9   r:   r;   r<   Úoverall_sizeÚ	op_factors         r   r   r   j   sC   € õB (¨¸ÑIÔI€LÝ�A�y 1‘}Ñ%Ô%€IØð Ø�Q‰ˆ	à˜)Ñ#Ð#r   Úarrayc                 ó*   — t          | d¦  «        rdS dS )NÚ__array_interface__TF)Úhasattr)rA   s    r   Úhas_array_interfacerE   “   s   € ÝˆuÐ+Ñ,Ô,ð Øˆtàˆur   N)Ú__doc__Útypingr   r   r   r   r   r   r	   r
   Úopt_einsum.typingr   r   Ú__all__Ú_valid_charsÚ_sizesÚdictÚzipÚ_default_dim_dictÚintr   Ústrr   Úboolr   rE   r   r   r   ú<module>rR      sö  ðØ ?Ð ?à TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ Tà 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7à
DÐ
DÐ
D€à$€Ø	BÐ	BÐ	B€Ø�D˜˜˜\¨6Ñ2Ô2Ñ3Ô3Ð ð 
Ø Q (¨3¤-Ð Q¸4À¼9Ð QÈÐ QÐ QÐ Qñ 
„Ø Qð 
Ø X *¨S¤/Ð X¸TÀ#ÀsÀ(¼^Ð XÐPSÐ XÐ XÐ Xñ 
„Ø Xð #ð °ð ¸ð ð ð ð ð85<Ø˜#Œð5<à�^Ô$ð5<ð ð5<ð ˆ9�SŒ>˜4 Ô/°ÀÐOÔPð	5<ð 5<ð 5<ð 5<ðp&$Ø ”_ð&$àð&$ð ð&$ð ˜#˜s˜(”^ð	&$ð
 	ð&$ð &$ð &$ð &$ðR˜yð ¨Yð ð ð ð ð ð r   