§
    Ÿ²ÅjU+  ã                   óx  — d dl Z d dlZd dlmZmZmZmZ d dlZd dlmZmZm	Z	m
Z
 d dlmZ  ed¦  «        ddœdej        dee         d	efd
„¦   «         Zd„ Zd„ Ze	dej        e	         dededede
j        diZd„ Z e¦   «         Zde j        d	efd„Zdej        ej                 d	ej        ej                 fd„ZdS )é    N)ÚListÚOptionalÚSequenceÚUnion)ÚdeviceÚdtypeÚTensorÚtypes)Ú
exposed_inztorch.library)Úop_nameÚprototype_functionr   Úreturnc               ó"	  ‡‡— d}t          j        | ¦  «        Šˆfd„Šdt          fˆfd„}g }t          ¦   «         }d}t	          ‰j                             ¦   «         ¦  «        D �]\  }\  }	}
t          |
¦  «        s ‰d¦  «         |
j        t           j	        j
        k    r|s|                     d¦  «         d}|
j        t           j	        j        u r ‰d	|	› d
�¦  «         |
j        }t          |¦  «        t          k    r ||¦  «        }|t                               ¦   «         vr¦|j        t$          u rgt'          |¦  «        }d}|t                               ¦   «         v rd|› d�} ‰d	|	› d|
j        › d|› dt                               ¦   «         › d�	¦  «         n1 ‰d	|	› d|
j        › dt                               ¦   «         › d�¦  «         t          |         }t          |¦  «        t          k    rH||k    rt)          d¦  «        ‚|                     d¦  «        rd|› d|t-          d¦  «        d…         › �}nE|	|v rA|                     d¦  «        s ‰d	|	› d�¦  «         d|› d|t-          d¦  «        d…         › �}|                     |	¦  «         |
j        t           j	        j        u r|                     |› d|	› �¦  «         �Œcd}|
j        �'t3          |
j        t4          t6          t8          f¦  «        rt          |
j        ¦  «        }nºt3          |
j        t          t:          j        f¦  «        rd|
j        › d�}nˆt3          |
j        t:          j        ¦  «        rEt          |
j        ¦  «        }d}|                     |¦  «        sJ ‚|t-          |¦  «        d…         }n$ ‰d	|	› dt          |
j        ¦  «        › d�¦  «         |                     |› d|	› d|› �¦  «         �Œ�||k    r3t          |¦  «        |z
  }t-          |¦  «        dk    r ‰|› d �¦  «         ‰j         }t          |¦  «        t          k    r ||¦  «        }tC          |‰¦  «        }|�|› d!d" "                    |¦  «        › d#|› �S d!d" "                    |¦  «        › d#|› �S )$aJ  Parses the schema of a given function with type hints. The schema is inferred from the
    function's type hints, and can be used to define a new operator.

    We make the following assumptions:

    * None of the outputs alias any of the inputs or each other.
    * | String type annotations "device, dtype, Tensor, types" without library specification are
      | assumed to be torch.*. Similarly, string type annotations "Optional, List, Sequence, Union"
      | without library specification are assumed to be typing.*.
    * | Only the args listed in ``mutates_args`` are being mutated. If ``mutates_args`` is "unknown",
      | it assumes that all inputs to the operator are being mutates.

    Callers (e.g. the custom ops API) are responsible for checking these assumptions.

    Args:
        prototype_function: The function from which to infer a schema for from its type annotations.
        op_name (Optional[str]): The name of the operator in the schema. If ``name`` is None, then the
            name is not included in the inferred schema. Note that the input schema to
            ``torch.library.Library.define`` requires a operator name.
        mutates_args ("unknown" | Iterable[str]): The arguments that are mutated in the function.

    Returns:
        The inferred schema.

    Example:
        >>> def foo_impl(x: torch.Tensor) -> torch.Tensor:
        >>>     return x.sin()
        >>>
        >>> infer_schema(foo_impl, op_name="foo", mutates_args={})
        foo(Tensor x) -> Tensor
        >>>
        >>> infer_schema(foo_impl, mutates_args={})
        (Tensor x) -> Tensor
    Úunknownc                 ó0   •— t          d| › d‰› d�¦  «        ‚)Nzinfer_schema(func): z Got func with signature ú))Ú
