o
    haK                     @  s6  d dl mZ d dlmZmZ d dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# erVd dl$m%Z% ede
ee!Z&ede
ee"Z'e#eeZ(e#ee Z)ee#eeZ*eeeZ+eee"Z,G dd de-Z.d	d	d
dddZ/dS )    )annotations)NoReturnTYPE_CHECKING)ArrayRefCType	BaseCTypeBindingboolTConstRefCTypedeviceTExprintArrayRefTiOptTensorListRefTlayoutT	ListCTypelongTmemoryFormatTMutRefCType
NamedCTypeopmath_tOptionalCTypeoptionalIntArrayRefToptionalScalarRefToptionalSymIntArrayRefToptionalTensorRefTscalar_tscalarTscalarTypeTSpecialArgNamesymIntArrayRefTSymIntTtensorOptionsTtensorTVectorCType)Sequenceoptionsoutc                   @  s   e Zd ZdS )
UnsatErrorN)__name__
__module____qualname__ r*   r*   j/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/torchgen/api/translate.pyr&   R   s    r&   F)methodallow_expensive_conversionsbindingsSequence[Expr | Binding]goalsSequence[NamedCType | Binding]r,   boolr-   return
list[Expr]c                  sl  g }| D ]}t |tr|t|j|jd q|| qg |D ]}t |tr/|j q!| q!i |D ]}|j|j< |j}t |trvt |j	t
rvt |j	j	trvt|j	j	jdkrvd|j d|j dt|j	j	jttt< |jtt
ttkrd|j d|j d|j d	t|jtt< |jtttkrd|j d
t|jtt< |jtt
ttkrd|j d|j dt|jtt< |jttkrd|j dt|jtt< |jttt
ttkrd|j dt|jtt< q9|rdtdttt< dtdttt< dfddd  fddfddD S )!N)exprtypez
at::Tensor(z.has_value() ? *z : at::Tensor())z((z.has_value() && (*z&).defined()) ? at::OptionalTensorRef(*z) : at::OptionalTensorRef())z).to<opmath_t>()z'.has_value() ? at::OptionalScalarRef(&(z%.value())) : at::OptionalScalarRef())zstatic_cast<opmath_t>()zat::IOptTensorListRef(zconst_cast<Tensor&>(*this)selfgoalr   r3   r   c                   s:   d dd   D }td|   d| j d| d)N
c                 s  s0    | ]\}}d |   d|j d| V  qdS )z   z; // N)cpp_typename).0ter*   r*   r+   	<genexpr>   s     
z+translate.<locals>.unsat.<locals>.<genexpr>z&
Failed to synthesize the expression "r<   zI".
When I failed, the following bindings were available in the context:

z~

This probably means there is a missing rule in the rules of torchgen.api.translate.
Check this module for more information.
)joinitemsr&   r=   r>   )r:   ctx_desc)ctxr*   r+   unsat   s   
ztranslate.<locals>.unsatdirectr2   strc             	     s  d+fdd}| v r|  S t | jtr.zt| jt| jj|dW S  ty-   Y nw t | jtrKzt| j| jj|dW S  tyJ   Y nw | jtt	t
kr`t| jt	t|dS |rf|  | tdtt	tkr|ttjtt	t}tv r|S z|t}d	| d
| dW S  ty   | Y S w | tdt	tkr|tdtt	t}|tdtt	t}|tdtt	t}|tdtt	t}d| d| d| d| d	S | tdtt	tkrz|t}d| dW S  ty   |t}	|	 d Y S w | tdtt	tkr6z
|t}| dW S  ty5   |t}	|	 d Y S w | tdtt	tkr`z
|t}| dW S  ty_   |t}	|	 d Y S w | tdtt	tkrz
|t}| dW S  ty   |t}	Y dS w | jt	tkrz	|t| jtW S  ty   |t| jt	t}
d|
 d Y S w | jt	tkrz|t| jt	t}d| dW S  ty   |t| jt Y S w | jt	tkr|t| jt	t
S | jtt	tkr|t| jtt	t
}| d | d!S | jt	t
kr%|t| jt	t}| d"S | jtt	t
krC|t| jtt	t}| d#| d$S | jt	tkrqz	|t| jtW S  typ   |t| jt	t}| d%| d! Y S w | jt	tkr|t| jt	t}| d&| d!S | jt	tkr|t| jtS | jt	t kr|t| jt!S  r@| jt"t	t
krt| jt	t}||}| d'S | jt"t	tkrt| jt	t}||}| d'S | jtt"t	t
krt| jt	t}||}| d#| d(S | jtt	t#kr"t| jt	t}||}| d#| d)S | jtt	t#kr@t| jt	t }||}| d#| d)S | jtt	t$kr^t| jtt	t$}||}d*| dS |  d S ),Nr:   r   r3   rI   c                   s    | ddS )NTrH   r*   )r:   solver*   r+   direct_solve   s   z.translate.<locals>.solve.<locals>.direct_solverJ   memory_formatz:c10::impl::check_tensor_options_and_extract_memory_format(z, r8   r$   dtype
pin_memorydevicelayoutzTensorOptions().dtype(z	).layout(z	).device(z).pinned_memory(zc10::optTypeMetaToScalarType(z.dtype_opt())z.scalar_type()z.layout_opt()z	.layout()z.device_opt()z	.device()z.pinned_memory_opt()z::std::nulloptzC10_AS_INTARRAYREF_SLOW(zc10::fromIntArrayRefSlow(z1.has_value() ? ::std::make_optional(c10::SymInt(*z)) : ::std::nulloptz.guard_int(__FILE__, __LINE__)z$.has_value() ? ::std::make_optional(z1->guard_int(__FILE__, __LINE__)) : ::std::nulloptz=.has_value() ? ::std::make_optional(C10_AS_INTARRAYREF_SLOW(*z>.has_value() ? ::std::make_optional(c10::fromIntArrayRefSlow(*z.vec()z->vec()) : ::std::nulloptz) : ::std::nulloptzconst_cast<Tensor&>()r:   r   r3   rI   )%
isinstancer6   r	   r   r>   r   elemr&   r   r   r   r   r   r   r    possibly_redundant_memory_formatoptions_ctyper    r   r   r
   r   out_tensor_ctypelongVec_ctyper   longSymVec_ctyper   r   optionalLongVec_ctyper   r   optionalScalar_ctyper   optionalTensor_ctyper"   r   r!   )r:   rH   rM   rN   r$   rO   rP   rQ   rR   
out_tensorsymIntArrayRef_typerargnamesymInt_typeintArrayRef_ctypesymIntArrayRef_ctypeoptionalIntArrayRef_ctypeoptionalScalarRef_ctypeoptionalTensorRef_ctypeconst_ref_tensor_ctyper-   rF   goal_ctypesrL   rG   r*   r+   rL      sJ  







ztranslate.<locals>.solvec                   s   g | ]}t  |d d|qS )FrJ   )r   )r?   grK   r*   r+   
<listcomp>  s    ztranslate.<locals>.<listcomp>)r:   r   r3   r   )r:   r   rH   r2   r3   rI   )rS   r   appendr   r>   nctyper5   r6   r	   rT   r   r   rI   r   r!   r   r   r   r   r   r   r   r   )r.   r0   r,   r-   binding_exprsbrj   r@   r*   rh   r+   	translateg   sh   

 
 Mrp   N)
r.   r/   r0   r1   r,   r2   r-   r2   r3   r4   )0
__future__r   typingr   r   torchgen.api.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   collections.abcr#   rV   rW   rX   rY   rZ   r[   r\   RuntimeErrorr&   rp   r*   r*   r*   r+   <module>   s     "