Ë
    g^(hš0  ã                   ó®  — d dl Z d dlZd dlZd dlmZ d dl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j                  Z ed«      ddœdej                  d	ee   d
efd„«       Zdeeej$                  f   dedededef
d„Zd„ Ze
dej,                  e
   dee
   dedededej4                  diZd„ Z e«       Zdej<                  d
efd„Zdee    d
ee   fd„Z!y)é    N)ÚGenericAlias)ÚOptionalÚUnion)ÚdeviceÚdtypeÚTensorÚtypes)Ú
exposed_inztorch.library)Úop_nameÚprototype_functionr   Úreturnc               óh	  ‡‡‡‡‡‡‡— d}| j                   ŠdŠt        j                  | «      Šˆfd„Šdt        fˆˆˆfd„Šdt        t
        t        t           t        f   df   dt        t        t        j                  df   t        f   fˆfd	„Šd
t
        t        t           t        f   dt        t        j                  t        f   fˆˆfd„Šg }t        «       }d}t        ‰j                  j                  «       «      D �]3  \  }\  }}	t        |	«      s ‰d«       |	j                   t        j"                  j$                  k(  r|s|j'                  d«       d}|	j(                  t        j"                  j*                  u r ‰d|› d�«        ‰|	j(                  «      \  }
}|
t,        vr›|
j.                  t        u r[t1        |
«      }d}|t,        j3                  «       v rd|› d�} ‰d|› d|	j(                  › d|› dt,        j3                  «       › d�	«       n. ‰d|› d|	j(                  › dt,        j3                  «       › d�«       t,        |
   }t        |«      t        k(  r6||k7  rt5        d«      ‚|j7                  d«      rJd|› d|t9        d«      d › �}n5||v r1|j7                  d«      s ‰d|› d�«       d|› d|t9        d«      d › �}|j;                  |«       |	j<                  t        j"                  j*                  u r|j'                  |› d|› �«       �Œd}|	j<                  �%t?        |	j<                  t@        tB        t        f«      rt        |	j<                  «      }nºt?        |	j<                  t        tD        jF                  f«      rd |	j<                  › d �}nt?        |	j<                  tD        jH                  «      r9t        |	j<                  «      }d!}|j7                  |«      sJ ‚|t9        |«      d }n" ‰d|› d"t        |	j<                  «      › d#�«       |j'                  |› d|› d$|› �«       �Œ6 ||k7  r't        |«      |z
  }t9        |«      d%kD  r ‰|› d&�«        ‰‰jJ                  «      \  }}tM        |‰«      }|�|› d'd(jO                  |«      › d)|› �S d'd(jO                  |«      › 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
    ÚunknownNc                 ó(   •— t        d| › d‰› d�«      ‚)Nzinfer_schema(func): z Got func with signature ú))Ú
ValueError)ÚwhatÚsigs    €úY/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/_library/infer_schema.pyÚerror_fnzinfer_schema.<locals>.error_fnD   s    ø€ ÜÐ/°¨vÐ5NÈsÈeÐSTÐUÓVÐVó    Úannotation_typec                 óV   •— 	 t        | ‰‰«      S # t        $ r  ‰d| › d�«       Y y w xY w)NzUnsupported type annotation z. It is not a type.)ÚevalÚ	Exception)r   r   Ú
pf_globalsÚ	pf_localss    €€€r   Úconvert_type_stringz)infer_schema.<locals>.convert_type_stringG   s<   ø€ ð	Ü˜¨°YÓ?Ð?øÜò 	ÙØ.¨Ð.?Ð?RÐSöð	ús   ƒ �(§(Útys.r   c                 ó‚   •— g }d}| D ]#  } ‰|«      \  }}|j                  |«       ||z  }Œ% |rt        |«      dfS | dfS )NFT)ÚappendÚtuple)r   ÚresÚchangedÚtyÚ
ty_changedÚunstringify_types        €r   Úunstringify_typesz'infer_schema.<locals>.unstringify_typesO   s_   ø€ ð ˆØˆØò 	"ˆBÙ-¨bÓ1‰NˆB�
Ø�J‰J�rŒNØ�zÑ!‰Gð	"ñ Ü˜“:˜tÐ#Ð#à˜�:Ðr   r%   c                 óÊ   •— t        | t        «      r
 ‰| «      dfS t        j                  | «      x}r. ‰t        j                  | «      «      \  }}|rt        ||«      dfS | dfS )NTF)Ú
