+
    –°³jë  ã                  ó¾   € ^ RI Ht ^ RIt^ RIHt ^ RIt^ RIHt ^RIH	t	H
t
HtHtHt ]'       d	   ^ RIHtHt R.t]P$                  ! R4      R	 R
 l4       tR R ltR# )é    )ÚannotationsN)ÚTYPE_CHECKING)Údims)Ú	_ellipsisÚAnonymousAxisÚcomma_separateÚparse_patternÚvalidate_rearrange_expressions)ÚCallableÚSequenceÚ	rearrangeé   c               ó(   € V ^8„  d   QhRRRRRRRR/# )é   Útensor_ndimÚintÚpatternÚstrÚaxes_lengthsÚreturnz&Callable[[torch.Tensor], torch.Tensor]© )Úformats   "Ú[/home/luca/screen-checking/.venv/lib/python3.14/site-packages/functorch/einops/rearrange.pyÚ__annotate__r      s2   € ÷ }5ñ }5Øð}5Ø"ð}5Ø47ð}5à+ñ}5ó    c                óš  aaa€ \        W4      w  r4\        W4V4       \        R VP                   4       4      pVP                  '       da   V \        VP                  4      ^,
          ,
          p\        VP                  4      ^,
          pWW,           ;q€8”  d   \        RV RV  R24      hMD^ p\        VP                  4      p\        VP                  4      ;q€8w  d   \        RV RV  R24      hWv,           V,           p	V	^ 8X  d   R # \        ;QJ d    . R \        V	4       4       F  NK  	  5M! R \        V	4       4       4      o/ o. p
^ oVP                   EF&  p\        V\        4      '       dœ   V FF  p\        V\        4      '       g   \        R\        V4       24      hSS,          3SV&   S^,          oKH  	  V'       gF   \        R	4      pSS,          3SV&   V
P!                  V4       VP!                  V4       S^,          oK³  Kµ  V\"        8X  d\   \"        p\        ;QJ d!    . VV3R
 l\        V4       4       F  NK  	  5M! VV3R
 l\        V4       4       4      SV&   SV,          oEK  \        RV 24      h	  R V3R llpV! VP                  4      pV! VP                  4      p\        ;QJ d    . V3R lV
 4       F  NK  	  5M! V3R lV
 4       4      p\        ;QJ d%    . V3R lVP%                  4        4       F  NK  	  5M! V3R lVP%                  4        4       4      pRpRV R\'        S4       RV	 R2V'       d   RP)                  R V 4       4      MR,           R\'        V4       R\'        V4       R2,           V'       d   R\'        V.4       R2MR,           p/ p\+        V\-        4       V4       VV,          # )aV  Translate an `einops`-style pattern into a callable that performs the rearrange using first-class dimensions.

Since the an equivalent result is computed for tensors with the same number of dimensions, with the same pattern and
specified axes lengths, this function can be memoized.

Args:
    tensor_ndim (int): the number of dimensions in the tensor to rearrange
    pattern (str): the `einops`-style rearrangement pattern
    axes_lengths (int): any additional length specifications for dimensions

Returns:
    Callable[[torch.Tensor], torch.Tensor]: a callable that performs the rearrangement
c              3  ó.   "  € T F  q'       * x € K  	  R # 5i©Nr   )Ú.0Údims   & r   Ú	<genexpr>Ú-_create_rearrange_callable.<locals>.<genexpr>,   s   é € Ð:Ñ)9 #—g‘gÓ)9ùs   ‚z!Number of dimensions in pattern (zH) must be less than or equal to the number of dimensions in the tensor (Ú)z;) must be equal to the number of dimensions in the tensor (c                ó   € V # r   r   )Útensors   &r   Ú<lambda>Ú,_create_rearrange_callable.<locals>.<lambda>C   s   € ™fr   c              3  ó,   "  € T F
  pR V 2x € K  	  R# 5i)ÚdNr   )r   Úis   & r   r!   r"   E   s   é € Ð-M¹}¸!°°!°­g»}ùs   ‚zExpected str, got Ú1c              3  óD   <"  € T F  pSSV,           ,          x € K  	  R # 5ir   r   )r   ÚjÚdims_iÚfirst_class_dimss   & €€r   r!   r"   \   s"   øé € ð 3Ù6L°Ð  ¨!¥×,Ò,Ó6Lùó   ƒ úUnexpected dimension: c               ó    € V ^8„  d   QhRRRR/# )r   Úcompositionz)Sequence[list[str | AnonymousAxis] | str]r   zlist[str | tuple[str, ...]]r   )r   s   "r   r   Ú0_create_rearrange_callable.<locals>.__annotate__c   s   € ÷ ñ Ø>ðà	$ñr   c                ó:  <€ . pV  F‘  p\        V\        4      '       dD   TP                  \        ;QJ d    . V3R lV 4       F  NK  	  5M! V3R lV 4       4      4       K\  V\        8X  d   VP                  S\        ,          4       K…  \        RV 24      h	  V# )ztConvert a `ParsedExpression.composition` into a `Tensor.__getitem__` index of strings representing first
