+
    Pj,                     T    ^ RI t^ RIt^ RIHtHtHt ^ RIHt ^ RI	H
t
 R tR tR tR# )    N)parse_shape	rearrangereduce)is_backend_tested)imp_op_backendsc                    aaaaa R  p R pR pR pR pR pR pR pR pR	 p	R
 p
R oR oR oR oR oV VVVVVVVVV	V
VV3R lVV3R lVV3R lVV3R l.p\          EF_  p\        RVP                  4       V EF>  p\        P                  ! R4      P                  . RO4      pV! V4      pVP                  V! VP                  V4      4      4      p\        P                  ! VV4      '       g   Q h\        P                  ! R4      P                  . RO4      pVP                  R8w  d   VP                  R8w  d   RM^p\        P                  RRRRRV13,          pV! VV,          4      pVP                  V! VP                  V4      V,          4      4      p\        P                  ! VV4      '       d   EK?  Q h	  EKb  	  R# ) c                 V    \        V R 4      p\        VP                  4      R8X  g   Q hV# )b c h w -> b h w c
      (      r   tupleshapexys   & s/Users/ahmed/devFolder/Ultron/claude-voice/gateway/.venv/lib/python3.14/site-packages/einops/tests/test_examples.pytest1&test_rearrange_examples.<locals>.test1
   s+    a-.QWW~!1111    c                 V    \        V R 4      p\        VP                  4      R8X  g   Q hV# )zb c h w -> b (c h w))r   i]  r   r   s   & r   test2&test_rearrange_examples.<locals>.test2   s+    a/0QWW~!3333r   c                 \    \        V R ^^R7      p\        VP                  4      R8X  g   Q hV# )z$b (c h1 w1) h w -> b c (h h1) (w w1)h1w1)r      <   P   r   r   s   & r   test3&test_rearrange_examples.<locals>.test3   s/    a?A!LQWW~!8888r   c                 \    \        V R ^^R7      p\        VP                  4      R8X  g   Q hV# )z$b c (h h1) (w w1) -> b (h1 w1 c) h wr   )r   r#      r   r   r   s   & r   test4&test_rearrange_examples.<locals>.test4   s/    a?A!LQWW~!????r   c                 V    \        V R 4      p\        VP                  4      R8X  g   Q hV# )z(b1 sound b2 letter -> b1 b2 sound letter)r   r   r   r   r   r   s   & r   test5&test_rearrange_examples.<locals>.test5"   s+    aCDQWW~!1111r   c                     \        V R 4      pVR,          p\        VP                  4      R8X  g   Q h\        VR3/ \        V R4      B p\        VP                  4      R8X  g   Q hV# )zb c h w -> (b h w) cz(b h w) c2 -> b c2 h wzb _ h w)NNNNN   )i.  r   r   r   r   r   )r   r   r   r   )r   tr   s   &  r   test6&test_rearrange_examples.<locals>.test6(   sd    a/0fIQWW~!3333a1O[I5NOQWW~!1111r   c                     \        V R ^R7      w  r\        VP                  4      R8X  g   Q h\        VP                  4      R8X  g   Q hW,           # )zb (c g) h w -> g b c h w)gr1   r   )r   y1y2s   &  r   test7&test_rearrange_examples.<locals>.test72   sH    18A>RXX"2222RXX"2222wr   c                 ^    \        V R R^^R7      p\        VP                  4      R8X  g   Q hV# )zb c (h h1) (w w1) -> b c h wmax)	reductionr   r    )r   r   r'   r   )r   r   r   r   s   & r   test8&test_rearrange_examples.<locals>.test89   s2    14!PQRQWW~!;;;;r   c                     \        V R RR7      p\        VP                  4      R8X  g   Q h\        VR4      p\        VP                  4      R8X  g   Q hV# )zb c h w -> b c () ()r<   )r=   zb c () () -> c b)r   r      rA   )r   r   )r   r   r   r   r   s   & r   test9&test_rearrange_examples.<locals>.test9?   sO    1,>QWW~///a+,QWW~)))r   c                 z    \        V ^ ,           4      p\        VR4      p\        VP                  4      R8X  g   Q hV# )r   r
   r   listr   r   r   r   tensorss   & r   test10'test_rearrange_examples.<locals>.test10G   s9    q1u+G%9:W]]#'7777r   c                 z    \        V ^ ,           4      p\        VR4      p\        VP                  4      R8X  g   Q hV# )r   zb c h w -> h (b w) c)r   i  r   rE   rG   s   & r   test11'test_rearrange_examples.<locals>.test11N   s9    q1u+G%;<W]]#'8888r   c                 B    V! V 4      p \        V R W#R7      p V! V 4      p V # )zb (c1 c2) h w-> b (c2 c1) h w)c1c2r   )r   convolverO   rP   s   &&&&r   
shufflenet+test_rearrange_examples.<locals>.shufflenetU   s(    QKa8RGQKr   c                 f    \        V R 4      p \        V RVR7      p V! V 4      p \        V RVR7      p V # )b c t1 t2 -> b c (t1 t2)z b c (t stride) -> (stride b) c t)stridez (stride b) c t -> b c (t stride)rQ   )r   rW   usual_convolutions   &&&r   convolve_strided_1d4test_rearrange_examples.<locals>.convolve_strided_1d\   s<    a34a;FKa a;FKr   c                 N    \        V R WR7      p V! V 4      p \        V RWR7      p V # )z$b c (h hs) (w ws) -> (hs ws b) c h w)hswsz$(hs ws b) c h w -> b c (h hs) (w ws)rQ   )r   h_stridew_striderX   s   &&&&r   convolve_strided_2d4test_rearrange_examples.<locals>.convolve_strided_2dc   s/    a?HZa a?HZr   c                 t    \        V R 4      p \        V R^R7      pV! V4      pV \        VR^R7      ,           p V # )rV   zb c (t dt) -> b (dt c) t)dtzb (dt c) t -> b c (t dt)rQ   )r   rX   r   s   && r   unet_like_1d-test_rearrange_examples.<locals>.unet_like_1di   sA    a34a3:a 	!7A>>r   c                     V # )N )r   s   &r   convolve_mock.test_rearrange_examples.<locals>.convolve_mockr   s    r   c                    < S! V S^^R7      # )   )rR   rO   rP   rg   )r   rh   rS   s   &r   <lambda>)test_rearrange_examples.<locals>.<lambda>   s    *Q1Cr   c                    < S! V ^SR7      # )r0   )rW   rX   rg   )r   rh   rY   s   &r   rl   rm      s    %a]Sr   c                    < S! V ^^SR7      # )r0   )r^   r_   rX   rg   )r   rh   r`   s   &r   rl   rm      s    %a!aS`ar   c                    < S! V SR 7      # ))rX   rg   )r   rh   rd   s   &r   rl   rm      s    ,qMBr   ztesting source_examples for torchoneflowr/   :NN   :NNrA   Ni )r   r   r   r   i  )r   r"   r   r   )
r   printframework_namenparangereshapeto_numpy
from_numpyarray_equal	index_exp)r   r   r$   r(   r+   r3   r9   r>   rB   rI   rL   testsbackendtestr   result1result2	last_stepindexing_expressionrh   rY   r`   rS   rd   s                      @@@@@r   test_rearrange_examplesr   	   s    	CSaBE$ #?,g.D.DED		+,445EFA1gG&&tG,>,>q,A'BCG>>'73333 		78@@AabA&55@WE[E[_hEhopI"$,,sCk	k/I"J1012G&&tG,>,>q,ABU,V'WXG>>'73333  #r   c            	         \         P                  ! . R
O4      p ^p\         P                  R8  d   R# V P                   Uu. uF  p\         P                  ! W"W.4      NK  	  ppV^ ,          R,          V^ &   VR,          R,          VR&   V P	                  ^.V P                  O54      pV F  p\         P
                  ! RWT4      pK  	  VP	                  R4      pV P	                  R4      pV FA  pVP                  w  rxr\        VRWR7      pV\        VR4      ,          p\        VRWR7      pKC  	  Tp\         P                  ! Wk4      '       g   Q hT pV F3  pVP                  w  rxr\        VR	WR7      pV\        VR4      ,          pK5  	  VP	                  R4      p\         P                  ! Wl4      '       g   Q hR# u upi )rs   z1.15.0Nzi j a b, a i ...  -> b ... jz (i rest alpha) -> rest (alpha i))alphaiz$i j alpha beta -> (alpha i) (j beta)zrest (beta j) -> (beta rest j))betajz"i ... (j alpha) -> ... j (alpha i))rs   rk   r!      )r.   r.   NrA   Nr.   rt   )r.   r.   r.   r   )rw   ones__version__r   ry   einsumr   allclose)r   rankdGsr   Gr7   r   r   r   r   r8   y3s                r   tensor_train_example_numpyr      s    	AD	~~ /0ww	7w!"''1$
%wB	7qE+BqEVK BrF 	
		1-qww- A II4a;  
2B 	
		"AGGea;5N	!CDDa9J	 
 
B;;r 	
AGGea=UP	!CDD  
2B;;r; 
8s    !F=c            	        a \        R 4      '       g   \        P                  ! 4        ^ RIoV3R lp V3R lp^p^p^p^p^2^d.^d^2.^K^K..p\	        V4      pSP                  WG^V,           ,          ^^.4      pV ! VVVVVVR7      p	V! VVVVVVR7      p
V	P                  V
P                  4      p	SP                  W4      '       g   Q hR# )rq   Nc           	      :  < V P                  ^ 4      pV P                  ^4      pV P                  ^4      pV U	U
u. uF  w  rW,          W,          3NK  	  pp	p
V P                  Wb^V,           Wx4      P                  ^ ^^^^4      P                  4       pSP	                  VR,          4      pSP	                  VR,          4      pVR,          pVR,          pSP	                  VR,          4      pSP	                  VR,          4      pVP
                  '       d   SP                  P                  MSP                  pVP
                  '       d   SP                  P                  MSP                  pSP                  ^ V^,
          V4      P                  V^4      P                  Wb,          ^^4      P                  VP                  4      P                  V4      pSP                  ^ V^,
          V4      P                  V^4      P                  4       P                  Wb,          ^^4      P                  VP                  4      P                  V4      pV! V4      P                  ^V! ^ .4      4      pV! V4      P                  ^V! ^.4      4      pVP                  V^4      P                  ^^Wx,          4      P                  VP                  4      pVP                  V^4      P                  ^^Wx,          4      P                  VP                  4      pV! VR,          P                  4      pVP                  V,           VR&   VP                  V,           VR&   SP!                  VP                  4      V,          VR&   SP!                  VP                  4      V,          VR&   SP#                  WT.^,          4      P                  V4      pSP%                  VP                  VR^4      V,          VP                  VR^4      VP                  VRV4      3R4      pV# u up
p	i )	r   ).r   ).rA   ).r0   ).rs   ).rk   ).r!   NN).:Nrk   Nrt   )sizeviewpermute
contiguoussigmoidis_cudacudaFloatTensor
LongTensorlinspacerepeatr   typer2   index_selectdataexpTensorcat)tensornum_classesnum_anchorsanchorsstride_hstride_wbsin_hin_wa_wa_hscaled_anchors
predictionr   r   whconfpred_clsr   r   grid_xgrid_yanchor_wanchor_h
pred_boxes_scaleoutputrq   s   &&&&&&                      r   old_way+test_pytorch_yolo_fragment.<locals>.old_way   sI   [[^{{1~{{1~KRS7xs3>3>:7S[[!k/4NVVWXZ[]^`acdeppr
MM*V,-MM*V,-vv}}Z/0==G!45 12			ejj,,u?P?P./iiiUZZ**U=M=M
 NN1dQh-VD!_VB$a+T!'']T+ 	 NN1dQh-VD!_QSVB$a+T!'']T+ 	 ~.;;Az1#O~.;;Az1#O??2q)00At{CHHQ??2q)00At{CHHQ G!4!:!:;