isinstanceÚstrÚtypingÚ
get_originÚget_argsr   )r%   ÚoriginÚargsÚargs_changedr   r(   s       €€r   r'   z&infer_schema.<locals>.unstringify_type]   sl   ø€ ô �bœ#ÔÙ& rÓ*¨DÐ0Ð0Ü×(Ñ(¨Ó,Ð,ˆVÐ,Ù!2´6·?±?À2Ó3FÓ!GÑˆD�,ÙÜ# F¨DÓ1°4Ð7Ð7à�5ˆyÐr   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!)zM 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) -> )(Ú__globals__ÚinspectÚ	signaturer+   r"   r   ÚtypeÚobjectr,   ÚAnyÚboolÚsetÚ	enumerateÚ
parametersÚitemsÚsupported_paramÚkindÚ	ParameterÚKEYWORD_ONLYr!   Ú
annotationÚemptyÚSUPPORTED_PARAM_TYPESÚ
__origin__Útuple_to_listÚkeysr   Ú
startswithÚlenÚaddÚdefaultr*   ÚintÚfloatÚtorchr   r   Úreturn_annotationÚparse_returnÚjoin)r   Úmutates_argsr   ÚUNKNOWN_MUTATESÚ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_seenrV   Úretr   r   r   r   r   r'   r(   s                        @@@@@@@r   Úinfer_schemarj      sÆ  þ€ ðT  €OØ#×/Ñ/€JØ€Iô ×
Ñ
Ð.Ó
/€CôWð¬S÷ ðÜ”5œœf™¤sÐ*Ñ+¨SÐ0Ñ1ðä	Œu”V—Z‘Z �_Ñ%¤tÐ+Ñ	,õðœU¤4¬¡<´Ð#4Ñ5ð ¼%ÄÇ
Á
ÌDÐ@PÑ:Qö ð €FÜ“€IØÐÜ'¨¯©×(<Ñ(<Ó(>Ó?ó FBÑˆ‰]ˆd�EÜ˜uÔ%ÙÐUÔVà�:‰:œ×*Ñ*×7Ñ7Ò7á%Ø—‘˜cÔ"Ø%)Ð"à×Ñœw×0Ñ0×6Ñ6Ñ6Ù�z $ Ð'DÐEÔFñ .¨e×.>Ñ.>Ó?Ñˆ˜àÔ"7Ñ7Ø×)Ñ)¬UÑ2Ü)¨/Ó:�	Ø#)Ð àÔ 5× :Ñ :Ó <Ñ<Ø)6°y°kÀÐ'GÐ$ÙØ   Ð&<¸U×=MÑ=MÐ<Nð Orà'Ð(Ø+Ô,A×,FÑ,FÓ,HÐ+IÈðLõñ Ø   Ð&<¸U×=MÑ=MÐ<Nð O,Ü,A×,FÑ,FÓ,HÐ+IÈðLôô
 ,¨OÑ<ˆÜ�Ó¤Ò$Ø˜Ò.Ü ðOóð ð ×%Ñ% hÔ/Ø (¨¨¨R°¼CÀ»M¸NÐ0KÐ/LÐM‘Ø�\Ñ!Ø×)Ñ)¨(Ô3ÙØ   Ð&sÐtôð % S E¨¨K¼¸H»¸Ð,GÐ+HÐIˆKØ�‰�dÔØ�=‰=œG×-Ñ-×3Ñ3Ñ3Ø�M‰M˜[˜M¨¨4¨&Ð1Ö2àˆLØ�}‰}Ð$¬
