§
    �Åjì  ã            
       ó^  — d dl mZ d dlmZmZmZmZmZ d dlm	Z	 d dl
mZ d dlmZ  ed¦  «        Zeeedf         ee         f         Z ed¬	¦  «        d
ededeeeef         fd„¦   «         Zdee         d
edeeee         f         fd„Zdedefd„Zdedee         d
edee         fd„ZdS )é    )Ú	lru_cache)ÚListÚSequenceÚTupleÚTypeVarÚUnion)ÚEinopsError)Úget_backend)ÚParsedExpressionÚTensor.é€   )ÚmaxsizeÚpatternÚopnameÚreturnc           
      óÊ  — |                       ¦   «         }t          |¦  «        }t          |¦  «        t          |¦  «        k    rt          d|› d| › d�¦  «        ‚d|vrt          d|› d| › d�¦  «        ‚|D ]:}|dk    r2t	          j        |¦  «        \  }}|st          d|› d|› d| › d�¦  «        ‚Œ;|                     d¦  «        }t          |¦  «        |z
  dz
  }||z   }	|||	fS )	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:\Projects\Historical\venv\Lib\site-packages\einops/packing.pyÚanalyze_patternr#      s!  € ð �=Š=‰?Œ?€DÝ�4‰yŒy€HÝ
ˆ4�y„y•C˜‘M”MÒ!Ð!ÝÐS¸ÐSÐSÈÐSÐSÐSÑTÔTÐTØ
�(ÐÐÝÐD¨&ÐDÐD¸ÐDÐDÐDÑEÔEÐEØð ]ð ]ˆØ�3Š;ˆ;Ý/ÔMÈdÑSÔSÑˆH�fØð ]Ý!Ð"[°tÐ"[Ð"[ÀÐ"[Ð"[ÐPWÐ"[Ð"[Ð"[Ñ\Ô\Ð\øØ—J’J˜s‘O”O€MÝ�t‘9”9˜}Ñ,¨qÑ0€LØ˜|Ñ+€HØ˜,¨Ð0Ð0ó    Útensorsc                 ó  — t          |d¦  «        \  }}}t          | d         ¦  «        }g }g }t          | ¦  «        D ]¸\  }}	|                     |	¦  «        }
t	          |
¦  «        |k     rt          d|› d|
› d|› d|› d�	¦  «        ‚t	          |
¦  «        |z
  }|                     |
||…         ¦  «         |                     |                     |	g |
d|…         ¢d	‘|
|d…         ¢R ¦  «        ¦  «         Œ¹|                     ||¬
¦  «        |fS )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'   !   sm  € õH -<¸GÀVÑ,LÔ,LÑ)€M�< õ ˜' !œ*Ñ%Ô%€Gà%'ÐØ!#€MÝ˜wÑ'Ô'ð 	xð 	x‰	ˆˆ6Ø—’˜fÑ%Ô%ˆÝˆu‰:Œ:˜Ò Ð ÝðL !ð Lð LÈEð Lð LØ!(ðLð LØ<DðLð Lð Lñô ð õ "% U¡¤¨lÑ!:ÐØ×Ò˜U =Ð1GÐ#GÔHÑIÔIÐIØ×Ò §¢°Ð8u¸%ÀÀÀÔ:OÐ8uÐQSÐ8uÐV[Ð\rÐ\sÐ\sÔVtÐ8uÐ8uÑ vÔ vÑwÔwÐwÐwà�>Š>Ð*°ˆ>Ñ?Ô?ÀÐNÐNr$   Úxc                 ó   — d}| D ]}||z  }Œ|S )Nr   © )r4   Úresultr1   s      r"   Úprodr8   Z   s&   € Ø€FØð ð ˆØ�!‰ˆˆØ€Mr$   r2   r0   c           	      ó  ‡ ‡‡‡‡‡— t          |d¬¦  «        \  }}}t          ‰ ¦  «        Š‰                     ‰ ¦  «        }t          |¦  «        |dz   |z   k    rt	          d|› d|› �¦  «        ‚|}d„ |D ¦   «         }t          d„ |D ¦   «         ¦  «        }	|	dk    rt	          d|› d|› d	�¦  «        ‚d
gt          |¦  «        z  ||         gz   Š|	d
k    r/t          |dd…         ¦  «        D ]\  }
}‰|
         |z   ‰|
dz   <   Œn�|                     d¦  «        }t          |¦  «        D ]}
‰|
         ||
         z   ‰|
dz   <   Œt          |dz   t          |¦  «        ¦  «        ddd…         D ]}‰|dz            ||         z
  ‰|<   Œ|d|…         Š||dz   d…         Št          dd¦  «        f|z  Š	 ˆˆˆˆˆˆ fd„t          |¦  «        D ¦   «         S # t          $ r$}t	          d|› d‰d         › d|› �¦  «        |‚d}~ww xY w)a8  
    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 c                 ó8   — g | ]}d |v rd nt          |¦  «        ‘ŒS )r(   )r8   )Ú.0Úp_shapes     r"   ú
