
    Ph               
           d dl Z d dlmZmZ d dlZd dlmZ ddlmZ ddl	m
Z
mZmZ ddlmZmZ ddlmZ d	d
lmZmZ ededej.                  dej0                  dej2                  diZ G d de      Z G d de      Zy)    N)DictList)GetItemSource   )	variables)unimplemented	UserErrorUserErrorType)GuardBuilderinstall_guard)np   )typestrVariableTrackerz!List types must use ListVariable.z&Dict types must use ConstDictVariable.z%Tensor types must use TensorVariable.zvSymInts must use SymNodeVariable. If the underlying value is static, we will create a ConstantVariable and specialize.z SymInts must use SymNodeVariablec                        e Zd Zedefd       Z fdZd Zd Zd Z	d Z
ed        Zd	efd
Zed        Zd Zd Z	 	 	 	 	 	 d fdZdeddfdZ xZS )ConstantVariablereturnc                 @   |j                  dd       }t        j                  |       }|s/t        j	                         D ]  \  }}t        | |      sJ |        |rt        | t        t        f      rg }t        |       D ]e  \  }}|rt        ||      nd }	|	r(t        |	j                  t        j                               |j                  t        j                  ||	             g t!        j"                  j%                  t'        |             |fi |S t        | fi |S )Nsource)r   )getr   
is_literal_type_to_assert_reasonitems
isinstancelisttuple	enumerater   r   
make_guardr   CONSTANT_MATCHappendcreater   BaseListVariablecls_fortype)
valuekwargsr   r   disallowed_typereasonr   ixitem_sources
             kC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torch/_dynamo/variables/constant.pyr!   zConstantVariable.create   s   Hd+%007
+A+G+G+I'%e_=EvE= ,J *UT5M:E!%(1:@mFA6d!+"8"89T9T"UV$++* , 	 ) --55d5kB5SFSS000    c                 `   t        |   di | t        j                  |      s/t        j                         D ]  \  }}t        ||      sJ |        t        |t        t        f      rJ d       t        0t        |t        j                        r|j                         | _        y || _        y )NzFConstantVariable(list) is banned - please create a ListVariable(items) )super__init__r   r   r   r   r   r   r   r   numberitemr%   )selfr%   r&   r'   r(   	__class__s        r,   r1   zConstantVariable.__init__8   s    "6"**51+A+G+G+I'%e_=EvE= ,J D%=
 	TS	T 
 >j		:DJDJr-   c                     | j                   S Nr%   r4   s    r,   as_proxyzConstantVariable.as_proxyF       zzr-   c                 H    dt        | j                        j                   dS )NzConstantVariable())r$   r%   __name__r9   s    r,   __str__zConstantVariable.__str__I   s!    "4

#3#<#<"=Q??r-   c                 ,    t        | j                        S r7   r$   r%   r9   s    r,   python_typezConstantVariable.python_typeM       DJJr-   c                     | j                   S r7   r8   r9   s    r,   as_python_constantz#ConstantVariable.as_python_constantP   r;   r-   c                 &    | j                  d      S )zz
        Need this when adding a BaseListVariable and a ConstantVariable together.
        Happens in detectron2.
        N)tx)unpack_var_sequencer9   s    r,   r   zConstantVariable.itemsS   s     ''4'00r-   argc                 b    t         j                  | j                  |j                                  S r7   )r   r!   r%   rE   )r4   rI   s     r,   getitem_constzConstantVariable.getitem_const[   s*    &&JJs--/0
 	
r-   c           	      :   t        |       t        t        t        t        d       t        t
        j                  t        j                  t        j                  fv ryt        |       t        t        t        t        t        j                  fv rt        d | D              S y)NTc              3   F   K   | ]  }t         j                  |        y wr7   )r   r   ).0r*   s     r,   	<genexpr>z.ConstantVariable.is_literal.<locals>.<genexpr>o   s     Cs!'2215ss   !F)r$   intfloatboolstrEllipsisr5   torchdtypedevicer   r   set	frozensetSizeall)objs    r,   r   zConstantVariable.is_literal`   sq    9JKKLL	
 	
 9uc9ejjAACsCCCr-   c                     	 | j                         D cg c]  }t        j                  |       c}S c c}w # t        $ r}t        |d }~ww xY wr7   )rE   r   r!   	TypeErrorNotImplementedError)r4   rG   r*   es       r,   rH   z$ConstantVariable.unpack_var_sequencer   sN    	-8<8O8O8QR8Q1$++A.8QRRR 	-%1,	-s!   8 38 8 	AAAc                     t        | j                  t              rt        t        j
                  dd      t        | j                  |      }t        |      r
