
    3j+                        S SK r S SKJrJr  S SKrS SKrS SKJrJ	r	J
r
  S SKJr   " S S5      r\" SSSS	S
S9SS4\" SSSS	S
S9SS4\" SSSS
S9SS4\" SSSS
SSSS9SS4\" SSSSSSS9SS4/r/ S QrS! r/ S"QrS# rS$ rS% rg)&    N)AnyCallable)EinopsError_compactify_pattern_for_einsumeinsum)collect_test_backendsc                   4    \ rS rSrS\S\4S jrS\4S jrSrg)		Arguments   argskargsc                     Xl         X l        g Nr   kwargs)selfr   r   s      R/home/wildlama/miniconda3/lib/python3.13/site-packages/einops/tests/test_einsum.py__init__Arguments.__init__   s    	    functionc                 :    U" U R                   0 U R                  D6$ r   r   )r   r   s     r   __call__Arguments.__call__   s    2dkk22r   r   N)	__name__
__module____qualname____firstlineno__r   r   r   r   __static_attributes__ r   r   r
   r
      s!    c C 3 3r   r
   zb c_in h w -> w c_out h bz
c_in c_out      )
bias_shapec_outc_in)   r"         )r(   r!   r'   r&   r$   zb c_in h w -> w c_in h b )r#   r%   )r(   r"   r'   r&   zb c_in h w -> b c_outzc_in h w c_outr'   r(      )r#   r%   hwr$   r&   r*   zb t head c_in -> b t head c_outzhead c_in c_out   )r#   headr%   r$   r&   r'   r(   r*   )r&   r'   r(   r.   ))zb c h w, b w -> b hzabcd,ad->ac)r0   r-   )r&   r(   )zb c h w, b w, b c -> b hzabcd,ad,ab->ac))r&   r'   (   r*   r-   r&   r'   )r&   r1   )z2... one two three, three four five -> ... two fivez...abc,cde->...be)    r*   r&   r'   r(   r(   r*   r.   r4   r*   r'   r.   )z2one two three ..., three four five -> two five ...zabc...,cde->be...))r&   r'   r(   r4   r*   r5   )r'   r.   r4   r*   )z6... one two three, ... three four five -> ... two fivez...abc,...cde->...be)r3   )r4   r*   r(   r*   r.   r6   )z*first_tensor second_tensor -> first_tensorzab->a))r*   r(   r*   )zi i -> zaa->))r*   r*   r    )z% one  two  ,  three four->two  four  z	ab,cd->bd)r2   )r(   r*   )r'   r*   )zi middle i -> middlezaba->b))r*   
   r*   r8   )zi ... i -> ...z