VVf_
6VVf_
6"YYqvv.9
6"YYqvv.9
6x2Q67<<[I__RQ'&0$))BA2FVXZ\^iHjkmo
 ] Ts   Pc                 :  < \        V R VR7      pSP                  V4      P                  V P                  4      p\        VR4      pVP                  w    rp
\        SP                  V	4      P                  4       R4      P                  V P                  4      p\        SP                  V
4      P                  4       R4      P                  V P                  4      pSP                  V4      pV^ ,          P                  4       V,           V,          V^ &   V^,          P                  4       V,           V,          V^&   VR,          P                  4       V,          VR&   V^,          P                  4       V^&   VR,          P                  4       VR&   \        VR4      # )z5 b (anchor prediction) h w -> prediction b anchor h w)anchorz!anchor dim -> dim () anchor () ()zh -> () () h ()zw -> () () () w:r0   rk   Nr   z2prediction b anchor h w -> b anchor h w prediction)
r   r   todevicer   rx   float
zeros_liker   r   )r   r   r   r   r   r   raw_predictionsanchor_sizes_r   r   grid_hgrid_wpredicted_bboxesrq   s   &&&&&&        r   new_way+test_pytorch_yolo_fragment.<locals>.new_way   se   #F,clwx##G,//> *MN-331at5<<-3357HILLV]][5<<-3357HILLV]][ ++O<.q199;fDP.q199;fDP!0!5!9!9!;| K-a088:.r2::<)+_``r   )r   r   r   r   r   r   )	r   pytestskiprq   lenrandnry   r   r   )r   r   r   r   
batch_sizer   r   r   r   r   r   rq   s              @r   test_pytorch_yolo_fragmentr      s    W%%3ja& HHJKCy3)b"X.Gg,KZK!@!QGHAG G oogmm,G>>'++++r   )numpyrw   r   einopsr   r   r   einops.testsr   einops.tests.test_opsr   r   r   r   rg   r   r   <module>r      s*      1 1 * 1M4`&Rg,r   