Ë
    øÿæiì  ã            
       ó  — 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y)é    )Ú	lru_cache)ÚListÚSequenceÚTupleÚTypeVarÚUnion)ÚEinopsError)Úget_backend)ÚParsedExpressionÚTensor.é€   )ÚmaxsizeÚpatternÚopnameÚreturnc           
      ó†  — | j                  «       }t        |«      }t        |«      t        |«      k7  rt        d|› d| › d�«      ‚d|vrt        d|› d| › d�«      ‚|D ]7  }|dk7  sŒ	t	        j
                  |«      \  }}|rŒ$t        d|› d|› d| › d�«      ‚ |j                  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/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/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�fÚÜ!Ð$6°t°f¸DÀÀÈÐPWÈyÐXZÐ"[Ó\Ð\ð	 ð
 —J‘J˜s“O€MÜ�t“9˜}Ñ,¨qÑ0€LØ˜|Ñ+€HØ˜,¨Ð0Ð0ó    Útensorsc                 ó¤  — t        |d«      \  }}}t        | d   «      }g }g }t        | «      D ]Œ  \  }}	|j                  |	«      }
t	        |
«      |k  rt        d|› d|
› d|› d|› d�	«      ‚t	        |
«      |z
  }|j                  |
|| «       |j                  |j                  |	g |
d| ¢d	‘|
|d ¢­«      «       ŒŽ |j                  ||¬
«      |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'   !   s  € ôH -<¸GÀVÓ,LÑ)€M�< ô ˜' !™*Ó%€Gà%'ÐØ!#€MÜ˜wÖ'‰	ˆˆ6Ø—‘˜fÓ%ˆÜˆu‹:˜Ò ÜØ! ! Ð$KÈEÈ7ð S!Ø!( 	Ð);¸H¸:ÀUðLóð ô "% U£¨lÑ!:ÐØ×Ñ˜U =Ð1GÐHÔIØ×Ñ §¡°Ð8u¸%ÀÀÐ:OÐ8uÐQSÐ8uÐV[Ð\rÐ\sÐVtÑ8uÓ vÕwð (ð �>‰>Ð*°ˆ>Ó?ÀÐNÐNr$   Úxc                 ó"   — d}| D ]  }||z  }Œ	 |S )Nr   © )r4   Úresultr1   s      r"   Úprodr8   Z   s   € Ø€FÛˆØ�!‰‰ð à€Mr$   r2   r0   c                 óÈ  — t        |d¬«      \  }}}t        | «      }|j                  | «      }t        |«      |dz   |z   k7  rt	        d|› d|› �«      ‚|}|D �	cg c]  }	d|	v rdn
t        |	«      ‘Œ }
}	t        d„ |
D «       «      }|dkD  rt	        d|› d|› d	�«      ‚d
gt        |«      z  ||   gz   }|d
k(  r%t        |
dd «      D ]  \  }}||   |z   ||dz   <   Œ nf|
j                  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  }	 t        |«      D ��cg c]9  \  }}|j                  | g |¢t        ||   ||dz      «      ‘­   g |¢|¢|¢­«      ‘Œ; c}}S c c}	w c c}}w # 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 r(   c              3   ó8   K  — | ]  }t        |d k(  «      –— Œ y­w)r(   N)Úint)Ú.0r4   s     r"   Ú	<genexpr>z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 Ó.Ñ.°+¸mÑ2LÐ1MÑM€OØ !Ò#ÜÐ6°s¸Ð;Ö<‰DˆAˆqØ%4°QÑ%7¸!Ñ%;ˆO˜A ™EÒ"ñ =ð &>×%CÑ%CÀBÓ%GÐÜÐ,Ö-ˆAØ%4°QÑ%7Ð:RÐSTÑ:UÑ%UˆO˜A ™EÒ"ð .äÐ,¨qÑ0´#Ð6NÓ2OÓPÑQUÐSUÐQUÔVˆAØ!0°°Q±Ñ!7Ð:RÐSTÑ:UÑ!UˆO˜AÒð Wð ˜n˜}Ð-€KØ˜M¨AÑ-Ð/Ð0€IÜ˜$ Ó%Ð'¨-Ñ7€Lðô %.¨mÔ$<ô
ñ %=Ñ ��=ð �O‰OàÐY˜ÐY¤u¨_¸QÑ-?ÀÐQRÐUVÑQVÑAWÓ'XÑYÑZØ:�+Ð: Ð:°	Ñ:õð
 %=ò
ð 	
ùò; +pùó:
øô ò äØ(¨¨	Ð1RÐSbÐceÑSfÐRgØ˜}˜oð/ó
ð ð	ûðús0   ÁF0Å F; Å.>F5Æ,F; Æ5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>rW      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$   