Ë
    GìjÕ3  ã                   ó�  — d Z ddlZddlmZmZmZmZmZmZ ddl	m
Z
mZ g d¢ZdZdedefd	„Zd
edefd„Zdedefd„Zdededee   fd„Zd
edefd„Zdedefd„Zdedefd„Zdee   dee   dedefd„ZeeeeeefZdedefd„Zdedefd„Zdee   deeef   defd„Zdee   deeeed f   f   fd!„Z d#dededeeeee
   f   fd"„Z!y)$zBA functionally equivalent parser of the numpy.einsum input parser.é    N)ÚAnyÚDictÚIteratorÚListÚSequenceÚTuple)Ú	ArrayTypeÚTensorShapeType)Úis_valid_einsum_charÚhas_valid_einsum_chars_onlyÚ
get_symbolÚ	get_shapeÚgen_unused_symbolsÚconvert_to_valid_einsum_charsÚalpha_canonicalizeÚfind_output_strÚfind_output_shapeÚpossibly_convert_to_numpyÚparse_einsum_inputÚ4abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZÚxÚreturnc                 ó   — | t         v xs | dv S )u½   Check if the character ``x`` is valid for numpy einsum.

    **Examples:**

    ```python
    is_valid_einsum_char("a")
    #> True

    is_valid_einsum_char("Ç´")
    #> False
    ```
    z,->.)Ú_einsum_symbols_base)r   s    úUC:\Users\Stabi\Downloads\virtual-tryon(1)\venv\Lib\site-packages\opt_einsum/parser.pyr   r      s   € ð Ô%Ð%Ò7¨1°¨;Ð7ó    Ú
einsum_strc                 ó4   — t        t        t        | «      «      S )uâ   Check if ``einsum_str`` contains only valid characters for numpy einsum.

    **Examples:**

    ```python
    has_valid_einsum_chars_only("abAZ")
    #> True

    has_valid_einsum_chars_only("Ã–ver")
    #> False
    ```
    )ÚallÚmapr   )r   s    r   r   r   )   s   € ô ŒsÔ'¨Ó4Ó5Ð5r   Úic                 ó`   — | dk  r	t         |    S | dk\  rt        | dz   «      S t        | dz   «      S )u<  Get the symbol corresponding to int ``i`` - runs through the usual 52
    letters before resorting to unicode characters, starting at ``chr(192)`` and skipping surrogates.

    **Examples:**

    ```python
    get_symbol(2)
    #> 'c'

    get_symbol(200)
    #> 'Å”'

    get_symbol(20000)
    #> 'äº¬'
    ```
    é4   i Ø  i   éŒ   )r   Úchr)r!   s    r   r   r   9   s9   € ð" 	ˆ2‚vÜ# AÑ&Ð&Ø	
ˆeŠä�1�t‘8‹}Ðä�1�s‘7‹|Ðr   ÚusedÚnc              #   óh   K  — dx}}||k  r%t        |«      }|dz  }|| v rŒ|–— |dz  }||k  rŒ$yy­w)z©Generate ``n`` symbols that are not already in ``used``.

    **Examples:**
    ```python
    list(oe.parser.gen_unused_symbols("abd", 2))
    #> ['c', 'e']
    ```
    r   é   N)r   )r&   r'   r!   ÚcntÚss        r   r   r   S   sK   è ø€ ð €K€AˆØ
