
    ]i              
          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
             K/mnt/rpi/tmp/demucs-venv-sys/lib/python3.13/site-packages/einops/packing.pyanalyze_patternr#      s     ==?D4yH
4yCM!8yPRSTT
(M&	DEE3;/MMdSH8!$6tfDPWyXZ"[\\	 
 JJsOMt9},q0L+H00    tensorsc                    [        US5      u  p#n[        U S   5      n/ n/ n[        U 5       H  u  pU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                  XU 5        UR                  UR                  U	/ U
SU QS	PXS 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 -<GV,L)M '!*%G%'!#Mw'	f%u: !!$KE7 S!!(	);H:UL  "%Ul!:U1GHI8u%:O8uQS8uV[\sVt8u 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  pX   U-   XS-   '   M     OgU
R                  S5      n[        U5       H  nX   X   -   XS-   '   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   XS-      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     !Q8P1#a2g,,8Ps   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 -<GH,U)M&!G--'K
;=1,|;;L	1Z[fZghii&Man*oanV]w2DM+Qan*o!!Q8P!QQ"7)#B=/Qlm
 	
 cC..+2L1MMO!#6s;<DA%4%7!%;OE" = &>%C%CB%G,-A%4%7:R:U%UOE" .,q0#6N2OPQUSUQUVA!0Q!7:RST:U!UOA W n}-KA-/0I$%'-7L %.m$<
 %= = OOYYu_-?UVQVAW'XYZ:+::	:
 %=
 	
; +p:
  (	1RSbceSfRg}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  ( +		eCHotCy() 31S 1# 1%S#2F 1 1&6O(6" 6OS 6OU64;;N5O 6OrE c \6 \$u+ \ \V \r$   