a...a->...)r*   r'   r&      r(   r*   )r'   r&   r;   r(   )zi ... i -> i ...za...a->a...r:   )r*   r'   r&   r;   r(   )zone one one -> onezaaa->a))r*   r*   r*   r7   )zi j k -> j i kzabc->bac))r;   r&   r'   )r&   r;   r'   )z
... -> ...z...->...)r*   r(   r'   r&   r;   r<   )z..., ..., ... -> ...z...,...,...->...)r'   r&   r=   r=   r=   )zindex ->za->r9   r    c                     [        SSS9 H  n [        R                  R                  5       nU R                  S;   d  M3  U R                  5       R                  n[         H  u  p4nU" U5      n[        SUR                  SU R                  5        UR                  US9R                  S5      nU R                  U5      nU" U5      n	U R                  U	5      n
U
R                  U:X  a  M   e   M     g )	NTF)layerssymbolic)
tensorflowtorchoneflowpaddleRunningforsizefloat32)r   nprandomdefault_rngframework_namer?   EinMixtest_layer_casesprinteinsum_patternuniformastype
from_numpyto_numpyshape)backendrng
layer_typer   in_shape	out_shapelayerinputinput_frameworkoutput_frameworkoutputs              r   
test_layerra      s    (uEii##%!!%QQ )00J-=)	Z(i!5!5ug>T>TU299)D")"4"4U";#(#9  ))*:;||y000 .>	 Fr   )
rA   rB   jaxnumpyrC   cupyztensorflow.kerasrD   pytensormlxc            	         [        S [        5       5      n U  GHZ  n[         GHK  u  p#pE[        SU SUR                   35        [        U5      nXc:X  d   e[        R                  R                  S5      nU Vs/ s H   oR                  US9R                  S5      PM"     n	nU	 V
s/ s H  oR                  U
5      PM     nn
S H  nU(       a  UR                  " U/UQ76 nO[        / UQUP76 n[        UR                  5      U:w  a  [        SU S	UR                   35      e[        R                  " U/U	Q76 nUR!                  U5      n[        R"                  R%                  XS
S9  M     GMN     GM]     g s  snf s  sn
f )Nc                 (    U R                   [        ;   $ r   rM   valid_backends_functionalxs    r   <lambda>!test_functional.<locals>.<lambda>   s     0 04M Mr   	Running 'z' for r   rG   rI   TFExpected output shape 	 but got r*   decimal)filterr   test_functional_casesrP   rM   r   rJ   rK   RandomStaterR   rS   rT   r   tuplerV   
ValueErrorrU   testingassert_array_almost_equal)backendsrW   einops_patterntrue_pattern	in_shapesr[   predicted_patternrstaterV   	in_arraysarrayin_arrays_frameworkdo_manual_call	out_arraytrue_out_arraypredicted_out_arrays                   r   test_functionalr      sx   MOdOfgHBWBW>N)In-VG4J4J3KLM !?~ N$444 YY**1-FS\]S\%U3::9ES\I]JS"T)#5#5e#<)"T #0! '/@ WCV WI & L(; L^ LI )Y6$'=i[	R[RaRaQb%cdd "$<!D)!D&-&6&6y&A#

445Hbc4d #0 CX  ^"Ts   9'E8&E=c                     [        S [        SSS95      n U  GHd  n[         GHU  u  p#pE[        SU SUR                   35        [        U5      nXc:X  d   e[        R                  R                  S5      nU Vs/ s H  oR                  U5      PM     n	nU Vs/ s H   oR                  US9R                  S	5      PM"     n
n[        R                  " U/U
Q76 nS
 H  nU(       a  UR                  " U/U	Q76 nO[        / U	QUP76 nUR                  U[        [        X5      5      5      nUR                   U:w  a  [#        SU SUR                    35      e[        R$                  R'                  XSS9  M     GMX     GMg     g s  snf s  snf )Nc                 (    U R                   [        ;   $ r   ri   rk   s    r   rm   *test_functional_symbolic.<locals>.<lambda>   s    !""&??r   TF)r@   r?   ro   z' for symbolic r   rG   rI   rp   rq   rr   r*   rs   )ru   r   rv   rP   rM   r   rJ   rK   rw   create_symbolrR   rS   r   eval_symbollistziprV   ry   rz   r{   )r|   rW   r}   r~   r   r[   r   r   rZ   in_symsin_dataexpected_out_datar   predicted_out_symbolpredicted_out_datas                  r   test_functional_symbolicr      s   ?AV`dmrAsH BWBW>N)In-_W=S=S<TUV >~ N$444YY**1-FGPQy8,,X6yGQW`aW`8~~8~4;;IFW`Ga "		, A A"/!+2>>:K+Vg+V(+1+K7+KN+K(%,%8%8(W./&" &++y8$'=i[	RdRjRjQk%lmm

445Gde4f #0 CX  Ras   9F'Fc            	        ^ [         R                  R                  S5      mU4S jn [        R                  " [
        SS9   [        U " SS5      S5        S S S 5        [        R                  " [
        SS9   [        U " SS5      S	5        S S S 5        [        R                  " [
        SS9   [        U " S
S5      S5        S S S 5        [        R                  " [
        SS9   [        U " SS5      S5        S S S 5        [        R                  " [        SS9   [        U " SS5      S5        S S S 5        [        R                  " [        SS9   [        U " SSS5      S5        S S S 5        [        R                  " [        SS9   [        U " S5      SR                  [        R                  5      S-   5        S S S 5        [        R                  " [        SS9   [        U " SS5      S5        S S S 5        [        R                  " [        SS9   [        SU " SSS5      5        S S S 5        [        R                  " [        SS9   [        S5        S S S 5        [        R                  " [        SS9   [        U " SS5      5        S S S 5        g ! , (       d  f       GN:= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GNH= f! , (       d  f       GN%= f! , (       d  f       GN= f! , (       d  f       N= f! , (       d  f       g = f)Nr   c                  @   > TR                  U S9R                  S5      $ )NrG   rI   )rR   rS   )rV   r   s    r   create_tensor-test_functional_errors.<locals>.create_tensor  s    ~~5~)00;;r   z
^Singleton)matchr*   r;   z	i () -> iz^Shape rearrangementza b -> (a b)r8   z(a b) -> a bz^Anonymous axeszi 2 -> iz^Invalid axis identifierz	i 2j -> iz^Einsum patternr'   r&   zi j kz^Too many axes z	 extra ->z^Unknown axiszi j -> kz^The last argumentz
i j k -> ir(   z^`einops.einsum` takes)rJ   rK   rw   pytestraisesNotImplementedErrorr   r   ry   RuntimeErrorjoinstringascii_letters)r   r   s    @r   test_functional_errorsr   	  sw    YY""1%F< 
*,	?!Q	
 
@ 
*2H	I!Q	
 
J 
*2H	I"a 	
 
J 
*2C	D!Q	
 
E 
{*D	E!Q	
 
F 
z):	;!Q"	
 
< 
|+;	<!HHV))*[8	
 
= 
|?	;!Q	
 
< 
z)=	>!Q"	
 
? 
z)A	B	
 
C 
z)A	B!Q	
 
C	BY 
@	? 
J	I 
J	I 
E	D 
F	E 
<	; 
=	< 
<	; 
?	> 
C	B 
C	Bs    J5J*J+J=K	K!?3K3LL>L)+L:
J
J(+
J:=
K
K!
K03
L
L
L&)
L7:
M)r   typingr   r   rc   rJ   r   einops.einopsr   r   r   einops.testsr   r
   rO   rv   ra   rj   r   r   r   r    r   r   <module>r      s         M M .3 3 	-|TV]_` 	-|WY`bc 	,bTK 	)+;SUYZ^_ghi 	35FSW^_fgopq+ >s l1  eFg@Y
r   