�Š'Ü�q‹MˆØ	ˆQ‰ˆØ�‰9ØØŠØˆq‰ˆð ��'ùs   ‚-2°2c                 óÔ   ‡— t        t        | «      t        d«      z
  «      }t        |«      D ��ci c]  \  }}|t        |«      “Œ c}}Šdj	                  ˆfd„| D «       «      S c c}}w )u  Convert the str ``einsum_str`` to contain only the alphabetic characters
    valid for numpy einsum. If there are too many symbols, let the backend
    throw an error.

    Examples:
    --------
    >>> oe.parser.convert_to_valid_einsum_chars("Ä¤Ä›Ä¼Ä¼Ã¶")
    'cbdda'
    z,->Ú c              3   óB   •K  — | ]  }‰j                  ||«      –— Œ y ­w©N©Úget)Ú.0r   Úreplacers     €r   Ú	<genexpr>z0convert_to_valid_einsum_chars.<locals>.<genexpr>r   s   øè ø€ Ð:©z¨!�8—<‘<  1×%©zùó   ƒ)ÚsortedÚsetÚ	enumerater   Újoin)r   Úsymbolsr!   r   r3   s       @r   r   r   f   s_   ø€ ô ”S˜“_¤s¨5£zÑ1Ó2€GÜ-6°wÔ-?Ô@Ñ-?¡T Q¨�”:˜a“=Ñ Ð-?Ò@€HØ�7‰7Ó:©zÓ:Ó:Ð:ùó As   °A$Úequationc                 óŒ   ‡— i Š| D ]#  }|dv rŒ|‰vsŒt        t        ‰«      «      ‰|<   Œ% dj                  ˆfd„| D «       «      S )uÙ   Alpha convert an equation in an order-independent canonical way.

    Examples:
    --------
    >>> oe.parser.alpha_canonicalize("dcba")
    'abcd'

    >>> oe.parser.alpha_canonicalize("Ä¤Ä›Ä¼Ä¼Ã¶")
    'abccd'
    z.,->r-   c              3   óB   •K  — | ]  }‰j                  ||«      –— Œ y ­wr/   r0   )r2   r   Úrenames     €r   r4   z%alpha_canonicalize.<locals>.<genexpr>†   s   øè ø€ Ð6©X¨�6—:‘:˜a ×#©Xùr5   )r   Úlenr9   )r;   Únamer>   s     @r   r   r   u   sO   ø€ ð  €FÛˆØ�6‰>ØØ�vÒÜ%¤c¨&£kÓ2ˆF�4ŠLð	 ð
 �7‰7Ó6©XÓ6Ó6Ð6r   Ú
subscriptsc                 ó€   ‡— | j                  dd«      Šdj                  ˆfd„t        t        ‰«      «      D «       «      S )aU  Find the output string for the inputs ``subscripts`` under canonical einstein summation rules.
    That is, repeated indices are summed over by default.

    Examples:
    --------
    >>> oe.parser.find_output_str("ab,bc")
    'ac'

    >>> oe.parser.find_output_str("a,b")
    'ab'

    >>> oe.parser.find_output_str("a,a,b,b")
    ''
    Ú,r-   c              3   óL   •K  — | ]  }‰j                  |«      d k(  sŒ|–— Œ y­w)r)   N)Úcount)r2   r+   Útmp_subscriptss     €r   r4   z"find_output_str.<locals>.<genexpr>™   s(   øè ø€ ÐZÑ9˜¸^×=QÑ=QÐRSÓ=TÐXYÓ=Y”1Ñ9ùs   ƒ$�$)Úreplacer9   r6   r7   )rA   rF   s    @r   r   r   ‰   s6   ø€ ð  ×'Ñ'¨¨RÓ0€NØ�7‰7ÓZœf¤S¨Ó%8Ô9ÓZÓZÐZr   ÚinputsÚshapesÚoutputc                 ó0   ‡ ‡— t        ˆ ˆfd„|D «       «      S )aP  Find the output shape for given inputs, shapes and output string, taking
    into account broadcasting.

    Examples:
    --------
    >>> oe.parser.find_output_shape(["ab", "bc"], [(2, 3), (3, 4)], "ac")
    (2, 4)

    # Broadcasting is accounted for
    >>> oe.parser.find_output_shape(["a", "a"], [(4, ), (1, )], "a")
    (4,)
    c              3   óš   •K  — | ]=  }t        d „ t        ‰‰D �cg c]  }|j                  |«      ‘Œ c}«      D «       «      –— Œ? yc c}w ­w)c              3   ó8   K  — | ]  \  }}|d k\  sŒ||   –— Œ y­w)r   N© )r2   ÚshapeÚlocs      r   r4   z.find_output_shape.<locals>.<genexpr>.<genexpr>©   s$   è ø€ ÐgÑ2Z¡J E¨3Ð^aÐefÓ^f�U˜3•ZÑ2Zùs   ‚�
N)ÚmaxÚzipÚfind)r2   Úcr   rH   rI   s      €€r   r4   z$find_output_shape.<locals>.<genexpr>©   sD   øè ø€ ÐxÑqwÐlm”Ñg´#°fÑRXÓ>YÑRXÈQ¸q¿v¹vÀa½yÐRXÑ>YÔ2ZÓg×gÑqwùÒ>Yùs   ƒA™A±A)Útuple)rH   rI   rJ   s   `` r   r   r   œ   s   ù€ ô ÔxÑqwÓxÓxÐxr   c                 ól  — t        | d«      r| j                  S t        | t        «      ryt        | t        «      rmg }t        | t        «      rPt        | t        «      s@|j                  t        | «      «       | d   } t        | t        «      rt        | t        «      sŒ@t        |«      S t        d| › d�«      ‚)a  Get the shape of the array-like object `x`. If `x` is not array-like, raise an error.

    Array-like objects are those that have a `shape` attribute, are sequences of BaseTypes, or are BaseTypes.
    BaseTypes are defined as `bool`, `int`, `float`, `complex`, `str`, and `bytes`.
    rO   rN   r   zCannot determine the shape of z5, can only determine the shape of array-like objects.)	ÚhasattrrO   Ú
