Ë
    GìjÐ  ã                   ó0  — d Z ddlZddlmZmZmZmZmZmZm	Z	m
Z
 ddlZddlmZ ddlmZmZmZ dZg d¢Z e eee«      «      Zdded	eeeef      d
eedf   fd„Z	 dded	eeeef      dee   d
ee   fd„Ze
	 	 	 	 	 d dedededededee   deded   d
eeeeeef   f   fd„«       Ze
	 	 	 	 	 	 d!dedededededee   deded   d
eeef   fd„«       Z	 	 	 	 	 	 d"dedededededee   deded
e	eeeeeef   f   eeef   f   fd„Zded
ee   fd„Zy)#z Testing routines for opt_einsum.é    N)ÚAnyÚDictÚListÚLiteralÚOptionalÚTupleÚUnionÚoverload)Ú
get_symbol)Ú	ArrayTypeÚPathTypeÚTensorShapeTypeÚabcdefghijklmopqABC)é   é   é   é   r   r   r   é   r   r   r   r   r   é   r   r   r   r   r   ÚstringÚdimension_dictÚreturn.c                 óâ   — |€t         }g }| j                  d«      d   j                  d«      }|D ].  }|D �cg c]  }||   ‘Œ	 }}|j                  t        |«      «       Œ0 t        |«      S c c}w )a’  Builds random tensor shapes for testing.

    Parameters:
        string: List of tensor strings to build
        dimension_dict: Dictionary of index sizes, defaults to indices size of 2-7

    Returns:
        The resulting shapes.

    Examples:
        ```python
        >>> shapes = build_shapes('abbc', {'a': 2, 'b':3, 'c':5})
        >>> shapes
        [(2, 3), (3, 3, 5), (5,)]
        ```

    z->r   Ú,)Ú_default_dim_dictÚsplitÚappendÚtuple)r   r   ÚshapesÚtermsÚtermÚxÚdimss          úVC:\Users\Stabi\Downloads\virtual-tryon(1)\venv\Lib\site-packages\opt_einsum/testing.pyÚbuild_shapesr%      sv   € ð$ ÐÜ*ˆà€FØ�L‰L˜Ó˜qÑ!×'Ñ'¨Ó,€EÛˆÙ+/Ó0©4 a�˜qÓ!¨4ˆÐ0Ø�‰”e˜D“kÕ"ð ô �‹=Ðùò 1s   ·A,Úarray_functionc                 ó  — |€+t        j                  d«      }|j                  j                  }g }t	        | |¬«      D ]<  }|r|j                   ||Ž «       Œ|j                  t        j                  «       «       Œ> t        |«      S )a¸  Builds random numpy arrays for testing.

    Parameters:
        string: List of tensor strings to build
        dimension_dict: Dictionary of index _sizes
        array_function: Function to build the arrays, defaults to np.random.rand

    Returns:
        The resulting views.

    Examples:
        ```python
        >>> view = build_views('abbc', {'a': 2, 'b':3, 'c':5})
        >>> view[0].shape
        (2, 3, 3, 5)
        ```

    Únumpy)r   )ÚpytestÚimportorskipÚrandomÚrandr%   r   r   )r   r   r&   ÚnpÚviewsÚshapes         r$   Úbuild_viewsr0   -   sp   € ð* ÐÜ× Ñ  Ó)ˆØŸ™Ÿ™ˆà€EÜ˜f°^×DˆÙØ�L‰L™¨Ð/Õ0à�L‰LœŸ™›Õ)ð	 Eô
 �‹<Ðó    ÚnÚ
regularityÚn_outÚd_minÚd_maxÚseedÚ
global_dimÚreturn_size_dictTc                 ó   — y ©N© ©r2   r3   r4   r5   r6   r7   r8   r9   s           r$   Úrand_equationr>   O   s   € ð ,/r1   Fc                  ó   — y r;   r<   r=   s           r$   r>   r>   ]   s   € ð r1   c           	      ó:  ‡‡‡— t        j                  d«      }|�|j                  j                  |«       | |z  dz  ‰z   }	t	        | «      D �
cg c]  }
d‘Œ }}
g Št	        |	«      D �ci c]+  }t        |«      |j                  j                  ||dz   «      “Œ- c}Šˆˆˆfd„}t        |j                  j                  t         |«       «      «      «      D ]l  \  }}|| k  r||xx   |z  cc<   Œ|j                  j                  d| «      }|||   v r$|j                  j                  d| «      }|||   v rŒ$||xx   |z  cc<   Œn |rOt        |	«      }|j                  j                  ||dz   «      ‰|<   t	        | «      D ]  }||xx   |z  cc<   Œ ‰|z  Šdj                  |j                  j                  ‰«      «      Šdj                  dj                  |«      ‰«      }|D �cg c]  }t        ˆfd	„|D «       «      ‘Œ }}||f}|r|‰fz   S |S c c}
w c c}w c c}w )
a9  Generate a random contraction and shapes.

    Parameters:
        n: Number of array arguments.
        regularity: 'Regularity' of the contraction graph. This essentially determines how
            many indices each tensor shares with others on average.
        n_out: Number of output indices (i.e. the number of non-contracted indices).
            Defaults to 0, i.e., a contraction resulting in a scalar.
        d_min: Minimum dimension size.
        d_max: Maximum dimension size.
        seed: If not None, seed numpy's random generator with this.
        global_dim: Add a global, 'broadcast', dimension to every operand.
        return_size_dict: Return the mapping of indices to sizes.

    Returns:
        eq: The equation string.
        shapes: The array shapes.
        size_dict: The dict of index sizes, only returned if ``return_size_dict=True``.

    Examples:
        ```python
        >>> eq, shapes = rand_equation(n=10, regularity=4, n_out=5, seed=42)
        >>> eq
        'oyeqn,tmaq,skpo,vg,hxui,n,fwxmr,hitplcj,kudlgfv,rywjsb->cebda'

        >>> shapes
        [(9, 5, 4, 5, 4),
        (4, 4, 8, 5),
        (9, 4, 6, 9),
        (6, 6),
        (6, 9, 7, 8),
        (4,),
        (9, 3, 9, 4, 9),
        (6, 8, 4, 6, 8, 6, 3),
        (4, 7, 8, 8, 6, 9, 6),
        (9, 5, 3, 3, 9, 5)]
        ```
    r(   r   Ú é   c               3   óz   •K  — t        ‰«      D ](  \  } }| ‰k  r‰j                  |«       |–— Œ!|–— |–— Œ* y ­wr;   )Ú	enumerater   )ÚiÚixr4   ÚoutputÚ	size_dicts     €€€r$   Úgenzrand_equation.<locals>.gen¦   s>   øè ø€ Ü˜yÖ)‰EˆAˆrà�5ŠyØ—‘˜bÔ!Ø“ð ’Ø“ñ *ùs   ƒ8;r   z{}->{}r   c              3   ó(   •K  — | ]	  }‰|   –— Œ y ­wr;   r<   )Ú.0rF   rH   s     €r$   Ú	<genexpr>z rand_equation.<locals>.<genexpr>Ë   s   øè ø€ Ð/©B b�I˜b•M©Bùs   ƒ)r)   r*   r+   r7   Úranger   ÚrandintrD   ÚpermutationÚlistÚjoinÚformatr   )r2   r3   r4   r5   r6   r7   r8   r9   r-   Únum_indsÚ_ÚinputsrE   rI   rF   ÚwhereÚgdimÚeqÚopr   ÚretrG   rH   s     `                  @@r$   r>   r>   j   s  ú€ ô` 
