Ë
    Gìj®  ã                   óX  — 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y)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                  ó   — y ©N© ©r   r   s     úVC:\Users\Stabi\Downloads\virtual-tryon(1)\venv\Lib\site-packages\opt_einsum/helpers.pyr   r      s   € ØNQó    c                  ó   — y r   r   r   s     r   r   r      s   € Ø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
  }‰j	                  |«       |‰||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   ó@   •K  — | ]  }‰j                  |«      –— Œ y ­wr   )Úpop)Ú.0r$   Ú	remainings     €r   Ú	<genexpr>z#find_contraction.<locals>.<genexpr>_   s   øè ø€ ÐHÑ(G 1ˆi�m‰m˜A×Ñ(Gùs   ƒT)Úreverse)ÚlistÚsortedÚ	frozensetÚunionÚappend)	r%   r&   r'   ÚinputsÚidx_contractÚ
idx_remainÚ
new_resultÚidx_removedr,   s	           @r   r   r   2   sr   ø€ ôX �ZÓ €IÛH¬¨yÀ$Õ(GÓH€FÜ—?‘? FÐ+€LØ!�×!Ñ! 9Ð-€Jà˜lÑ*€JØ Ñ+€KØ×Ñ�ZÔ à�y +¨|Ð;Ð;r   Úidx_contractionÚinnerÚ	num_termsÚsize_dictionaryc                 óP   — 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   s8   € ôB (¨¸ÓI€LÜ�A�y 1‘}Ó%€IÙØ�Q‰ˆ	à˜)Ñ#Ð#r   Úarrayc                 ó   — t        | d«      ryy)NÚ__array_interface__TF)Úhasattr)rA   s    r   Úhas_array_interfacerE   “   s   € ÜˆuÐ+Ô,Øàr   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ç 7â
D€à$€Ú	B€Ù™˜\¨6Ó2Ó3Ð ð 
Ø Q (¨3¡-Ð Q¸4À¹9Ð QÈÒ Qó 
Ø Qð 
Ø X *¨S¡/Ð X¸TÀ#ÀsÀ(¹^Ð XÐPSÒ Xó 
Ø Xð #ð °ð ¸ó ð85<Ø˜#‰ð5<à�^Ñ$ð5<ð ð5<ð ˆ9�S‰>˜4 Ñ/°ÀÐOÑPó	5<ðp&$Ø ‘_ð&$àð&$ð ð&$ð ˜#˜s˜(‘^ð	&$ð
 	ó&$ðR˜yð ¨Yô r   