
    ]i                     t    % S SK r S SKrS SKJrJrJrJrJr  S SKJ	r	  Sr
\\S'    " S S5      r " S S	5      rg)
    N)ListOptionalSetTupleUnion)EinopsErroru   …	_ellipsisc                   ,    \ rS rSrSrS\4S jrS rSrg)AnonymousAxis
   zHImportant thing: all instances of this class are not equal to each othervaluec                     [        U5      U l        U R                  S::  a3  U R                  S:X  a  [        S5      e[        SU R                   35      eg )N   zENo need to create anonymous axis of length 1. Report this as an issuez0Anonymous axis should have positive length, not )intr   r   )selfr   s     K/mnt/rpi/tmp/demucs-venv-sys/lib/python3.13/site-packages/einops/parsing.py__init__AnonymousAxis.__init__   sO    Z
::?zzQ!"ijj!$TUYU_U_T`"abb	     c                 2    [        U R                  5       S3$ )Nz-axis)strr   )r   s    r   __repr__AnonymousAxis.__repr__   s    djj/"%((r   )r   N)	__name__
__module____qualname____firstlineno____doc__r   r   r   __static_attributes__ r   r   r   r   
   s    Rcc c)r   r   c            
           \ rS rSrSrSSS.S\S\S\4S jjrS	\4S
 jr	S	\4S jr
\SS\S\S	\\\4   4S jj5       r\S\S	\4S j5       rSrg)ParsedExpression   z
non-mutable structure that contains information about one side of expression (e.g. 'b c (h w)')
and keeps some information important for downstream
F)allow_underscoreallow_duplicates
expressionr$   r%   c                  ^ ^^^ ST l         S T l        [        5       T l        ST l        / T l        SU;   am  SU;  a  [        S5      e[        R                  US5      S:w  d  [        R                  US5      S:w  a  [        S5      eUR                  S[        5      nST l         S mUUUU 4S	 jnS nU H  nUS
;   aZ  Ub  U" U5        S nUS:X  a  Tb  [        S5      e/ mM.  US:X  a-  Tc  [        S5      eT R
                  R                  T5        S mMa  Mc  [        R                  U5      (       d  US[        4;   a  Uc  UnM  XV-  nM  [        SU S35      e   Tb  [        SU S35      eUb	  U" U5        g g )NF.z...z6Expression may contain dots only inside ellipsis (...)r      zUExpression may contain dots only inside ellipsis (...); only one ellipsis for tensor Tc                   > U TR                   ;   a#  T(       a  U S:X  d  T(       d  [        SU  S35      eU [        :X  af  TR                   R                  [        5        Tc'  TR                  R                  [        5        STl        g TR                  [        5        STl        g [        R                  U 5      nU(       a0  [        U 5      S:X  a!  Tc  TR                  R                  / 5        g  g TR                  U TS9u  p#U(       d  U(       d  [        SU  S	U 35      eU(       a  [        U 5      n TR                   R                  U 5        U(       a  STl        Tc  TR                  R                  U /5        g TR                  U 5        g )
N_z2Indexing expression contains duplicate dimension ""FTr   )r$   zInvalid axis identifier: 
)identifiersr   r	   addcompositionappendhas_ellipsis_parenthesizedr   	isdecimalr   check_axis_name_return_reasonr   has_non_unitary_anonymous_axes)x	is_numberis_axis_namereasonr%   r$   bracket_groupr   s       r   add_axis_name0ParsedExpression.__init__.<locals>.add_axis_name3   sW   D$$$(Q#X?O%(Z[\Z]]^&_``I~  $$Y/ ($$++I66;D3!((36:D3MM!,	Q1$,((//3  '+'I'I!^n'I'o$!\%(A!Bvh&OPP%a(A  $$Q':>D7 ($$++QC0!((+r   z() (zDAxis composition is one-level (brackets inside brackets not allowed))zBrackets are not balancedr+   zUnknown character ''z'Imbalanced parentheses in expression: "r,   )has_ellipsisr2   setr.   r5   r0   r   r   countreplacer	   r1   isalnum)r   r&   r$   r%   r;   current_identifiercharr:   s   ` ``   @r   r   ParsedExpression.__init__   s   "':>'%(U49+8:*J&!"Z[[yyU+q0CIIj#4NRS4S!k  $++E9=J $D-1 	,  	,D "Du}%1!"45%)"3;$0)*pqq$&MS[$,)*EFF$$++M:$(M	 !
 T""dsI.>&>%-)-&&.&!$7vQ"?@@) , $ G
|STUVV),- *r   returnc                     / nU R                    H9  n[        U[        5      (       d   S5       eU H  nUR                  U5        M     M;     U$ )Nzdoes not work with ellipsis)r0   
isinstancelistr1   )r   resultcomposed_axisaxiss       r   flat_axes_order ParsedExpression.flat_axes_orderq   sM    !--MmT22Q4QQ2%d# & . r   c                 z    U R                    H+  n[        U[        5      (       d  M  [        U5      S:  d  M+    g   g)Nr   TF)r0   rJ   rK   len)r   axess     r   has_composed_axes"ParsedExpression.has_composed_axesy   s1    $$D$%%#d)a- % r   namec                 ,   [         R                  U 5      (       d  gU S   S:X  d	  U S   S:X  a  U S:X  a  U(       a  gg[        R                  " U 5      (       a  [        R
                  " SU  3[        SS	9  U S
;   a  [        R
                  " S[        SS	9  g)N)Fznot a valid python identifierr   r+   )T )Fz8axis name should should not start or end with underscorez7It is discouraged to use axes names that are keywords:    )
stacklevel)rN   zQIt is discouraged to use 'axis' as an axis name and will raise an error in future)r   isidentifierkeyword	iskeywordwarningswarnRuntimeWarningFutureWarning)rV   r$   s     r   r4   .ParsedExpression.check_axis_name_return_reason   s    %%9!W^tBx3s{/T  &&MdVT" 
 xg! 
 r   c                 4    [         R                  U 5      u  pU$ )zs
Valid axes names are python identifiers except keywords,
and additionally should not start or end with underscore
)r"   r4   )rV   is_valid_reasons      r   check_axis_name ParsedExpression.check_axis_name   s     -JJ4Pr   )r0   r@   r2   r5   r.   N)F)r   r   r   r   r   r   boolr   r   rO   rT   staticmethodr   r4   rg   r   r    r   r   r"   r"      s    
 EJdi P.3 P.T P.]a P.d 4  C 4 TYZ^`cZcTd  , c d  r   r"   )r]   r_   typingr   r   r   r   r   einopsr   r	   r   __annotations__r   r"   r    r   r   <module>rn      s4      4 4 	3 ) )E Er   