ValueError)ÚwhatÚsigs    €úLC:\Projects\Historical\venv\Lib\site-packages\torch/_library/infer_schema.pyÚerror_fnzinfer_schema.<locals>.error_fn9   s+   ø€ ÝØL 4ÐLÐLÀcÐLÐLÐLñ
ô 
ð 	
ó    Úannotation_typec                 ór   •— 	 t          | ¦  «        S # t          $ r} ‰d| › d�¦  «         Y d }~d S d }~ww xY w)NzUnsupported type annotation z. It is not a type.)ÚevalÚ	Exception)r   Úer   s     €r   Úconvert_type_stringz)infer_schema.<locals>.convert_type_string>   su   ø€ ð	Ý˜Ñ(Ô(Ð(øÝð 	ð 	ð 	ØˆHØS¨ÐSÐSÐSñô ð ð ð ð ð ð ð øøøøð	øøøs   ƒ ’
6œ1±6Fz>We do not support positional-only args, varargs, or varkwargs.Ú*Tz
Parameter z must have a type annotation.z

zFor example, z.

z has unsupported type z]. We do not support Tuple inputs in schema. As a workaround, please try to use List instead. zThe valid types are: ú.ú. The valid types are: zomutates_args must either be a sequence of the names of the arguments that are mutated or the string 'unknown'. r	   zTensor(az!)NzM is in mutable_args but only Tensors or collections of Tensors can be mutatedú ú"ztorch.z' has an unsupported default value type z;. Please file an issue on GitHub so we can prioritize this.ú=r   z» in mutates_args were not found in the custom op's signature. mutates_args should contain the names of all args that the custom op mutates, or just the string 'unknown' if you don't know.ú(ú, z) -> )#ÚinspectÚ	signatureÚstrÚsetÚ	enumerateÚ
parametersÚitemsÚsupported_paramÚkindÚ	ParameterÚKEYWORD_ONLYÚappendÚ
annotationÚemptyÚtypeÚSUPPORTED_PARAM_TYPESÚkeysÚ
__origin__ÚtupleÚtuple_to_listr   Ú
startswithÚlenÚaddÚdefaultÚ
isinstanceÚintÚfloatÚboolÚtorchr   r   Úreturn_annotationÚparse_returnÚjoin)r   Úmutates_argsr   ÚUNKNOWN_MUTATESr   ÚparamsÚ	seen_argsÚsaw_kwarg_only_argÚidxÚnameÚparamr   Ú	list_typeÚexample_type_strÚschema_typeÚdefault_reprÚ
dtype_reprÚ	torch_dotÚmutates_args_not_seenrD   Úretr   r   s                        @@r   Úinfer_schemarW      sØ  øø€ ðT  €OÝ
Ô
Ð.Ñ
/Ô
/€Cð
ð 
ð 
ð 
ð 
ð
­Sð ð ð ð ð ð ð €FÝ‘”€IØÐÝ'¨¬×(<Ò(<Ñ(>Ô(>Ñ?Ô?ð HBñ HBÑˆ‰]ˆd�EÝ˜uÑ%Ô%ð 	WØˆHÐUÑVÔVÐVàŒ:�Ô*Ô7Ò7Ð7à%ð *Ø—’˜cÑ"Ô"Ð"Ø%)Ð"àÔ�wÔ0Ô6Ð6Ð6ØˆHÐE $ÐEÐEÐEÑFÔFÐFð  Ô*ˆÝ�Ñ Ô ¥CÒ'Ð'Ø1Ð1°/ÑBÔBˆOàÕ"7×"<Ò"<Ñ">Ô">Ð>Ð>ØÔ)­UÐ2Ð2Ý)¨/Ñ:Ô:�	Ø#)Ð àÕ 5× :Ò :Ñ <Ô <Ð<Ð<Ø'G°yÐ'GÐ'GÐ'GÐ$Ø�ðL ð Lð L¸UÔ=Mð Lð Là'ðLð Lõ -B×,FÒ,FÑ,HÔ,HðLð Lð Lñô ð ð ð �ðL ð Lð L¸UÔ=Mð Lð LÝ,A×,FÒ,FÑ,HÔ,HðLð Lð Lñô ð õ
 ,¨OÔ<ˆÝ�ÑÔ¥Ò$Ð$Ø˜Ò.Ð.Ý ðOñô ð ð ×%Ò% hÑ/Ô/ð NØM¨ÐMÐM°½CÀ¹M¼M¸N¸NÔ0KÐMÐM�øØ�\Ð!Ð!Ø×)Ò)¨(Ñ3Ô3ð Ø�Øt ÐtÐtÐtñô ð ð J SÐIÐI¨K½¸H¹¼¸¸Ô,GÐIÐIˆKØ�Š�dÑÔÐØŒ=�GÔ-Ô3Ð3Ð3Ø�MŠM˜[Ð1Ð1¨4Ð1Ð1Ñ2Ô2Ð2Ñ2àˆLØŒ}Ð$­
°5´=Å3ÍÍtÐBTÑ(UÔ(UÐ$Ý" 5¤=Ñ1Ô1��Ý˜EœM­Cµ´Ð+>Ñ?Ô?ð Ø3 5¤=Ð3Ð3Ð3��Ý˜EœM­5¬;Ñ7Ô7ð 	Ý  ¤Ñ/Ô/�
Ø$�	Ø!×,Ò,¨YÑ7Ô7Ð7Ð7Ð7Ø)­#¨i©.¬.Ð*:Ð*:Ô;��à�ðQ ð Qð QÍdÐSXÔS`ÑNaÔNað Qð Qð Qñô ð ð �MŠM˜[Ð@Ð@¨4Ð@Ð@°,Ð@Ð@ÑAÔAÐAÑAØ�Ò&Ð&Ý # LÑ 1Ô 1°IÑ =ÐÝÐ$Ñ%Ô%¨Ò)Ð)ØˆHØ(ð Vð Vð Vñô ð ð Ô-ÐÝÐÑÔ¥#Ò%Ð%Ø/Ð/Ð0AÑBÔBÐÝ
Ð(¨(Ñ
3Ô
3€CØÐØÐ9Ð9˜DŸIšI fÑ-Ô-Ð9Ð9°CÐ9Ð9Ð9Ø,ˆt�yŠy˜Ñ Ô Ð,Ð, sÐ,Ð,Ð,r   c                 ól  ‡— | ‰ft           j        |          ‰› d�fg}d„ }|r*|                     ˆfd„ || ¦  «        D ¦   «         ¦  «         |r:|                     ˆfd„ |t           j        |          ¦  «        D ¦   «         ¦  «         |r*|                     ˆfd„ || ¦  «        D ¦   «         ¦  «         |S )Nú?c                 óJ   — t           j        |          t           j        |          gS ©N)Útypingr   r   )Útyps    r   Úderived_seq_typesz(derived_types.<locals>.derived_seq_types¬   s    € åŒO˜CÔ ÝŒK˜Ôð
ð 	
r   c              3   ó&   •K  — | ]}|‰› d �fV — ŒdS )z[]N© ©Ú.0Úseq_typÚcpp_types     €r   ú	<genexpr>z derived_types.<locals>.<genexpr>³   s?   øè è € ð 
ð 
Ø+2ˆW˜�o�o�oÐ&ð
ð 
ð 
ð 
ð 
ð 
r   c              3   ó&   •K  — | ]}|‰› d �fV — ŒdS )z?[]Nr`   ra   s     €r   re   z derived_types.<locals>.<genexpr>·   sE   øè è € ð 
ð 
àð ˜Ð&Ð&Ð&Ð'ð
ð 
ð 
ð 
ð 
ð 
r   c              3   óF   •K  — | ]}t           j        |         ‰› d �fV — ŒdS )z[]?N)r\   r   ra   s     €r   re   z derived_types.<locals>.<genexpr>¼   sL   øè è € ð 
ð 
àõ Œ_˜WÔ%¨(Ð'7Ð'7Ð'7Ð8ð
ð 
ð 
ð 
ð 
ð 
r   )r\   r   Úextend)Ú	base_typerd   Ú	list_baseÚoptional_base_listÚoptional_list_baseÚresultr^   s    `     r   Úderived_typesrn   ¤   s9  ø€ ð 
�HÐÝ	Œ˜Ô	#¨ ^ ^ ^Ð4ð€Fð