isinstanceÚ
_BaseTypesr   Úappendr?   rU   Ú
ValueError)r   rO   s     r   r   r   ¯   s–   € ô ˆq�'ÔØ�w‰wˆÜ	�A”zÔ	"ØÜ	�A”xÔ	 ØˆÜ˜œHÔ%¬j¸¼JÔ.GØ�L‰Lœ˜Q›Ô Ø�!‘ˆAô ˜œHÔ%¬j¸¼JÕ.Gô �U‹|ÐäÐ9¸!¸Ð<qÐrÓsÐsr   c                 óz   — t        | d«      s	 ddl}|j                  | «      S | S # t        $ r t        d«      ‚w xY w)aU  Convert things without a 'shape' to ndarrays, but leave everything else.

    Examples:
    --------
    >>> oe.parser.possibly_convert_to_numpy(5)
    array(5)

    >>> oe.parser.possibly_convert_to_numpy([5, 3])
    array([5, 3])

    >>> oe.parser.possibly_convert_to_numpy(np.array([5, 3]))
    array([5, 3])

    # Any class with a shape is passed through
    >>> class Shape:
    ...     def __init__(self, shape):
    ...         self.shape = shape
    ...

    >>> myshape = Shape((5, 5))
    >>> oe.parser.possibly_convert_to_numpy(myshape)
    <__main__.Shape object at 0x10f850710>
    rO   r   Nzinumpy is required to convert non-array objects to arrays. This function will be deprecated in the future.)rW   ÚnumpyÚModuleNotFoundErrorÚ
asanyarray)r   Únps     r   r   r   Ã   sM   € ô0 �1�gÔð	Ûð �}‰}˜QÓÐàˆøô #ò 	Ü%Ø{óð ð	ús   Ž% ¥:Úold_subÚ
symbol_mapc                 óD   — d}| D ]  }|t         u r|dz  }Œ|||   z  }Œ |S )a  Convert user custom subscripts list to subscript string according to `symbol_map`.

    Examples:
    --------
    >>>  oe.parser.convert_subscripts(['abc', 'def'], {'abc':'a', 'def':'b'})
    'ab'
    >>> oe.parser.convert_subscripts([Ellipsis, object], {object:'a'})
    '...a'
    r-   ú...)ÚEllipsis)ra   rb   Únew_subr+   s       r   Úconvert_subscriptsrg   è   s;   € ð €GÛˆØ”‰=Ø�uÑ‰Gð �z !‘}Ñ$‰Gð ð €Nr   Úoperands.c                 ó’  ‡
