
    [Th0                        S SK r S SKrS SKrS SKJr  S SKJrJr  S SKrS SKJrJ	r	J
r
Jr  S SKJr  \R                  r\" S5      SS.S\R                  S	\\   S
\4S jj5       rS\\\R$                  4   S\S\S\S\4
S jrS r\
S\R,                  \
   S\\
   S\S\S\S\R4                  S0rS r\" 5       rS\R<                  S
\4S jrS\\    S
\\   4S jr!g)    N)GenericAlias)OptionalUnion)devicedtypeTensortypes)
exposed_inztorch.library)op_nameprototype_functionr   returnc               	  ^^^^^^^ SnU R                   mSm[        R                  " U 5      mU4S jmS[        4UUU4S jjmS[        [
        [        [           [        4   S4   S[        [        [        R                  S4   [        4   4U4S	 jjmS
[
        [        [           [        4   S[        [        R                  [        4   4UU4S jjm/ n[        5       nSn[        TR                  R                  5       5       GHf  u  nu  p[        U	5      (       d  T" S5        U	R                   [        R"                  R$                  :X  a  U(       d  UR'                  S5        SnU	R(                  [        R"                  R*                  L a  T" SU S35        T" U	R(                  5      u  pU
[,        ;  a  U
R.                  [        L a]  [1        U
5      nSnU[,        R3                  5       ;   a  SU S3nT" SU SU	R(                   SU S[,        R3                  5        S3	5        O.T" SU SU	R(                   S[,        R3                  5        S35        [,        U
   n[        U5      [        :X  a;  X:w  a  [5        S5      eUR7                  S5      (       a  SU SU[9        S5      S  3nO;X;   a6  UR7                  S5      (       d  T" SU S35        SU SU[9        S5      S  3nUR;                  U5        U	R<                  [        R"                  R*                  L a  UR'                  U SU 35        GM5  SnU	R<                  b*  [?        U	R<                  [@        [B        [        45      (       a  [        U	R<                  5      nO[?        U	R<                  [        [D        RF                  45      (       a  S U	R<                   S 3nO[?        U	R<                  [D        RH                  5      (       a>  [        U	R<                  5      nS!nUR7                  U5      (       d   eU[9        U5      S nO"T" SU S"[        U	R<                  5       S#35        UR'                  U SU S$U 35        GMi     X:w  a(  [        U5      U-
  n[9        U5      S%:  a  T" U S&35        T" TRJ                  5      u  nn[M        UT5      nUb  U S'S(RO                  U5       S)U 3$ S'S(RO                  U5       S)U 3$ )*a  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                 (   > [        SU  ST S35      e)Nzinfer_schema(func): z Got func with signature ))
ValueError)whatsigs    S/var/www/auris/envauris/lib/python3.13/site-packages/torch/_library/infer_schema.pyerror_fninfer_schema.<locals>.error_fnD   s     /v5NseSTUVV    annotation_typec                 X   >  [        U TT5      $ ! [         a    T" SU  S35         g f = f)NzUnsupported type annotation z. It is not a type.)eval	Exception)r   r   
pf_globals	pf_localss    r   convert_type_string)infer_schema.<locals>.convert_type_stringG   s<    	Y?? 	..??RS	s    ))tys.r   c                    > / nSnU  H"  nT" U5      u  p4UR                  U5        X$-  nM$     U(       a  [        U5      S4$ U S4$ )NFT)appendtuple)r!   reschangedty
ty_changedunstringify_types        r   unstringify_types'infer_schema.<locals>.unstringify_typesO   sV     B-b1NBJJrN!G  :t##:r   r'   c                    > [        U [        5      (       a
  T" U 5      S4$ [        R                  " U 5      =n(       a2  T" [        R                  " U 5      5      u  p#U(       a  [        X5      S4$ U S4$ )NTF)
isinstancestrtyping
get_originget_argsr   )r'   originargsargs_changedr   r*   s       r   r)   &infer_schema.<locals>.unstringify_type]   sk     b#&r*D00((,,V,!26??23F!GD#F14775y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_seenrZ   retr   r   r   r   r   r)   r*   s                        @@@@@@@r   infer_schemarn      s   T  O#//JI 

.
/CWS  5fs*+S01	uVZZ_%t+	,U4<#45 %

D@P:Q   FI'(<(<(>?]du%%UV::**777%c"%)"w00666z$'DEF .e.>.>?"77))U2)/:	#)  5 : : <<)6yk'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MN0K/LM!))(33 &st %SEKH,G+HIKd==G--333MM[M4&12L}}$
5==3tBT(U(U"5==1EMMC+>??!"5==/3EMM5;;77 /
$	!,,Y7777)#i.*:; &MdSXS`S`NaMb cP Q MM[M4&,@AM @N & #L 1I =$%)() *U V ,C,A,ABq
((
3C!DIIf-.eC599tyy !se,,r   	base_typecpp_type	list_baseoptional_base_listoptional_list_basec                   ^ U T4[         R                  U    T S34/nS[        [        [         R                  4   4S jnU(       a!  UR                  U4S jU" U 5       5       5        U(       a2  UR                  U4S jU" [         R                  U    5       5       5        U(       a!  UR                  U4S jU" U 5       5       5        U$ )N?typc                     [         R                  U    [         R                  U    [        [        R
                  R                  U 45      [        [        U 45      4$ N)r/   SequenceListr   collectionsabclist)rv   s    r   derived_seq_types(derived_types.<locals>.derived_seq_types   sF    OOC KK11C6:v&	
 	
r   c              3   0   >#    U  H  oT S 34v   M     g7f)z[]N .0seq_typrp   s     r   	<genexpr> derived_types.<locals>.<genexpr>   s      
6R7
"o&6Rs   c              3   2   >#    U  H  nUT S 34v   M     g7f)z?[]Nr   r   s     r   r   r      s$      
H 
#&'Hs   c              3   T   >#    U  H  n[         R                  U   T S 34v   M     g7f)z[]?N)r/   r   r   s     r   r   r      s-      
7 __W%(3'787s   %()r/   r   r   rA   _SpecialFormextend)ro   rp   rq   rr   rs   resultr~   s    `     r   derived_typesr      s     
H		#z^4PF

uT6+>+>%>? 
  
6G	6R
 	
  
,V__Y-GH
 	
  
,Y7
 	
 Mr   c                     [         SSSS4[        SSSS4[        SSSS4[        SSSS4[        SSSS4[
        R                  SSSS4[        S	SSS4[        S
SSS4/n / nU  H  nUR                  [        U6 5        M     [        U5      $ )Nr   TFSymIntrX   rD   r.   Scalar
ScalarTypeDevice)r   rW   rX   rD   r.   r	   Numberr   r   r   r   dict)datar   lines      r   get_supported_param_typesr      s     
4u-	heT*	ud+	vtUD)	eUE5)	xue4	eUE2	5%/
RD FmT*+ <r   r   zTensor[]r   rX   rD   r   c                    U c  gU [         R                  R                  L a  U" S5        [        R                  " U 5      nU[
        La4  U [        R                  5       ;  a  U" SU  S[         S35        [        U    $ [        R                  " U 5      nU H"  nU[        ;  d  M  U" SU  S[         S35        M$     SSR                  U Vs/ s H  n[        U   PM     sn5      -   S-   $ s  snf )	Nz()z7No return type annotation was provided. Please add one.zReturn has unsupported type r8   r7   r<   r=   r   )
r?   rK   rN   r/   r0   r$   SUPPORTED_RETURN_TYPESrR   r1   r\   )rM   r   r2   r3   args        r   r[   r[     s    W&&,,,JKz*FU388::.zl ;((>'?qB &j11??:&D,,.zl ;((>'?qB  4H4C2374HIICOOHs   C*
rd   c                     U R                   [        R                  R                  [        R                  R                  4;   $ rx   )rJ   r?   rK   POSITIONAL_OR_KEYWORDrL   )rd   s    r   rI   rI   $  s6    :://&&  r   
tuple_typec                 <   [        U SS5      nU [        R                  L d  U [        L d	  US:X  d  Uc  [        $ [        U5      S:X  a  [        US      $ [        U5      S:X  a  US   [        L a  [        US      $ [        [        R                  [        U5            $ )zu
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}   rT   Ellipsisr   )r   	type_argss     r   rQ   rQ   +  s     
J5I 	fll"? 	Y1	IaL!!	Y1	1!9IaL!!FLLy!1233r   )"r{   r?   r/   r	   r   r   r   rY   r   r   r   torch.utils._exposed_inr
   _TestTensorCallabler.   rn   rA   r   rD   r   r   rz   r}   rW   rX   r   r   r[   rO   rK   rI   r$   rQ   r   r   r   <module>r      s?       "  . . .
 ll O "n-n-
 c]n- 	n- n-b"T6.../"" " 	"
 "J& H
KKL*	7&	LL( P6 23 7,,  4d5k 4d4j 4r   