×	Ñ	˜WÓ	%€BØÐØ
�	‰	�‰�tÔð �:‰~ Ñ" UÑ*€HÜ œ(Ó#™(�QŠb˜(€FÐ#Ø€FäMRÐS[Ì_Ó]É_È”˜A“ §	¡	× 1Ñ 1°%¸À¹Ó CÑCÈ_Ñ]€Iö	ô ˜2Ÿ9™9×0Ñ0´±c³e³Ó=Ö>‰ˆˆ2àˆqŠ5Ø�1‹I˜‰OŒIð —I‘I×%Ñ% a¨Ó+ˆEØ˜˜u™Ñ%ØŸ	™	×)Ñ)¨!¨QÓ/�ð ˜˜u™Ò%ð �5‹M˜RÑŒMð ?ñ Ü˜(Ó#ˆØŸ)™)×+Ñ+¨E°5¸1±9Ó=ˆ	�$‰Ü�q–ˆAØ�1‹I˜ÑŒIð à�$‰ˆð �W‰W�R—Y‘Y×*Ñ*¨6Ó2Ó3€FØ	�‰˜Ÿ™ &Ó)¨6Ó	2€Bñ ;AÓA¹&°BŒeÓ/©BÓ/Õ/¸&€FÐAàˆvˆ,€CáØ�i�\Ñ!Ð!àˆ
ùòe $ùò ^ùòP Bs   Á	HÁ(0HÇ#HÚpathc                 ó„   — t        j                  d«      }| D �cg c]  } |j                  j                  |Ž ‘Œ c}S c c}w )z‘Build random numpy arrays from a path.

    Parameters:
        path: The path to build arrays from.

    Returns:
    The resulting arrays.
    r(   )r)   r*   r+   r,   )r[   r-   r"   s      r$   Úbuild_arrays_from_tuplesr]   Õ   s;   € ô 
×	Ñ	˜WÓ	%€Bá(,Ó-© 1ˆNˆB�I‰I�N‰N˜AÒ¨Ñ-Ð-ùÒ-s   š =r;   )NN).....)......)r   r   é	   NFF)Ú__doc__r+   Útypingr   r   r   r   r   r   r	   r
   r)   Úopt_einsum.parserr   Úopt_einsum.typingr   r   r   Ú_valid_charsÚ_sizesÚdictÚzipr   ÚstrÚintr%   r0   Úboolr>   r]   r<   r1   r$   Ú<module>rj      s—  ðÙ &ã ß M× MÓ Mã å (ß BÑ Bà$€Ú	B€Ù™˜\¨6Ó2Ó3Ð ñ˜ð ¨h°t¸CÀ¸H±~Ñ.Fð ÐRWÐXgÐilÐXlÑRmó ð< cgñØðØ!)¨$¨s°C¨x©.Ñ!9ðØRZÐ[^ÑR_ðà
ˆ9ÑóðD 
ð ØØØØñ
/Ø
ð
/àð
/ð ð
/ð ð	
/ð
 ð
/ð �3‰-ð
/ð ð
/ð ˜d‘mð
/ð ˆ3�˜$˜s C˜x™.Ð(Ñ)ò
/ó 
ð
/ð 
ð ØØØØØ'*ñ	Ø
ð	àð	ð ð	ð ð		ð
 ð	ð �3‰-ð	ð ð	ð ˜e‘nð	ð ˆ3�ˆ=Ñò	ó 
ð	ð ØØØØØ"ñhØ
ðhàðhð ðhð ð	hð
 ðhð �3‰-ðhð ðhð ðhð ˆ5��h  S¨# X¡Ð.Ñ/°°s¸H°}Ñ1EÐEÑFóhðV. 8ð .°°S±	ô .r1   