t               |S )Nz]Can't access members of type(obj) for a generated custom object. Please use __class__ insteadtype_reflection_method)	case_name)	r   r%   r$   r	   r
   ANTI_PATTERNgetattrcallabler_   r4   rG   namemembers       r,   const_getattrzConstantVariable.const_getattrx   sV    djj$'**/2	  T*F%''r-   r   c                     ddl m t        fdD              r@t        j                   j	                          j
                        j                  ||      S 	 D cg c]  }|j                          }}|j                         D ci c]  \  }}||j                          }	}} fd}
t         j
                  t              rQt        j                  j                         v r1t         j
                        }t         j#                   ||i |	      S  |
t$              s |
t&              rt        t(              }|d   }t        |t*        j,                  t*        j.                  f      rCddl m |j0                  j3                  d| j
                  |fi       }j#                  |||      S t         j#                   | j
                  |            S dk(  r,s*|s(t         j#                  t5         j
                              S dk(  r[t5              dk(  rMd   j7                         r:|rJ d   j                         }| j
                  v }t         j#                  |      S t9        d	t;         j
                         d
        y c c}w c c}}w # t        $ r t           ||      cY S w xY w)Nr   )SymNodeVariablec              3   6   K   | ]  }t        |        y wr7   )r   )rN   r*   rl   s     r,   rO   z/ConstantVariable.call_method.<locals>.<genexpr>   s     <t!z!_-ts   c                     t        j                  |       xr5 t        t              xr# t	              dk(  xr d   j                         S )Nr   r   )r   r%   hasattroperatorlenis_python_constant)num_tyargsrh   r4   s    r,   has_arith_binopz5ConstantVariable.call_method.<locals>.has_arith_binop   sL    4::v. 1Hd+1IN1 G..0	r-   r   call_function__len____contains__zconst method call .)tensorrl   anyr   r:   r%   call_methodrE   r   r_   r0   r   rS   __dict__keysre   r   r!   rP   rQ   rp   rU   SymIntSymFloatoutputcreate_proxyrq   rr   r   r   )r4   rG   rh   rt   r&   a
const_argskvconst_kwargsru   methodop
add_targetproxysearchresultrl   r5   s   ` ``             @r,   r|   zConstantVariable.call_method   sR    	,<t<<,,T]]_djjIUUD$ 	?:>?$Q!..0$J?BH,,.Q.$!QAq3355.LQ	 djj#&43<<3D3D3F+FTZZ.F#**6:+N+NOOS!_U%;4(B#AJ*u||U^^&DE3 		..#R$**j)A2 '--b%DD#**2djj*+EFFY#**3tzz?;;^#D	Q47;U;U;W:!W//1Ftzz)F#**622*74::+>*?qGHO @Q" 	?7&r4v>>	?s0   !J" %J<J" J,J" J" "K ?K rh   c                 l    t        | j                  |      }t        j                  j	                  |      S r7   )ro   r%   r   r   r!   )r4   rG   rh   r   s       r,   call_hasattrzConstantVariable.call_hasattr   s)    T*))0088r-   )rt   zList[VariableTracker]r&   zDict[str, VariableTracker]r   r   )r>   
__module____qualname__staticmethodr   r!   r1   r:   r?   rB   rE   propertyr   rK   r   rH   rj   r|   rS   r   __classcell__r5   s   @r,   r   r      s    1? 1 10@  1 1
 

  "-7I &	7I
 -7I 
7Ir9S 9-> 9r-   r   c                   <     e Zd Z fdZd Zd Zd Zd Zd Z xZ	S )EnumVariablec                 2    t        |   di | || _        y )Nr/   )r0   r1   r%   )r4   r%   r&   r5   s      r,   r1   zEnumVariable.__init__   s    "6"
r-   c                     | j                   S r7   r8   r9   s    r,   r:   zEnumVariable.as_proxy   r;   r-   c                 4    dt        | j                         dS )NzEnumVariable(r=   rA   r9   s    r,   r?   zEnumVariable.__str__   s    tDJJ/022r-   c                 ,    t        | j                        S r7   rA   r9   s    r,   rB   zEnumVariable.python_type   rC   r-   c                     | j                   S r7   r8   r9   s    r,   rE   zEnumVariable.as_python_constant   r;   r-   c                 \    t        | j                  |      }t        |      r
t               |S r7   )re   r%   rf   r_   rg   s       r,   rj   zEnumVariable.const_getattr   s(    T*F%''r-   )
r>   r   r   r1   r:   r?   rB   rE   rj   r   r   s   @r,   r   r      s!    3 r-   r   )rp   typingr   r   rU   torch._dynamo.sourcer    r   excr   r	   r
   guardsr   r   utilsr   baser   r   r   dictTensorr   r   r   r   r   r/   r-   r,   <module>r      su       .  9 9 0  * 	
-
2	LL9	LL [	NN6 "b9 b9J? r-   