class dims.c              3  óH   <"  € T F  pSV,           F  pVx € K	  	  K  	  R # 5ir   r   )r   Ú
identifierr    Úidentifier_dim_maps   &  €r   r!   ÚJ_create_rearrange_callable.<locals>.composition_to_dims.<locals>.<genexpr>l   s-   øé € ð á*3˜JØ#5°j×#AÐ#A˜Cõ á#Añ Û*3ùs   ƒ"r1   )Ú
isinstanceÚlistÚappendÚtupler   ÚextendÚ
ValueError)r3   Údim_compositionÚ	dimensionr8   s   &  €r   Úcomposition_to_dimsÚ7_create_rearrange_callable.<locals>.composition_to_dimsc   s�   ø€ ð
 8:ˆÛ$ˆIÜ˜)¤T×*Ò*Ø×&Ñ&ß”Eô á*3ó—E‘Eô á*3óó öð œiÔ'Ø×&Ñ&Ð'9¼)Õ'DÖEä Ð#9¸)¸Ð!EÓFÐFñ %ð Ðr   c              3  óD   <"  € T F  pSV,          ^ ,          x € K  	  R# 5i©r   Nr   )r   Úaxisr8   s   & €r   r!   r"   z   s   øé € ÐH¹i°dÐ(¨Õ.¨q×1Ò1»iùr0   c              3  óL   <"  € T F  w  rSV,          ^ ,          V3x € K  	  R# 5irE   r   )r   rF   Úlengthr8   s   &  €r   r!   r"   {   s'   øé € ð ÙBV±,°$Ð	˜DÕ	! !Õ	$ fÕ-ÓBVùs   ƒ!$Údo_rearrangezdef z(tensor):
    z = dims(z)
Ú c              3  ó8   "  € T F  w  rR V RV R2x € K  	  R# 5i)z    z.size = Ú
Nr   )r   r    rH   s   &  r   r!   r"   †   s%   é € ð ÙDU±=°C�$�s�e˜8 F 8¨2Õ.ÓDUùs   ‚z    tensor = tensor[z].order(z    return tensor.sum(z, keepdim=False)
z    return tensor
)r	   r
   Úsumr3   Úhas_ellipsisÚlenÚidentifiersr?   r=   Úranger:   r;   r   ÚAssertionErrorÚtyper   r<   r   Úitemsr   ÚjoinÚexecÚglobals)r   r   r   ÚleftÚrightÚn_anon_dimsÚn_ellipsis_dimsÚn_named_dimsÚpattern_ndimÚn_dimsÚ	anon_axesrA   r7   Ú	anon_axisrB   Ú	left_dimsÚ
right_dimsÚ	anon_dimsÚspecified_lengthsÚcustom_rearrange_callable_nameÚcustom_rearrange_callable_codeÚ	namespacer.   r/   r8   s   &&,                   @@@r   Ú_create_rearrange_callablerh      sÁ  ú€ ô"   Ó6�K€DÜ" 4°Ô=äÑ:¨×)9Ò)9Ó:Ó:€KØ××ÐØ%¬¨T×-=Ñ-=Ó)>ÀÕ)BÕCˆÜ˜4×+Ñ+Ó,¨qÕ0ˆà'Õ6Ð6ˆLÔEÜØ3°L°>ð B-Ø-8¨M¸ð<óð ð Fð ˆÜ˜4×+Ñ+Ó,ˆä × 0Ñ 0Ó1Ð1ˆLÔAÜØ3°L°>ð BØ*˜m¨1ð.óð ð Õ+¨kÕ9€Fà�„{á$Ð$ç(-¬Ñ-M¼uÀV¼}Ó-M¯©Ñ-M¼uÀV¼}Ó-MÓ(MÐØEGÐØ%'€Ið €FØ×%Õ%ˆ	Ü�i¤×&Ò&Û'�
ä! *¬c×2Ò2Ü(Ð+=¼dÀ:Ó>NÐ=OÐ)PÓQÐQØ2BÀ6Õ2JÐ1LÐ" :Ñ.Ø˜!•’ñ (÷ ä)¨#Ó.�	Ø1AÀ&Õ1IÐ0KÐ" 9Ñ-Ø× Ñ  Ô+Ø× Ñ  Ô+Ø˜!•’ñ ð œ)Ô#Ü"ˆJß-2¬Uõ 3Ü6;¸OÔ6Ló3¯U©Uõ 3Ü6;¸OÔ6Ló3ó .Ð˜zÑ*ð �oÕ%‹FäÐ5°i°[ÐAÓBÐBñ- &÷0ð ñ* $ D×$4Ñ$4Ó5€IÙ$ U×%6Ñ%6Ó7€Jß”ÔH¹iÓH—‘ÔH¹iÓHÓH€Ißœô ØBN×BTÑBTÔBVóŸ™ô ØBN×BTÑBTÔBVóó Ðð &4Ð"ð Ð1Ð2ð 3Ü!Ð"2Ó3Ð4°H¸V¸HÀCðI÷ !ð �G‰Gñ ÙDUóô ð õ
	