°5·=±=Ä3ÌÌtÐBTÔ(UÜ" 5§=¡=Ó1‘Ü˜EŸM™M¬C´·±Ð+>Ô?Ø!" 5§=¡= /°Ð3‘Ü˜EŸM™M¬5¯;©;Ô7Ü  §¡Ó/�
Ø$�	Ø!×,Ñ,¨YÔ7Ð7Ð7Ø)¬#¨i«.Ð*:Ð;‘áØ   Ð&MÌdÐSX×S`ÑS`ÓNaÐMbð cPð Qôð �M‰M˜[˜M¨¨4¨&°°,°Ð@ÖAðMFBðN �Ò&Ü # LÓ 1°IÑ =ÐÜÐ$Ó%¨Ò)ÙØ(Ð)ð *Uð Vôñ ,¨C×,AÑ,AÓBÑÐ�qÜ
Ð(¨(Ó
3€CØÐØ�˜!˜DŸI™I fÓ-Ð.¨e°C°5Ð9Ð9Øˆt�y‰y˜Ó Ð!  s eÐ,Ð,r   Ú	base_typeÚcpp_typeÚ	list_baseÚoptional_base_listÚoptional_list_basec                 óp  ‡— | ‰ft         j                  |    ‰› d�fg}dt        t        t         j                  f   fd„}|r |j                  ˆfd„ || «      D «       «       |r1|j                  ˆfd„ |t         j                  |    «      D «       «       |r |j                  ˆfd„ || «      D «       «       |S )Nú?Útypc                 ó¶   — t         j                  |    t         j                  |    t        t        j
                  j                  | f«      t        t        | f«      fS ©N)r,   ÚSequenceÚListr   ÚcollectionsÚabcÚlist)rr   s    r   Úderived_seq_typesz(derived_types.<locals>.derived_seq_typesÐ   sF   € ä�O‰O˜CÑ Ü�K‰K˜ÑÜœŸ™×1Ñ1°C°6Ó:Üœ ˜vÓ&ð	
ð 	
r   c              3   ó,   •K  — | ]  }|‰› d �f–— Œ y­w)z[]N© ©Ú.0Úseq_typrl   s     €r   ú	<genexpr>z derived_types.<locals>.<genexpr>Ù   s!   øè ø€ ò 
Ø+2ˆW˜˜
 "�oÔ&ñ
ùó   ƒc              3   ó,   •K  — | ]  }|‰› d �f–— Œ y­w)z?[]Nr|   r}   s     €r   r€   z derived_types.<locals>.<genexpr>Ý   s%   øè ø€ ò 
àð ˜˜
 #Ð&Ô'ñ
ùr�   c              3   óN   •K  — | ]  }t         j                  |   ‰› d �f–— Œ y­w)z[]?N)r,   r   r}   s     €r   r€   z derived_types.<locals>.<genexpr>â   s.   øè ø€ ò 
àô �_‰_˜WÑ%¨(¨°3Ð'7Ô8ñ
ùs   ƒ"%)r,   r   r   r=   Ú_SpecialFormÚextend)rk   rl   rm   rn   ro   Úresultrz   s    `     r   Úderived_typesr‡   Ä   sÁ   ø€ ð 
�HÐÜ	�‰˜Ñ	#¨ z° ^Ð4ðP€Fð

œu¤T¬6×+>Ñ+>Ð%>Ñ?ó 
ñ Ø�‰ó 
Ù6GÈ	Ó6Rô
ô 	
ñ Ø�‰ó 
á,¬V¯_©_¸YÑ-GÓHô
ô 	
ñ Ø�‰ó 
á,¨YÓ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 ]  }|j                  t        |Ž «       Œ t        |«      S )Nr   TFÚSymIntrT   r@   r+   ÚScalarÚ
ScalarTypeÚDevice)r   rS   rT   r@   r+   r	   ÚNumberr   r   r…   r‡   Údict)Údatar†   Úlines      r   Úget_supported_param_typesr‘   é   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 %¨Ð/ð
R€Dð €FØò ,ˆØ�‰”m TÐ*Õ+ð,ä�‹<Ðr   r   zTensor[]r‰   rT   r@   rŠ   c                 óÀ  — | €y| t         j                  j                  u r |d«       t        j                  | «      }|t
        ur2| t        j                  «       vr |d| › dt        › d�«       t        |    S t        j                  | «      }|D ]  }|t        vsŒ |d| › dt        › d�«       Œ  ddj                  |D �cg c]  }t        |   ‘Œ c}«      z   dz   S c c}w )	Nz()z7No return type annotation was provided. Please add one.zReturn has unsupported type r4   r3   r8   r9   r   )
