ó
    Ÿ“,jì  ã            
       ó  • S SK Jr  S SKJrJrJrJrJr  S SKJ	r	  S SK
Jr  S SKJr  \" S5      r\\\S4   \\   4   r\" SS	9S
\S\S\\\\4   4S j5       rS\\   S
\S\\\\   4   4S jrS\S\4S jrS\S\\   S
\S\\   4S jrg)é    )Ú	lru_cache)ÚListÚSequenceÚTupleÚTypeVarÚUnion)ÚEinopsError)Úget_backend)ÚParsedExpressionÚTensor.é€   )ÚmaxsizeÚpatternÚopnameÚreturnc           
      óš  • U R                  5       n[        U5      n[        U5      [        U5      :w  a  [        SU SU  S35      eSU;  a  [        SU SU  S35      eU H?  nUS:w  d  M  [        R
                  " U5      u  pVU(       a  M,  [        SU SU SU  S35      e   UR                  S5      n[        U5      U-
  S-
  nXx-   n	XxU	4$ )	NzDuplicates in axes names in z(..., "z")Ú*zNo *-axis in zInvalid axis name z in é   )ÚsplitÚsetÚlenr	   r   Úcheck_axis_name_return_reasonÚindex)
r   r   ÚaxesÚaxes_setÚaxisÚis_validÚreasonÚn_axes_beforeÚn_axes_afterÚmin_axess
             ÚœC:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\einops/packing.pyÚanalyze_patternr#      sç   € ð �=‰=‹?€DÜ�4‹y€HÜ
ˆ4ƒy”C˜“MÓ!ÜÐ8¸¸ÀÈÀyÐPRÐSÓTÐTØ
�(ÓÜ˜M¨&¨°¸¸	ÀÐDÓEÐEÛˆØ�3�;Ü/×MÒMÈdÓSÑˆHß�8Ü!Ð$6°t°f¸DÀÀÈÐPWÈyÐXZÐ"[Ó\Ð\ñ	 ð
 —J‘J˜s“O€MÜ�t“9˜}Ñ,¨qÑ0€LØÑ+€HØ¨Ð0Ð0ó    Útensorsc                 óš  • [        US5      u  p#n[        U S   5      n/ n/ n[        U 5       H‹  u  p‰UR                  U	5      n
[	        U
5      U:  a  [        SU SU
 SU SU S3	5      e[	        U
5      U-
  nUR                  X¢U 5        UR                  UR                  U	/ U
SU QS	PX«S Q75      5        M�     UR                  XbS
9U4$ )a©  
Packs several tensors into one.
See einops tutorial for introduction into packing (and how it replaces stack and concatenation).

Parameters:
    tensors: tensors to be packed, can be of different dimensionality
    pattern: pattern that is shared for all inputs and output, e.g. "i j * k" or "batch seq *"

Returns:
    (packed_tensor, packed_shapes aka PS)

Example:
```python
>>> from numpy import zeros as Z
>>> inputs = [Z([2, 3, 5]), Z([2, 3, 7, 5]), Z([2, 3, 7, 9, 5])]
>>> packed, ps = pack(inputs, 'i j * k')
>>> packed.shape, ps
((2, 3, 71, 5), [(), (7,), (7, 9)])
```

In this example, axes were matched to: i=2, j=3, k=5 based on order (first, second, and last).
All other axes were 'packed' and concatenated.
PS (packed shapes) contains information about axes that were matched to '*' in every input.
Resulting tensor has as many elements as all inputs in total.

Packing can be reversed with unpack, which additionally needs PS (packed shapes) to reconstruct order.

```python
>>> inputs_unpacked = unpack(packed, ps, 'i j * k')
>>> [x.shape for x in inputs_unpacked]
[(2, 3, 5), (2, 3, 7, 5), (2, 3, 7, 9, 5)]
```

Read the tutorial for introduction and application scenarios.
Úpackr   zpacked tensor #z' (enumeration starts with 0) has shape z, while pattern z assumes at least z axesNéÿÿÿÿ)r   )	r#   r
   Ú	enumerateÚshaper   r	   ÚappendÚreshapeÚconcat)r%   r   r   r    r!   ÚbackendÚreshaped_tensorsÚpacked_shapesÚiÚtensorr*   Úaxis_after_packed_axess               r"   r'   r'   !   s  € ôH -<¸GÀVÓ,LÑ)€M ô ˜' !™*Ó%€Gà%'ÐØ!#€MÜ˜wÖ'‰	ˆØ—‘˜fÓ%ˆÜˆu‹:˜Ó ÜØ! ! Ð$KÈEÈ7ð S!Ø!( 	Ð);¸H¸:ÀUðLóð ô "% U£¨lÑ!:ÐØ×Ñ˜UÐ1GÐHÔIØ×Ñ §¡°Ð8u¸%ÀÀÐ:OÐ8uÐQSÐ8uÐV[Ð\sÐVtÑ8uÓ vÖwñ (ð �>‰>Ð*ˆ>Ð?ÀÐNÐNr$   Úxc                 ó$   • SnU  H  nX-  nM	     U$ )Nr   © )r4   Úresultr1   s      r"   Úprodr8   Z   s   € Ø€FÛˆØ‰Šñ à€Mr$   r2   r0   c                 óÐ  • [        USS9u  p4n[        U 5      nUR                  U 5      n[        U5      US-   U-   :w  a  [	        SU SU 35      eUnU V	s/ s H  n	SU	;   a  SO
[        U	5      PM     n
n	[        S U
 5       5      nUS:”  a  [	        SU SU S	35      eS
/[        U5      -  Xx   /-   nUS
:X  a$  [        U
SS 5       H  u  pÞXÍ   U-   XÍS-   '   M     OgU
R                  S5      n[        U5       H  nXÍ   X­   -   XÍS-   '   M     [        US-   [        U
5      5      SSS2    H  nUUS-      U
U   -
  UU'   M     USU nXxS-   S n[        SS5      4U-  n [        U5       VVs/ s H8  u  nnUR                  U / UQ[        XÍ   XÍS-      5      P7   / UQUQUQ75      PM:     snn$ s  sn	f s  snnf ! [         a  n[	        SU SUS    SU 35      UeSnAff = f)a¼  
Unpacks a single tensor into several by splitting over a selected axes.
See einops tutorial for introduction into packing (and how it replaces stack and concatenation).

Parameters:
    tensor: tensor to be unpacked
    packed_shapes: packed_shapes (aka PS) is a list of shapes that take place of '*' in each output.
        output will contain a single tensor for every provided shape
    pattern: pattern that is shared for input and all outputs, e.g. "i j * k" or "batch seq *",
        where * designates an axis to be unpacked

Returns:
    list of tensors

If framework supports views, results are views to the original tensor.

Example:
```python
>>> from numpy import zeros as Z
>>> inputs = [Z([2, 3, 5]), Z([2, 3, 7, 5]), Z([2, 3, 7, 9, 5])]
>>> packed, ps = pack(inputs, 'i j * k')
>>> packed.shape, ps
((2, 3, 71, 5), [(), (7,), (7, 9)])
```

In this example, axes were matched to: i=2, j=3, k=5 based on order (first, second, and last).
All other axes were 'packed' and concatenated.
PS (packed shapes) contains information about axes that were matched to '*' in every input.
Resulting tensor has as many elements as all inputs in total.

Packing can be reversed with unpack, which additionally needs PS (packed shapes) to reconstruct order.

```python
>>> inputs_unpacked = unpack(packed, ps, 'i j * k')
>>> [x.shape for x in inputs_unpacked]
[(2, 3, 5), (2, 3, 7, 5), (2, 3, 7, 9, 5)]
```

Read the tutorial for introduction and application scenarios.
Úunpack)r   r   zunpack(..., z)) received input of wrong dim with shape r(   c              3   ó>   #   • U  H  n[        US :H  5      v •  M     g7f)r(   N)Úint)Ú.0r4   s     r"   Ú	<genexpr>Úunpack.<locals>.<genexpr>•   s   é € Ð!QÒ8P°1¤# a¨2¡g§, ,Ò8Pùs   ‚z) received more than one -1 in z and can't infer dimensionsr   NzError during unpack(..., "z!"): could not split axis of size z into requested )r#   r
   r*   r   r	   r8   Úsumr)   r   ÚrangeÚslicer,   Ú	Exception)r2   r0   r   r   r    r!   r.   Úinput_shapeÚunpacked_axisÚp_shapeÚlengths_of_composed_axesÚn_unknown_composed_axesÚsplit_positionsr1   r4   Úunknown_composed_axisÚjÚshape_startÚ	shape_endÚslice_fillerÚelement_shapeÚes                         r"   r:   r:   a   s—  € ôR -<¸GÈHÑ,UÑ)€M ä˜&Ó!€GØ—-‘- Ó'€KÜ
ˆ;Ó˜=¨1Ñ,¨|Ñ;Ó;Ü˜L¨¨	Ð1ZÐ[fÐZgÐhÓiÐià&€MáanÓ*oÒanÐV]°°w³©2ÄDÈÃMÒ+QÑanÐÐ*oä!Ñ!QÑ8PÓ!QÓQÐØ Ó"ÜØ˜7˜)Ð#BÀ=À/ÐQlÐmó
ð 	
ð �cœC Ó.Ñ.°+Ñ2LÐ1MÑM€OØ !Ó#ÜÐ6°s¸Ð;Ö<‰DˆAØ%4Ñ%7¸!Ñ%;ˆO ™EÓ"ò =ð &>×%CÑ%CÀBÓ%GÐÜÐ,Ö-ˆAØ%4Ñ%7Ð:RÑ:UÑ%UˆO ™EÓ"ñ .äÐ,¨qÑ0´#Ð6NÓ2OÓPÑQUÐSUÐQUÔVˆAØ!0°°Q±Ñ!7Ð:RÐSTÑ:UÑ!UˆO˜AÓñ Wð ˜n˜}Ð-€KØ¨AÑ-Ð/Ð0€IÜ˜$ Ó%Ð'¨-Ñ7€Lðô %.¨mÔ$<ô
ò %=Ñ ��=ð �O‰OàÐY˜ÐY¤u¨_Ñ-?ÀÐUVÑQVÑAWÓ'XÑYÑZØ:�+Ð: Ð:°	Ñ:öñ
 %=ò
ð 	
ùò; +pùó:
øô ó äØ(¨¨	Ð1RÐSbÐceÑSfÐRgØ˜}˜oð/ó
ð ð	ûðús0   ÁF3Å"F> Å0?F8Æ/F> Æ8F> Æ>
G%ÇG Ç G%N)Ú	functoolsr   Útypingr   r   r   r   r   Úeinopsr	   Úeinops._backendsr
   Úeinops.parsingr   r   r<   ÚShapeÚstrr#   r'   r8   r:   r6   r$   r"   Ú<module>rX      sè   ðÝ ß 8Õ 8å Ý (Ý +á	�Ó	€àˆe�C˜�H‰o˜t C™yÐ(Ñ)€ñ �3Ñð1˜Sð 1¨#ð 1°%¸¸SÀ#¸Ñ2Fó 1ó ð1ð&6O�(˜6Ñ"ð 6O¨Sð 6O°U¸6À4ÈÁ;Ð;NÑ5Oô 6OðrˆEð �cô ð\�6ð \¨$¨u©+ð \Àð \ÈÈVÉõ \r$   