— t        | «      }g }g }t        t        | «      dz  «      D ]B  }|j                  |j	                  d«      «       |j                  |j	                  d«      «       ŒD t        |«      r|d   nd}	 t        t        j                  j                  |«      «      }|j                  t        «       t        t        |«      «      D ��ci c]  \  }}|t        |«      “Œ c}}Š
dj                  ˆ
fd„|D «       «      }	|�|	dz  }	|	t!        |‰
«      z  }	|	t#        |«      fS c c}}w # t        $ r t        d«      ‚w xY w)	z5Convert 'interleaved' input to standard einsum input.é   r   éÿÿÿÿNziFor this input type lists must contain either Ellipsis or hashable and comparable object (e.g. int, str).rC   c              3   ó6   •K  — | ]  }t        |‰«      –— Œ y ­wr/   )rg   )r2   Úsubrb   s     €r   r4   z,convert_interleaved_input.<locals>.<genexpr>  s   øè ø€ ÐXÉÀ#Ô,¨S°*×=Éùs   ƒú->)ÚlistÚranger?   rZ   Úpopr7   Ú	itertoolsÚchainÚfrom_iterableÚdiscardre   r8   r6   r   Ú	TypeErrorr9   rg   rU   )rh   Útmp_operandsÚoperand_listÚsubscript_listÚ_Úoutput_listÚ
symbol_setÚidxÚsymbolrA   rb   s             @r   Úconvert_interleaved_inputr   ü   sE  ø€ ä˜“>€LØ€LØ€NÜ”3�x“= AÑ%Ö&ˆØ×Ñ˜L×,Ñ,¨QÓ/Ô0Ø×Ñ˜l×.Ñ.¨qÓ1Õ2ð 'ô '*¨,Ô&7�,˜rÒ"¸T€Kð
äœŸ™×6Ñ6°~ÓFÓGˆ
ð 	×Ñœ8Ô$ô BKÌ6ÐR\ÓK]ÔA^Ô_ÑA^±+°#°v�fœj¨›oÑ-ÐA^Ò_ˆ
ð —‘ÓXÉÓXÓX€JØÐØ�dÑˆ
ØÔ(¨°jÓAÑAˆ
à”u˜\Ó*Ð*Ð*ùó `øäò 
ÜðAó
ð 	
ð
ús   Â AD1 ÃD+Ã*D1 Ä+D1 Ä1Ec           	      ó0  — t        | «      dk(  rt        d«      ‚t        | d   t        «      r=| d   j	                  dd«      }|r t        d„ | dd D «       «      rt        d«      ‚| dd } nt        | «      \  }} |r| }n| D �cg c]  }t        |«      ‘Œ }}d	|v sd
|v rK|j                  d	«      dkD  xs |j                  d
«      dkD  }|s|j                  d«      dk7  rt        d«      ‚d|v �rå|j	                  dd«      j	                  dd«      j	                  dd«      }dj                  t        |t        d„ |D «       «      «      «      }d}d|v r(|j                  d«      \  }	}
|	j                  d«      }d}n|j                  d«      }d}t        |«      D ]º  \  }}d|v sŒ|j                  d«      dk7  s|j                  d«      dk7  rt        d«      ‚||   dk(  rd}n't        t        ||   «      d«      t        |«      dz
  z
  }||kD  r|}|dk  rt        d«      ‚|dk(  r|j	                  dd«      ||<   Œ¢|j	                  d|| d «      ||<   Œ¼ dj                  |«      }|dk(  rd}n|| d }|r|d
j	                  d|«      z   z  }nEt        |«      }dj                  t        t!        |«      t!        |«      z
  «      «      }|d|z   |z   z  }d|v r|j                  d«      \  }}n|t        |«      }}|D ]8  }|j                  |«      dk7  rt        d|› d�«      ‚||vsŒ+t        d|› d�«      ‚ t        |j                  d«      «      t        | «      k7  r3t        dt        |j                  d«      «      › dt        | «      › d�«      ‚||| fS c c}w )ay  A reproduction of einsum c side einsum parsing in python.

    Parameters:
        operands: Intakes the same inputs as `contract_path`, but NOT the keyword args. The only
            supported keyword argument is:
        shapes: Whether ``parse_einsum_input`` should assume arrays (the default) or
            array shapes have been supplied.

    Returns:
        input_strings: Parsed input strings
        output_string: Parsed output string
        operands: The operands to use in the numpy contraction

    Examples:
        The operand list is simplified to reduce printing:

        ```python
        >>> 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])
        ```
    r   zNo input operandsÚ r-   c              3   ó4   K  — | ]  }t        |d «      –— Œ y­w)rO   N)rW   )r2   Úos     r   r4   z%parse_einsum_input.<locals>.<genexpr>B  s   è ø€ Ð=±¨1”7˜1˜g×&±ùs   ‚r)   Nzwshapes is set to True but given at least one operand looks like an array (at least one operand has a shape attribute). Ú-Ú>rn   z%Subscripts can only contain one '->'.Ú.rC   c              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr/   )r?   )r2   r   s     r   r4   z%parse_einsum_input.<locals>.<genexpr>Y  s   è ø€ Ð;[ÉNÀq¼CÀ¿FÉNùs   ‚TFé   rd   zInvalid Ellipses.rN   zEllipses lengths do not match.zOutput character 'z(' appeared more than once in the output.z' did not appear in the inputzNumber of einsum subscripts, z+, must be equal to the number of operands, )r?   r[   rX   ÚstrrG   Úanyr   r   rE   r9   r   rQ   Úsplitr8   r   r6   r7   )rh   rI   rA   Úoperand_shapesrƒ   Úinvalidr&   Úellipse_indsÚlongestÚ	input_tmpÚ
output_subÚsplit_subscriptsÚout_subÚnumrm   Úellipse_countÚout_ellipseÚoutput_subscriptÚnormal_indsÚinput_subscriptsÚchars                        r   r   r   !  s
  € ô6 ˆ8ƒ}˜ÒÜÐ,Ó-Ð-ä�(˜1‘+œsÔ#Ø˜a‘[×(Ñ(¨¨bÓ1ˆ
ÙÜÑ=°¸¸±Ó=Ô=Ü ðFóð ð ˜A˜B�<‰ä8¸ÓBÑˆ
�HáØ!‰á08Ó9±¨1œ) A�,°ˆÐ9ð 	ˆzÑ˜s jÑ0Ø×#Ñ# CÓ(¨1Ñ,ÒL°*×2BÑ2BÀ3Ó2GÈ!Ñ2KˆÙ�z×'Ñ'¨Ó-°Ò2ÜÐDÓEÐEð ˆjÒØ×!Ñ! # rÓ*×2Ñ2°3¸Ó;×CÑCÀDÈ"ÓMˆØ—w‘wÔ1°$¼Ñ;[ÉNÓ;[Ó8[Ó\Ó]ˆØˆð �:ÑØ$.×$4Ñ$4°TÓ$:Ñ!ˆI�zØ(Ÿ™¨sÓ3ÐØ‰Gà)×/Ñ/°Ó4ÐØˆGä!Ð"2Ö3‰HˆC�Ø�cŠzØ—I‘I˜c“N aÒ'¨S¯Y©Y°uÓ-=ÀÒ-BÜ$Ð%8Ó9Ð9ð " #Ñ&¨"Ò,Ø$%‘Mä$'¬¨N¸3Ñ,?Ó(@À!Ó$DÌÈCËÐSTÉÑ$U�Mà  7Ò*Ø+�Gà  1Ò$Ü$Ð%EÓFÐFØ" aÒ'Ø,/¯K©K¸¸rÓ,BÐ$ SÒ)à,/¯K©K¸¸|È]ÈNÈOÐ?\Ó,]Ð$ SÒ)ð' 4ð* —X‘XÐ.Ó/ˆ
ð �aŠ<Ø‰Kà&¨ x yÐ1ˆKáØ˜$ ×!3Ñ!3°E¸;Ó!GÑGÑG‰Jô  /¨zÓ:ÐØŸ'™'¤&¬Ð-=Ó)>ÄÀ[ÓAQÑ)QÓ"RÓSˆKà˜$ Ñ,¨{Ñ:Ñ:ˆJð ˆzÑØ-7×-=Ñ-=¸dÓ-CÑ*ÐÑ*à-7¼ÈÓ9TÐ*Ðó !ˆØ×!Ñ! $Ó'¨1Ò,ÜÐ1°$°Ð7_Ð`ÓaÐaØÐ'Ò'ÜÐ1°$°Ð7TÐUÓVÐVð	 !ô Ð×!Ñ! #Ó&Ó'¬3¨x«=Ò8ÜØ+¬CÐ0@×0FÑ0FÀsÓ0KÓ,LÐ+Mð N#Ü#& x£= /°ð4ó
ð 	
ð
 Ð-¨xÐ7Ð7ùòc :s   ÂN)F)"Ú__doc__rr   Útypingr   r   r   r   r   r   Úopt_einsum.typingr	   r
   Ú__all__r   r‰   Úboolr   r   Úintr   r   r   r   r   r   ÚfloatÚcomplexÚbytesrY   r   r   rg   r   r   rN   r   r   Ú<module>r¤      s¦  ðÙ Hã ß =× =ç 8ò€ð NÐ ð8˜Cð 8 Dó 8ð 6¨Cð 6°Dó 6ð �#ð ˜#ó ð4˜Sð  Sð ¨X°c©]ó ð&;¨cð ;°có ;ð7 ð 7¨ó 7ð([ ð [¨ó [ð&y˜d 3™ið y°°oÑ1Fð yÐPSð yÐXgó yð  �C˜ ¨¨eÐ4€
ðt�ð t˜ó tð(" ð "¨ó "ðJ  S¡	ð °t¸CÀ¸H±~ð È#ó ð("+¨°©ð "+¸%ÀÀUÈ3ÐPSÈ8Á_Ð@TÑ:Uó "+ñJ~8 ð ~8¨dð ~8¸uÀSÈ#ÈtÐT]ÉÐE^Ñ?_ô ~8r   