ð !¤°	Ó!:Ð ;¸8ÄNÐS]ÓD^ÐC_Ð_bÐ
cõ	d÷ ð %¤^°Y°KÓ%@Ð$AÐASÑTà&õ	
ð #ð( €IÜÐ	'¬«°IÔ>ØÐ3Õ4Ð4r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r%   z<torch.Tensor | list[torch.Tensor] | tuple[torch.Tensor, ...]r   r   r   r   r   ztorch.Tensorr   )r   s   "r   r   r   ™   s0   € ÷ :&ñ :&ØHð:&àð:&ð ð:&ð ñ	:&r   c                ó¬   € \        V \        P                  4      '       g   \        P                  ! V 4      p \	        V P
                  V3/ VB pV! V 4      # )a2  A native implementation of `einops.rearrange`, a reader-friendly smart element reordering for multidimensional
tensors. This operation includes functionality of transpose (axes permutation), reshape (view), squeeze, unsqueeze,
stack, concatenate and other operations.

See: https://einops.rocks/api/rearrange/

Args:
    tensor (Tensor or sequence of Tensor): the tensor(s) to rearrange
    pattern (str): the rearrangement pattern
    axes_lengths (int): any additional length specifications for dimensions

Returns:
    Tensor: the rearranged tensor

Examples:
    >>> # suppose we have a set of 32 images in "h w c" format (height-width-channel)
    >>> images = torch.randn((32, 30, 40, 3))

    >>> # stack along first (batch) axis, output is a single array
    >>> rearrange(images, "b h w c -> b h w c").shape
    torch.Size([32, 30, 40, 3])

    >>> # concatenate images along height (vertical axis), 960 = 32 * 30
    >>> rearrange(images, "b h w c -> (b h) w c").shape
    torch.Size([960, 40, 3])

    >>> # concatenated images along horizontal axis, 1280 = 32 * 40
    >>> rearrange(images, "b h w c -> h (b w) c").shape
    torch.Size([30, 1280, 3])

    >>> # reordered axes to "b c h w" format for deep learning
    >>> rearrange(images, "b h w c -> b c h w").shape
    torch.Size([32, 3, 30, 40])

    >>> # flattened each image into a vector, 3600 = 30 * 40 * 3
    >>> rearrange(images, "b h w c -> b (c h w)").shape
    torch.Size([32, 3600])

    >>> # split each image into 4 smaller (top-left, top-right, bottom-left, bottom-right), 128 = 32 * 2 * 2
    >>> rearrange(images, "b (h1 h) (w1 w) c -> (b h1 w1) h w c", h1=2, w1=2).shape
    torch.Size([128, 15, 20, 3])

    >>> # space-to-depth operation
    >>> rearrange(images, "b (h h1) (w w1) c -> b h w (c h1 w1)", h1=2, w1=2).shape
    torch.Size([32, 15, 20, 12])
)r:   ÚtorchÚTensorÚstackrh   Úndim)r%   r   r   Úrearrange_callables   &&, r   r   r   ™   sM   € ôf �fœeŸl™l×+Ò+Ü—’˜VÓ$ˆä3Ø�‰�WñØ ,ñÐñ ˜fÓ%Ð%r   )Ú
__future__r   Ú	functoolsÚtypingr   rk   Úfunctorch.dimr   Ú_parsingr   r   r   r	   r
   Úcollections.abcr   r   Ú__all__Ú	lru_cacherh   r   r   r   r   Ú<module>rx      sT   ðÝ "ã Ý  ã Ý ÷õ ÷ ß2àˆ-€ð ×Ò�SÓô}5ó ð}5÷@:&r   