<listcomp>zunpack.<locals>.<listcomp>“   s+   € Ð*oÐ*oÐ*oÐV]°°w°°¨2¨2ÅDÈÁMÄMÐ*oÐ*oÐ*or$   c              3   ó<   K  — | ]}t          |d k    ¦  «        V — ŒdS )r(   N)Úint)r<   r4   s     r"   ú	<genexpr>zunpack.<locals>.<genexpr>•   s,   è è € Ð!QÐ!Q°1¥# a¨2¢g¡,¤,Ð!QÐ!QÐ!QÐ!QÐ!QÐ!Qr$   z) received more than one -1 in z and can't infer dimensionsr   Nr(   c                 ó    •— g | ]J\  }}‰                      ‰g ‰¢t          ‰|         ‰|d z            ¦  «        ‘R          g ‰¢|¢‰¢R ¦  «        ‘ŒKS )r   )r,   Úslice)	r<   r1   Úelement_shaper.   Ú	shape_endÚshape_startÚslice_fillerÚsplit_positionsr2   s	      €€€€€€r"   r>   zunpack.<locals>.<listcomp>°   sƒ   ø€ ð 
ð 
ð 
ñ !��=ð �OŠOàÐY˜ÐY¥u¨_¸QÔ-?ÀÐQRÐUVÑQVÔAWÑ'XÔ'XÐYÐYÔZØ:�+Ð: Ð:°	Ð:Ð:ñô ð
ð 
ð 
r$   zError during unpack(..., "z!"): could not split axis of size z into requested )r#   r
   r*   r   r	   Úsumr)   r   ÚrangerC   Ú	Exception)r2   r0   r   r   r    r!   Úinput_shapeÚunpacked_axisÚlengths_of_composed_axesÚn_unknown_composed_axesr1   r4   Úunknown_composed_axisÚjÚer.   rE   rF   rG   rH   s   `              @@@@@r"   r:   r:   a   s   øøøøøø€ õR -<¸GÈHÐ,UÑ,UÔ,UÑ)€M�< å˜&Ñ!Ô!€GØ—-’- Ñ'Ô'€KÝ
ˆ;ÑÔ˜=¨1Ñ,¨|Ñ;Ò;Ð;ÝÐh¨ÐhÐhÐ[fÐhÐhÑiÔiÐià&€Mà*oÐ*oÐanÐ*oÑ*oÔ*oÐå!Ð!QÐ!QÐ8PÐ!QÑ!QÔ!QÑQÔQÐØ Ò"Ð"ÝØm˜7ÐmÐmÀ=ÐmÐmÐmñ
ô 
ð 	
ð �c�C Ñ.Ô.Ñ.°+¸mÔ2LÐ1MÑM€OØ !Ò#Ð#ÝÐ6°s¸°sÔ;Ñ<Ô<ð 	<ð 	<‰DˆAˆqØ%4°QÔ%7¸!Ñ%;ˆO˜A ™EÑ"Ð"ð	<ð &>×%CÒ%CÀBÑ%GÔ%GÐÝÐ,Ñ-Ô-ð 	Vð 	VˆAØ%4°QÔ%7Ð:RÐSTÔ:UÑ%UˆO˜A ™EÑ"Ð"ÝÐ,¨qÑ0µ#Ð6NÑ2OÔ2OÑPÔPÐQUÐQUÐSUÐQUÔVð 	Vð 	VˆAØ!0°°Q±Ô!7Ð:RÐSTÔ:UÑ!UˆO˜AÑÐà˜n˜}˜nÔ-€KØ˜M¨AÑ-Ð/Ð/Ô0€IÝ˜$ Ñ%Ô%Ð'¨-Ñ7€Lðð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
õ %.¨mÑ$<Ô$<ð
ñ 
ô 
ð 	
øõ ð ð ð åð/¨ð /ð /ÐSbÐceÔSfð /ð /Ø,ð/ð /ñ
ô 
ð ð	øøøøðøøøs   Æ0G Ç
G>ÇG9Ç9G>N)Ú	functoolsr   Útypingr   r   r   r   r   Úeinopsr	   Úeinops._backendsr
   Úeinops.parsingr   r   r@   ÚShapeÚstrr#   r'   r8   r:   r6   r$   r"   ú<module>rZ      s¡  ðØ Ð Ð Ð Ð Ð Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8à Ð Ð Ð Ð Ð Ø (Ð (Ð (Ð (Ð (Ð (Ø +Ð +Ð +Ð +Ð +Ð +à	ˆ�Ñ	Ô	€àˆe�C˜�HŒo˜t CœyÐ(Ô)€ð €�3ÐÑÔð1˜Sð 1¨#ð 1°%¸¸SÀ#¸Ô2Fð 1ð 1ð 1ñ Ôð1ð&6O�(˜6Ô"ð 6O¨Sð 6O°U¸6À4ÈÄ;Ð;NÔ5Oð 6Oð 6Oð 6Oð 6OðrˆEð �cð ð ð ð ð\�6ð \¨$¨u¬+ð \Àð \ÈÈVÌð \ð \ð \ð \ð \ð \r$   