r;   rG   rJ   r,   r-   r"   ÚSUPPORTED_RETURN_TYPESrN   r.   rX   )rI   r   r/   r0   Úargs        r   rW   rW     sø   € ØÐØà”W×&Ñ&×,Ñ,Ñ,ÙÐJÔKä×Ñ˜zÓ*€FØ”UÑØÔ3×8Ñ8Ó:Ñ:ÙØ.¨z¨lð ;(Ü(>Ð'?¸qðBôô & jÑ1Ð1ä�?‰?˜:Ó&€DØò ˆØÔ,Ò,ÙØ.¨z¨lð ;(Ü(>Ð'?¸qðBõðð �—‘À4ÖH¸CÔ2°3Ó7ÒHÓIÑIÈCÑOÐOùÒHs   Â?C
r`   c                 ó‚   — | j                   t        j                  j                  t        j                  j                  fv S rt   )rF   r;   rG   ÚPOSITIONAL_OR_KEYWORDrH   )r`   s    r   rE   rE   $  s6   € Ø�:‰:Ü×Ñ×/Ñ/Ü×Ñ×&Ñ&ðð ð r   Ú
tuple_typec                 ó.  — t        | dd«      }| t        j                  u s| t        u s|dk(  s|€t        S t        |«      dk(  rt        |d      S t        |«      dk(  r|d   t        u rt        |d      S t        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"   ry   rP   ÚEllipsisr   )r—   Ú	type_argss     r   rM   rM   +  s–   € ô ˜
 J°Ó5€Ið 	”f—l‘lÑ"ØœÑØ˜Š?ØÐô ˆÜ	ˆY‹˜1Ò	ä�I˜a‘LÑ!Ð!Ü	ˆY‹˜1Ò	 ¨1¡´Ñ!9Ü�I˜a‘LÑ!Ð!ä”F—L‘L¤ yÓ!1Ñ2Ñ3Ð3r   )"rw   r;   r,   r	   r   r   r   rU   r   r   r   Útorch.utils._exposed_inr
   Ú_TestTensorÚCallabler+   rj   r=   r„   r@   r‡   r‘   rv   ry   rS   rT   r�   r“   rW   rK   rG   rE   r"   rM   r|   r   r   ú<module>r£      s?  ðã Û Û Ý ß "ã ß .Ó .Ý .ð
 �l‰l€ñ ˆOÓð "òn-ØŸ™ðn-ð
 �c‰]ðn-ð 	òn-ó ðn-ðb"Ø�T˜6×.Ñ.Ð.Ñ/ð"àð"ð ð"ð ð	"ð
 ó"òJð& ˆHØ
‡K�K�Ñ˜Øˆ�L�*ØˆØ	ˆ7Øˆ&Ø	‡L�L�(ðÐ òPñ6 2Ó3Ð ð˜7×,Ñ,ð °ó ð4˜d 5™kð 4¨d°4©jô 4r   