
    N je                        S SK Jr  S SKrS SKr\R                  " \5      rS
S jrSS jr      SS jr	      SS jr
SS jr      SS jrSS	 jrg)    )annotationsNc                    U R                   R                  S5      S   nUR                  S5      (       a  g[        S U R                   5       5      (       + $ )zX
A schema is functional if no argument is written to and the name doesn't
end with '_'.
::_Fc              3  8   #    U  H  oR                   v   M     g 7fN)is_write).0args     l/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/torch/_library/_out_variant.py	<genexpr>!_is_functional.<locals>.<genexpr>   s     <+;C<<+;s   )namesplitendswithany	arguments)schemaop_names     r   _is_functionalr      sK    
 kk%b)G<6+;+;<<<<    c                X    U R                   S L=(       a    U R                   R                  $ r	   )
alias_infor
   )r   s    r   _is_mutable_argr      s     >>%A#..*A*AAr   c                   U R                    Vs/ s H  n[        U5      (       a  M  UPM     nnUR                    Vs/ s H  n[        U5      (       a  M  UPM     nn[        U5      [        U5      :w  a  g[        X45       Hk  u  pVUR                  UR                  :w  a    g[        UR                  5      [        UR                  5      :w  a    gUR                  UR                  :w  d  Mk    g   gs  snf s  snf )zOCompare two schemas by their non-mutable arguments (name, type, default value).FT)r   r   lenzipr   strtypedefault_value)schema_aschema_br   non_mutable_args_anon_mutable_args_babs          r   _signatures_matchr(      s    
 *2););X);#?SVCW#);X)1););X);#?SVCW#);X
#&8"99&;66QVVqvv;#aff+%??aoo- <  YXs   C1C1C6C6c                T   [        U R                  5      S:X  a  g[        U R                  5      [        U5      :w  a  g[        U R                  U5       HQ  u  p#UR                  b  UR                  c    gUR                  R                  UR                  R                  :w  d  MQ    g   g)zFOut variant must return either nothing or the mutable args themselves.r   TF)r   returnsr   r   
before_set)r   mutable_argsretr   s       r   _has_valid_out_variant_returnsr.   -   s    
 6>>a
6>>c,// 5>>!S^^%;>>$$(A(AA	 6
 r   c                   U R                   n[        U5      (       d  [        SU  SU 35      eU R                  nUR                  R                  S5      S   n[        [        [        R                  U5      U5      nUR                  5        H  n[        XE5      n[        R                  R                  UR                  ;  a  M8  UR                   n[        X5      (       d  MV  UR                   Vs/ s H  n[        U5      (       d  M  UPM     n	n[!        U	5      [!        UR"                  5      :w  a  M  [%        Xy5      (       d  [        SU SU 35      eUs  $    gs  snf )zM
Given a functional operator overload, return its corresponding out variant.
z#Failed to find out variant for op 'z&' as its schema is not functional. 
  r      zOut variant z^ has invalid returns. Expected either no returns or returns that alias the mutable args, got: N)_schemar   RuntimeError	namespacer   r   getattrtorchops	overloadsTagout_varianttagsr(   r   r   r   r*   r.   )
opr   r3   r   torch_packetoverload_name	candidatecandidate_schemar   r,   s
             r   to_out_variantr@   A   sS    ZZF&!!1" 6
 	
 Ikk%a(G7599i8'BL &//1L8	 99  	6$,, :: ,55
5C9MC5 	 
 |FNN 33-.>MMyk *()+  5 28 
s   0EEc           	         [        U 5      nUc%  [        U 5      n[        SU  SU=(       d    S 35      eX!:w  a  [        SU  SU SU S35      eg)	z
Checks that to_out_variant returns the expected out variant for a functional op.
Raises AssertionError if the out variant is not valid.
Nz#We did not find an out variant for a  . Some common mistakes include:
  1. The out variant is missing the torch.Tag.out_variant tag.
  2. The out variant is not an overload of the original op (e.g., 'op.out' or 'op.overload_out') 
  3. The out variant's input arguments does not match the functional op's signature (excluding the mutable args).
  4. The original operator is not functional.
Overloads tagged with out_variant:
z  (none)zto_out_variant(z) returned z, but expected z8. The out variant name does not match the functional op.)r@   _get_out_variants_infoAssertionError)functional_opexpected_out_opout_optagged_infos       r   check_out_variantrH   r   s     M*F~,];1- A3 (j)+
 	
  m_Kx @+, -EF
 	
 !r   c                   U R                   nU R                  R                  R                  S5      S   n[	        [	        [
        R                  U5      U5      n/ nUR                  5        HY  n[	        X55      n[
        R                  R                  UR                  ;   d  M8  UR                  SU SUR                   35        M[     SR                  U5      $ )zJCollect information about overloads tagged with out_variant for debugging.r   r0   z  - z: 
)r3   r1   r   r   r4   r5   r6   r7   r8   r9   r:   appendjoin)rD   r3   r   r<   overloads_infor=   r>   s          r   rB   rB      s    ''I##((..t4Q7G7599i8'BL "N%//1L8	99  INN2!!Dr):K:K9L"MN	 2 99^$$r   )r   torch._C.FunctionSchemareturnbool)r   ztorch._C.ArgumentrO   rP   )r"   rN   r#   rN   rO   rP   )r   rN   r,   zlist[torch._C.Argument]rO   rP   )r;   torch._ops.OpOverloadrO   ztorch._ops.OpOverload | None)rD   rQ   rE   rQ   rO   None)rO   r   )
__future__r   loggingr5   	getLogger__name__logr   r   r(   r.   r@   rH   rB    r   r   <module>rY      s    "   !=B%% 
&#) 
(.b
(
;P
	
6%r   