U
    9%e%                  
   @   s*  d dl mZmZ d dlmZ d dlmZmZmZ d dl	m
Z
mZmZmZmZmZmZ dZeedddZeeee ee f dd	d
Zddeeeeeeee ee f dddZeeeeee ee f dddZeeeeeee ee f dddZeeeeeee ee f dddZdS )    )ListTuple)cpp)BindingCppSignatureGroupCType)ArgumentBaseTyBaseTypeListTypeNativeFunctionOptionalTypeTypez
	)freturnc                 C   s   | j j S )N)funcnameZunambiguous_name)r    r   T/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/torchgen/api/unboxing.pyr   d   s    r   c           
         s   t j| dd    fddtt D dg }g }t D ]h\}}t|jt	sdt
d| |j}t|j|j|jd\}}}}	||	 || ||| qB||fS )NF)methodc              	      s.   g | ]&}d  | j  d| dt  dqS )zc10::IValue z = std::move(peek(stack, , z));)r   len).0iargsr   r   
<listcomp>p   s   z%convert_arguments.<locals>.<listcomp> z7Unexpected argument type, expecting `Argument` but got mutable)r   Zfrom_native_functionZmost_faithful_signature	argumentsranger   	enumerate
isinstanceargumentr   	Exceptionargumenttype_ivalue_converttyper   Zis_writeextendappend	with_name)
r   Z	code_listZbinding_listr   argr$   Zunboxed_name_codedeclr   r   r   convert_argumentsi   s.    



r/   Fr   )targ_namer   r   c                C   s   t j| ||ddj}t| tr<| d}t|||d\}}nht| trf| d}t||| |d\}}n>t| tr| d}t	||| |d\}}nt
d|  d	| ||||fS )
NF)r0   r   ZbindsZsymint_baser1   out_namectypeZ_opt_out)r1   r4   r0   r5   Z	_list_outzCannot handle type z. arg_name: )r   Zargumenttype_typer'   r#   r
   _gen_code_base_typer   _gen_code_optional_typer   _gen_code_list_typer%   )r0   r1   r   r5   r4   r-   r.   r   r   r   r&      s>       

  



r&   )r1   r4   r5   r   c              	   C   s2   |j dd d| d|  d|j dd dgg fS )NTZ	strip_ref  = z.to<z>();)cpp_typer3   r   r   r   r6      s    *r6   )r1   r4   r0   r5   r   c           	      C   s   |  d}t |j|\}}}}d|  d|  d|jdd d| d|  d	| d
|  dt| d| d
|jdd d| d| d
|jdd dd|fS )NZ_opt_inz
c10::optional<c10::IValue> z_opt = z.toOptional<c10::IValue>();
Tr9   r:   z;
if (z*_opt.has_value()) {
    const c10::IValue r;   z_opt.value();
    
    (z);
} else {
    z();
}
        
)r&   elemr<   	connectorjoinsplit)	r1   r4   r0   r5   in_nameres_namer,   res_coder.   r   r   r   r7      sB    



r7   c                 C   sx  |  d}|  d}d| d|  dg}t |j|\}}}	}
t|jtr|jjtjkr|jr|d|j	dd d	| d
|j	dd d|j d| d
d nt|jtr|d|j	dd d	| d| d| dt|	 d| d| d
d nx| d }|
d|j	dd d| d |d| d| dt|	 d| d| d|j	dd d	| d| d
d ||
fS )NZ_list_in_elemzconst c10::List<c10::IValue> r;   z
.toList();r?   Tr9   r:   z = as_array<r   z>(z);
            z;
for (c10::IValue z: z) {
    r=   z.push_back(z);
}
            Z_veczstd::vector<z> ;z
for (c10::IValue z);
}
r>   )r&   r@   r#   r
   r   r	   boolsizer(   r<   rC   r   rA   rB   r)   )r1   r4   r0   r5   rD   Z	elem_namer-   rE   Z	res_ctyperF   r.   Zvec_namer   r   r   r8      s    

 


 
r8   N)typingr   r   Ztorchgen.apir   Ztorchgen.api.typesr   r   r   Ztorchgen.modelr   r	   r
   r   r   r   r   rA   strr   r/   rI   r&   r6   r7   r8   r   r   r   r   <module>   s<   $[ "  #  	      