
    1;ji              
       ^   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UnionTypeVarTupleSequence)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
             H/root/voice-cloning/.venv/lib/python3.11/site-packages/einops/packing.pyanalyze_patternr#      s!    ==??D4yyH
4yyCMM!!SSSSSSTTT
(D&DDDDDEEE ] ]3;;/MdSSHf ]!"[t"["["["[PW"["["[\\\JJsOOMt99},q0L|+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 -<GV,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%:O8uQS8uV[\r\s\sVt8u8u v vwwww>>*>??NNr$   xc                     d}| D ]}||z  }|S )Nr    )r4   resultr1   s      r"   prodr8   [   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|           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*oV]w22DMM*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!Q1#a2g,,!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     
 
 
 != OOYYu_Q-?QRUVQVAW'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RuntimeError)r2   r0   r   r   r    r!   input_shapeunpacked_axislengths_of_composed_axesn_unknown_composed_axesr1   r4   unknown_composed_axisjr.   rE   rF   rG   rH   s   `             @@@@@r"   r:   r:   b   s   R -<GH,U,U,U)M<&!!G--''K
;=1,|;;;hhh[fhhiii&M*o*oan*o*o*o!!Q!Q8P!Q!Q!QQQ""m7mm=mmm
 
 	
 cC...+m2L1MMO!##6ss;<< 	< 	<DAq%4Q%7!%;OAE""	< &>%C%CB%G%G,-- 	V 	VA%4Q%7:RST:U%UOAE"",q0#6N2O2OPPQUQUSUQUV 	V 	VA!0Q!7:RST:U!UOAn}n-KMA-//0I$%%'-7L

 
 
 
 
 
 
 
 
 %.m$<$<
 
 
 	
  
 
 
/ / /SbceSf / /,/ /
 
 	

s   0G )G9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       ( ( ( ( ( ( + + + + + +			eCHotCy() 31S 1# 1%S#2F 1 1 1 1&6O(6" 6OS 6OU64;;N5O 6O 6O 6O 6OrE c    \
6 \
$u+ \
 \
V \
 \
 \
 \
 \
 \
r$   