
    3j                        % S SK Jr  S SKrS SKr\R                  " \5      r0 rS\S'         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SS jr      SS jrSS jrg)    )annotationsNz2dict[torch._ops.OpOverload, torch._ops.OpOverload]_manual_out_variant_registryc                    U[         U '   g)z0Register a functional op -> out variant mapping.N)r   )functional_opout_ops     U/home/wildlama/miniconda3/lib/python3.13/site-packages/torch/_library/_out_variant.pyregister_out_variantr	      s    
 39 /    c                ,    [         R                  U 5      $ )z;Return the manually registered out variant for op, or None.)r   get)ops    r   lookup_manual_out_variantr      s     (++B//r
   c                    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     r   	<genexpr>!_is_functional.<locals>.<genexpr>'   s     <+;C<<+;s   )namesplitendswithany	arguments)schemaop_names     r   _is_functionalr!      sK    
 kk%b)G<6+;+;<<<<r
   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_matchr1   .   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_returnsr7   A   s    
 6>>a
6>>c,// 5>>!S^^%;>>$$(A(AA	 6
 r
   c                    U R                   nUR                   Vs/ s H!  n[        U5      (       d  M  UR                  PM#     sn$ s  snf )z5Get the names of out arguments for an out variant op.)_schemar   r$   r   )r   r   r   s      r   get_out_arg_namesr:   U   s8    ^^F & 0 0I 0OC4HHCHH 0IIIs
   AA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)r9   r!   RuntimeError	namespacer   r   getattrtorchops	overloadsTagout_varianttagsr1   r   r$   r&   r3   r7   )
r   r   r>   r    torch_packetoverload_name	candidatecandidate_schemar   r5   s
             r   to_out_variantrJ   [   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.)rJ   _get_out_variants_infoAssertionError)r   expected_out_opr   tagged_infos       r   check_out_variantrP      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   r<   z  - z: 
)r>   r9   r   r   r?   r@   rA   rB   rC   rD   rE   appendjoin)r   r>   r    rF   overloads_inforG   rH   s          r   rL   rL      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._ops.OpOverloadr   rV   returnNone)r   rV   rW   ztorch._ops.OpOverload | None)r   torch._C.FunctionSchemarW   bool)r   ztorch._C.ArgumentrW   rZ   )r+   rY   r,   rY   rW   rZ   )r   rY   r5   zlist[torch._C.Argument]rW   rZ   )r   rV   rW   z	list[str])r   rV   rN   rV   rW   rX   )rW   r(   )
__future__r   loggingr@   	getLogger__name__logr   __annotations__r	   r   r!   r$   r1   r7   r:   rJ   rP   rL    r
   r   <module>rb      s    "   !
 TV P U9(9!9 
900!0=B%% 
&#) 
(J.b
(
;P
	
6%r
   