ð 
ð 
ð ð 
Ø�Šð 
ð 
ð 
ð 
Ø6GÐ6GÈ	Ñ6RÔ6Rð
ñ 
ô 
ñ 	
ô 	
ð 	
ð ð 
Ø�Šð 
ð 
ð 
ð 
à,Ð,­V¬_¸YÔ-GÑHÔHð
ñ 
ô 
ñ 	
ô 	
ð 	
ð ð 
Ø�Šð 
ð 
ð 
ð 
à,Ð,¨YÑ7Ô7ð
ñ 
ô 
ñ 	
ô 	
ð 	
ð €Mr   c                  ó$  — t           ddddft          ddddft          ddddft          ddddft          ddddft
          j        ddddft          d	dddft          d
dddfg} g }| D ]}| 	                    t          |Ž ¦  «         Œt          |¦  «        S )Nr	   TFÚSymIntrA   rB   r)   ÚScalarÚ
ScalarTypeÚDevice)r	   r@   rA   rB   r)   r
   ÚNumberr   r   rh   rn   Údict)Údatarm   Úlines      r   Úget_supported_param_typesrx   Ã   s¹   € õ 
�˜4  uÐ-Ý	ˆh˜˜e TÐ*Ý	�˜˜u dÐ+Ý	ˆv�t˜U DÐ)Ý	ˆe�U˜E 5Ð)Ý	Œ�x  u¨eÐ4Ý	�˜e U¨EÐ2Ý	�˜5 %¨Ð/ð
€Dð €FØð ,ð ,ˆØ�Š•m TÐ*Ñ+Ô+Ð+Ð+Ý�‰<Œ<Ðr   r	   zTensor[]rp   rA   rB   rq   c                 óº  — | €dS | t           j        j        u r |d¦  «         t          j        | ¦  «        }|t
          ur?| t                               ¦   «         vr |d| › dt          › d�¦  «         t          |          S t          j        | ¦  «        }|D ]"}|t          vr |d| › dt          › d�¦  «         Œ#dd 	                    d„ |D ¦   «         ¦  «        z   d	z   S )
