
    JTh                        S SK Jr  S SKJr  S SKJrJr  S SKJrJ	r	J
r
JrJrJrJr  \(       a  S SKJr  S SKJrJrJr  SrSS jr\" S	S
9 " S S5      5       rg)    )annotations)	dataclass)CallableTYPE_CHECKING)ArgumentBaseTyBaseTypeListTypeNativeFunctionOptionalTypeType)Sequence)BindingCType
NamedCTypez
	c                J    U R                   R                  R                  5       $ )N)funcnameunambiguous_name)fs    X/var/www/auris/envauris/lib/python3.13/site-packages/torchgen/executorch/api/unboxing.pyr   r      s    66;;''))    T)frozenc                      \ rS rSr% SrS\S'       SS jrSS.       SS jjr        SS	 jr          SS
 jr	          SS jr
Srg)Unboxing   a  
Takes a sequence of Bindings and unbox EValues to these Bindings. Return generated code that performs correct unboxing.
A sample generated code:
// aten::mul.out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
void mul_out(EValue** stack) {
    EValue& self = *stack[0];
    EValue& other = *stack[1];
    EValue& out = *stack[2];
    const torch::executor::Tensor & self_base = self.to<torch::executor::Tensor>();
    const torch::executor::Tensor & other_base = other.to<torch::executor::Tensor>();
    torch::executor::Tensor & out_base = out.to<torch::executor::Tensor>();

    EXECUTORCH_SCOPE_PROF("native_call_mul.out");
    torch::executor::mul_outf(self_base, other_base, out_base);


}
zCallable[..., NamedCType]argument_type_genc                   [        [        U5      5       Vs/ s H  nSX   R                   SU S3PM     nn/ nU H  n[        UR                  [
        5      (       d  [        SU 35      eUR                  nU R                  UR                  UR                  UR                  S9u  pxpUR                  U
5        UR                  U	5        UR                  UR                  U5      5        M     XC4$ s  snf )NzEValue& z
 = *stack[z];z7Unexpected argument type, expecting `Argument` but got mutable)rangelenr   
isinstanceargumentr   	Exceptionargumenttype_evalue_converttypeis_writeextendappend	with_name)selfargsi	code_listbinding_listargr$   unboxed_name_codedecls              r   convert_argumentsUnboxing.convert_arguments<   s     HMSQUYGWXGW!x~Zs"=GW	XCcllH55McUS  "%H*.*J*Jx}}h6G6G +K +'LT T"T"l ;<  && Ys   C3Fr   c               n   U R                  XUS9R                  n[        U[        5      (       a  U S3nU R	                  X%US9u  pgOk[        U[
        5      (       a  U S3nU R                  X%XS9u  pgO>[        U[        5      (       a  U S3nU R                  X%XS9u  pgO[        SU SU 35      eXTXg4$ )	a  
Takes in the type, name and mutability corresponding to an argument, and generates a tuple of:
(1) the C++ code necessary to unbox the argument
(2) A Binding corresponding to the newly created unboxed variable, including variable name and its CType
:param t: a `Type` of an argument
:param arg_name: argument name
:param mutable: boolean for whether this argument type is mutable
:return: unboxed result
)r    binds_base)arg_nameout_namectype_opt_out)r;   r<   tr=   	_list_outzCannot handle type z. arg_name: )
r   r'   r#   r	   _gen_code_base_typer   _gen_code_optional_typer
   _gen_code_list_typer%   )r,   r?   r;   r    r=   r<   r4   r5   s           r   r&   $Unboxing.argumenttype_evalue_convertP   s     &&q&JOOa"""5)H11!E 2 JD$ <(("8,H55! 6 JD$ 8$$"9-H11! 2 JD$ %aSXJ?  **r   c           
     Z    UR                  5        SU SU SUR                  SS9 S3// 4$ )N  = z.to<T	strip_refz>();)cpp_type)r,   r;   r<   r=   s       r   rA   Unboxing._gen_code_base_types   sH     ~~ (3xjU^^VZ^=[<\\`a
 	r   c           	         U S3nU R                  UR                  U5      u  pgpSU SU SUR                  SS9 S3R                  S5      U	4$ )	N_opt_in

    auto rG   z.toOptional<TrH   z>();
            
)r&   elemrJ   split)
r,   r;   r<   r?   r=   in_nameres_name	base_typeres_coder5   s
             r   rB    Unboxing._gen_code_optional_typez   st     Jg&.2.N.NFFG/
+X

3xjY-?-?$-?-O,P Qd	
 	
r   c                   U S3nU S3n/ nU R                  UR                  U5      u  pp[        UR                  [        5      (       aR  UR                  R                  [
        R                  :X  a*  UR                  SU SU S3R                  S5      5        X{4$ [        UR                  [        5      (       az  UR                  R                  [
        R                  :X  d(  UR                  R                  [
        R                  :X  a*  UR                  SU SU S3R                  S5      5        X{4$ [        UR                  [        5      (       aR  UR                  R                  [
        R                  :X  a*  UR                  SU SU S3R                  S5      5        X{4$ [        UR                  [        5      (       at  UR                  R                  [
        R                  :X  aL  UR                  S	UR                   S
U SU SU SU SU SU SU SU SU S3R                  S5      5        X{4$ [        UR                  [        5      (       a  [        UR                  R                  [        5      (       aq  UR                  R                  R                  [
        R                  :X  a?  UR                  SU SU SU SU SU SU SU SU SU S3R                  S5      5        X{4$ US-   nUR                  SU	R!                  SS9 S
U S35        UR                  SU SU S["        R%                  U
5       SU SU S UR!                  SS9 S!U S"U S#3R                  S5      5        X{4$ )$N_list_in_elemrN   rG   z!.toTensorList();
                rO   z.toIntList();
                z!.toDoubleList();
                z&
#ifdef USE_ATEN_LIB
std::array<bool, z> z;
auto z(.toBoolList();
size_t _i = 0;
for (auto z: z) {
    z	[_i++] = z;
}
#else
auto z&.toBoolList();
#endif
                z
#ifdef USE_ATEN_LIB
auto z@.toListOptionalTensor();
c10::List<::std::optional<at::Tensor>> z;
for (auto z.push_back(z);
}
#else
auto z0.toListOptionalTensor();
#endif
                _veczstd::vector<TrH   ;z
    for (EValue z) {
        z	
        z);
    }
    rF   (z);
                )r&   rP   r#   r	   r   r   Tensorr)   rQ   intSymIntfloatboolsizer   r*   rJ   	connectorjoin)r,   r;   r<   r?   r=   rR   	elem_namer4   rS   	res_ctyperU   r5   vec_names                r   rC   Unboxing._gen_code_list_type   s    Jh'j&	.2.N.NFFI/
+X affh''AFFKK6==,HKK

3xj !E$KN zE ))FFKK6::%)EKK

3xj !E$K~ zu ))affkkV\\.IKK

3xj !E$Kr zi ))affkkV[[.HKK&&H: &Yc( +Ry !Ji	{ # Zs8*  E$Kd zC qvv|,,166;;11  FMM1KKYc( ((0z 2+Ry !Jk) % Zs8* 
 E$K: z  &(HKKy11D1AB"XJaP KK2gY '			!" #		
+hZ (
^^d^#$AhZq
 ; E$K zr    N)r-   zSequence[Binding]returnztuple[list[Binding], list[str]])r?   r   r;   strr    ra   rj   z'tuple[str, CType, list[str], list[str]])r;   rk   r<   rk   r=   r   rj   tuple[list[str], list[str]])
r;   rk   r<   rk   r?   r   r=   r   rj   rl   )
r;   rk   r<   rk   r?   r
   r=   r   rj   rl   )__name__
__module____qualname____firstlineno____doc____annotations__r6   r&   rA   rB   rC   __static_attributes__ri   r   r   r   r      s    * '%'	('* :?!+!+!$!+26!+	0!+F'*38	$

'*
/;
DI
	$
RR'*R/7R@ER	$Rr   r   N)r   r   rj   rk   )
__future__r   dataclassesr   typingr   r   torchgen.modelr   r   r	   r
   r   r   r   collections.abcr   torchgen.api.typesr   r   r   rc   r   r   ri   r   r   <module>rz      sX    " ! *   (== 	* $z z zr   