ó
V^c           @   s  d  d l  Z  d  d l m Z d  d l m Z d  d l Z i d d d d g d 6d	 d
 d d d d g d 6d d d g d 6Z e d e d e d Z e e d <d d d d d d g Z d d g Z	 d   Z
 d   Z d   Z d   Z d   Z d    Z d!   Z d"   Z d#   Z d S($   i’’’’N(   t   deepcopy(   t   TYPE_FORMAL_GENERICt   Floatt   Doublet   Halft   BFloat16t   floating_pointt   Bytet   Chart   Shortt   Intt   Longt   Boolt   integralt   QInt8t   QUInt8t   QInt32t	   quantizedt   allt   CPUt   CUDAt	   SparseCPUt
   SparseCUDAt	   MkldnnCPUt   QuantizedCPUc         C   s=  d |  k r§ |  j  d t  } t |  j  d  t  rN |  j  d  j   } n  t |  } i  } xN | D]9 } | d k r t d | | <qg |  j  d t  | | <qg Wn
 |  d } d   } x@ | j   D]2 } | t k sß t	  t | | |   | | <qĒ W|  j  d t
  s2d	 | k r2| d	 j d
  q2n  |  j  d t
  sgd	 | k rg| d	 j d  qgn  d | k r| d j d  n  |  j  d t
  s¼d	 | k r¼| d	 j d  q¼n  |  j  d t
  sńd | k rń| d j d  qńn  x; | j   D]- } t g  | | D] } | ^ q | | <qžW| |  d <d  S(   Nt   backend_typest   backendst   type_method_definition_dispatchR   R   t   typesc         S   sZ   g  } xM |  D]E } | t  k r3 | j t  |  q | t k sE t  | j |  q W| S(   N(   t   type_mapt   extendt	   all_typest   AssertionErrort   append(   R   t   rett   t(    (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pyt   expand7   s    t   cpu_halfR   R   t   cpu_bfloat16R   R   t   cpu_boolR   t	   cuda_bool(   t   gett   default_backendst
   isinstancet   dictt   keyst   setR   R   t   all_backendsR    t   Falset   discardt   sorted(   t   optionR   R   t   backendR$   t   type(    (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pyt   process_types_and_backends#   s@    
	
+c         C   s   d |  k p |  j  d  d k S(   Nt   only_registert   namet
   ndimension(   R)   (   t   declaration(    (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pyt   excludeb   s    c         C   s   |  j  d d g  d  S(   Nt   variantst   method(   t
   setdefault(   R3   (    (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pyt   add_variantsf   s    c         C   s  g  } d   } d   } xż |  D]õ } x+ | d D] } | |  r0 t  | d <q0 q0 Wt d   | d D  rt |  } x+ | d D] } d | k r t  | d <q q W| |  r÷ d | d	 k r× | d	 j d  n  | d
 c d 7<| j |  n  | j |  q | j |  q W| S(   Nc         S   s5   |  d d d h k o4 |  j  d d  d  d d h k S(   NR5   s   THIntegerTensor*s	   THTensor*t   defaultt    t   NULLt   nullptr(   R)   t   None(   t   arg(    (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pyt   is_nullableq   s    c         S   s>   d |  d k r: |  d d k r: t  j d |  d  d  k St S(   Nt   functionR<   t   modet   natives   (^__i|[^_]_$)t   api_name(   t   ret   searchRD   R0   (   R3   (    (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pyt   should_generate_out_variantu   s     t	   argumentsRF   c         s   s   |  ] } d  | k Vq d S(   t   outputN(    (   t   .0RE   (    (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pys	   <genexpr>   s    RO   t   allocateR=   R<   RJ   t   _out(   t   Truet   anyR    t   removeR!   (   t   optionst   new_optionsRF   RM   R3   RE   t   allocate_option(    (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pyt!   handle_outputs_taken_as_argumentsn   s(    		c         C   s  |  d } t  j d |  } | d  k	 rt g  | j d  j d  D] } t |  ^ qA } i d d 6| d 6|  d <n | d k rå i d d 6g  d 6|  d <xf t |  d  D]5 \ } } | d d k r© |  d d j |  Pq© q© Wn i d	 d 6|  d d	 6|  d <d  S(
   Nt   returns   argument (\d+(,\d+)*)i   t   ,RN   t   kindt   selfR8   R5   (   RK   t   matchRD   t   groupt   splitt   intt	   enumerateR!   (   R3   R"   t   mt   xRN   t   i(    (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pyt   sanitize_return   s    
1c         C   s   |  j  d d  |  d <d  S(   NRH   t   TH(   R)   (   R3   (    (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pyt   set_mode§   s    c            sŠ   d  d  d      f d   |  d D } x  |  d D] } x t | d  D]y \ } } | d d k rK   | | d  } | | k rÄ | | } g  | d D] } | d ^ q } | | | d	 <qÄ qK qK Wq4 Wd  S(
   Nc         S   sh   g  t  |  d  D]D \ } } | d  k s5 | | k rO t j | d | d  n | ^ q } d j |  S(   NRN   R5   t   #(   Rb   RD   R   R)   t   join(   R3   Re   t   valuet   jRE   t   elements(    (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pyt	   signature“   s    Xc            s   i  |  ] } |   |   q S(    (    (   RP   R3   (   Rn   (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pys
   <dictcomp>¹   s   	RV   RN   R5   t   reals   Tensor &R8   t   zero_dim_dispatch_when_scalar(   RD   Rb   (   R:   t   signature_to_optionR3   Re   RE   t   signature_of_tensor_versiont   tensor_versiont   names(    (   Rn   s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pyt#   discover_zero_dim_tensor_operations³   s    
!c         C   s   d |  d k r t  St Sd  S(   NR=   R<   (   R0   RS   (   R3   (    (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pyt   is_extended_methodĶ   s    c      	   C   su  g  |  D] } t  |  s | ^ q }  t   } x|  D]ž } t j |  g  | d D] } t |  ^ qS | d <t j | d d t d t d t | d <t j	 |  t
 |  xm | d D]a } t |  | d d k rē t |  n  t |  t |  t |  sŗ | j | d  qŗ qŗ Wt | d  | d <q5 Wx7 |  D]/ } x& | d D] } | d | k | d <qOWq>W|  S(	   NRV   t   allow_kwargt   type_to_signaturet   remove_selfRH   RI   RJ   t   extended_method(   R;   R.   t   common_with_cwrapt   set_declaration_defaultsR    t   filter_unique_optionsR0   R   RS   t   sort_by_number_of_argsRu   Rh   Rf   R6   R?   Rv   t   addRY   (   t   declarationst   dt   non_extended_methodsR:   t   oR3   (    (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pyt   runŌ   s4    %	'




	(   RK   t   copyR    t   function_wrapperR   R{   R   R   R/   R*   R6   R;   R?   RY   Rf   Rh   Ru   Rv   R   (    (    (    s7   /torch/pytorch/aten/src/ATen/preprocess_declarations.pyt   <module>   s<   


	?			)				