Nz()z7No return type annotation was provided. Please add one.zReturn has unsupported type r!   r    r%   r&   c                 ó(   — g | ]}t           |         ‘ŒS r`   )ÚSUPPORTED_RETURN_TYPES)rb   Úargs     r   ú
<listcomp>z parse_return.<locals>.<listcomp>÷   s   € ÐHÐHÐH¸CÕ2°3Ô7ÐHÐHÐHr   r   )
r'   r0   r4   r\   Ú
get_originr9   r{   r7   Úget_argsrF   )r3   r   ÚoriginÚargsr|   s        r   rE   rE   ß   sA  € ØÐØˆtà•WÔ&Ô,Ð,Ð,ØˆÐJÑKÔKÐKåÔ˜zÑ*Ô*€FØ•UÐÐØÕ3×8Ò8Ñ:Ô:Ð:Ð:ØˆHðB¨zð Bð BÝ(>ðBð Bð Bñô ð õ & jÔ1Ð1åŒ?˜:Ñ&Ô&€DØð ð ˆØÕ,Ð,Ð,ØˆHðB¨zð Bð BÝ(>ðBð Bð Bñô ð øð
 �—’ÐHÐHÀ4ÐHÑHÔHÑIÔIÑIÈCÑOÐOr   rN   c                 óT   — | j         t          j        j        t          j        j        fv S r[   )r/   r'   r0   ÚPOSITIONAL_OR_KEYWORDr1   )rN   s    r   r.   r.   ý   s(   € ØŒ:ÝÔÔ/ÝÔÔ&ðð ð r   Ú
tuple_typec                 ó�  — t          | dd¦  «        }| t          j        u s|dk    s|€t          j        S t	          |¦  «        dk    rt          j        |d                  S t	          |¦  «        dk    r'|d         t
          u rt          j        |d                  S t          j        t          j        t          |¦  «                          S )z}
    Convert `tuple_type` into a list type with the same type arguments. Assumes that `tuple_type` is typing.Tuple type.
    Ú__args__Nr`   é   r   é   )Úgetattrr\   ÚTupler   r<   ÚEllipsisr   r9   )r„   Ú	type_argss     r   r:   r:     s§   € õ ˜
 J°Ñ5Ô5€Ið •V”\Ð!Ð! Y°"¢_ _¸	Ð8IåŒ{ÐÝ	ˆY‰Œ˜1Ò	Ð	åŒ{˜9 Qœ<Ô(Ð(Ý	ˆY‰Œ˜1Ò	Ð	 ¨1¤µÐ!9Ð!9ÝŒ{˜9 Qœ<Ô(Ð(åŒ{�6œ<­¨iÑ(8Ô(8Ô9Ô:Ð:r   )r'   r\   r   r   r   r   rC   r   r   r	   r
   Útorch.utils._exposed_inr   ÚCallabler)   rW   rn   rx   r@   rA   rB   rt   r{   rE   r6   r0   r.   ÚTyperŠ   r:   r`   r   r   ú<module>r�      s·  ðð €€€Ø €€€Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2à €€€Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ø .Ð .Ð .Ð .Ð .Ð .ð €ˆOÑÔð "ðT-ð T-ð T-ØœðT-ð
 �cŒ]ðT-ð 	ðT-ð T-ð T-ñ ÔðT-ðnð ð ð>ð ð ð& ˆHØ
„K�Ô˜ØˆØ	ˆ7Øˆ&Ø	„L�(ðÐ ðPð Pð Pð6 2Ð1Ñ3Ô3Ð ð˜7Ô,ð °ð ð ð ð ð;˜fœk¨&¬,Ô7ð ;¸F¼KÈÌÔ<Tð ;ð ;ð ;ð ;ð ;ð ;r   