ó
V�^c           @  sÇ   d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z y d  d l m Z Wn! e	 k
 rƒ d  d l m Z n Xd „  Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d S(   iÿÿÿÿ(   t   print_functionN(   t   CLoader(   t   Loaderc   
      C  s«  g  |  j  d d ƒ D] } | j ƒ  ^ q } d } t | ƒ d k rP | d } n  | d } | j d ƒ } d  } t } d  } t | ƒ d k rš | d } n  | d } t j d | ƒ } d  }	 | rð | j d ƒ | j d ƒ } | j d ƒ }	 n  | d	 k od
 | k } | d	 k r/| d k r/d } d } né| d	 k rDd } nÔ| d k s\| d k red } n³| d k rzd } nž| d k r�d } n‰| d k r¤d } nt| d k r¿t	 d ƒ ‚ nY| d k rÚt	 d ƒ ‚ n>| d k rïd } n)| d k rd } n| d k rd } nÿ | d k r4t	 d ƒ ‚ nä t j d  | ƒ rvt j d  | ƒ } d } t
 | j d ƒ ƒ } n¢ t j d! | ƒ rµt j d! | ƒ } d" j | j d ƒ ƒ } nc t j d# | ƒ rÖt	 d$ ƒ ‚ nB t j d% | ƒ rt j d% | ƒ } d& } t
 | j d ƒ ƒ } n  | d k r-d' } n  | s6n_| j d( ƒ rZ| d k rZd) } n;| d* k rot } n&| d+ k r„t } n| d, k rŸt	 d- ƒ ‚ nö | d. k rºt	 d/ ƒ ‚ nÛ | d0 k rÏd) } nÆ t j d1 | ƒ rùd2 | d d3 !d4 } nœ | d k rd5 } n‡ | d6 k r#d7 } nr | d8 k r8d9 } n] | d: k rMd; } nH y t
 | ƒ } Wn5 t k
 r”y t | ƒ } Wq•t k
 r�q•Xn X| | | | | |	 f S(<   Nt    i   t    i    t   =s   (Tensor.*)\((.+)\)(.*)i   i   s
   Generator?t   ?t   Nones
   Generator*t   nullptrs   Tensor[]s	   Tensor?[]t
   TensorLists   int[]t   IntArrayReft   intt   int64_ts   int?s   int64_t?sD   Please use int and not int64_t. See [temp translations] for details.sF   Please use int? and not int64_t?. See [temp translations] for details.s
   Dimname[]?s   DimnameList?t   floatt   doublet   strs   std::stringsE   Please use float and not double. See [temp translations] for details.s   int\[(\d+)\]s   bool\[(\d+)\]s   std::array<bool,{}>s
   std::arrays_   Please use array notation, e.g. bool[3] and not std::array.See [temp translations] for details.s   Dimname\[(\d+)\]t   DimnameLists   Generator *s   Tensor?s   {}t   Truet   Falset   truesB   Please use True and not true. See [temp translations] for details.t   falsesD   Please use False and not false. See [temp translations] for details.s   []s   \[.*\]t   {iÿÿÿÿt   }s   c10::nulloptt   Means   Reduction::Meant   contiguous_formats   MemoryFormat::Contiguoust   per_tensor_affines   QScheme::PER_TENSOR_AFFINE(   t   rsplitt   stript   lent   splitR   R   t   ret   matcht   groupt   RuntimeErrorR   t   formatt
   startswithR   t
   ValueErrorR   (
   t   argt   at   type_and_namet   namet   tt   defaultt   nullablet   sizeR   t
   annotation(    (    s,   /torch/pytorch/aten/src/ATen/native_parse.pyt   type_argument_translations   s´    +

																		c           s  g  } t  } t |  j ƒ  ƒ d k r( | Sxt |  j d ƒ ƒ D]ô \ } } g  | j d d ƒ D] } | j ƒ  ^ q] }	 |	 d g k r� | s‘ t ‚ t } q> n  t | ƒ \ }
 } } } } } i |
 j	 d ƒ d 6| d 6| d	 6| d
 6} | rù | | d <n  | d  k	 r| | d <n  | r%t | d <n  | j | ƒ q> Wt  } g  } g  } x„ | D]| } | d d k r¾| d
 r¾t j d | d
 ƒ r¾| j d ƒ r¾t | d <t  | d <| j | ƒ t } qO| j | ƒ qOW| | } | d } | rü| d c d 7<n  i d d 6d d 6t  d	 6d  d
 6i d d 6d d 6t  d	 6d  d
 6i d d 6d d 6t  d	 6d  d
 6i d d 6d d 6t  d	 6d  d
 6t  d 6g g ‰ ˆ j t j ˆ d ƒ ƒ x& ˆ d D] } | j i t d 6ƒ q­Wˆ j t j ˆ d ƒ ƒ x- ˆ d D]! } | j i d d 6t d	 6ƒ qðWˆ j i d d 6d d 6d  d
 6t d 6d d 6t d	 6i d d 6d d 6d  d
 6t d 6d d 6t d	 6i d d 6d d 6d  d
 6t d 6d d 6t d	 6i d d 6d d 6d  d
 6t d 6d d 6t d	 6g ƒ i d d 6d d 6t  d	 6d  d
 6g ‰  ˆ  j ˆ  d j ƒ  ƒ t ˆ  d d <ˆ  j ˆ  d j ƒ  ƒ d ˆ  d d <ˆ  j i d d 6d d 6t  d	 6d  d
 6t d 6d  d 6ƒ ‡  ‡ f d! †  } d" „  } g  } d } x| t | ƒ k  rÁ| | } t ˆ d ƒ } | | ƒ r§t | ƒ | | k r§g  } xE t | ƒ D]7 } | | } | | ƒ s'Pn  | j | ƒ | d 7} qWt | ƒ | k rš| | ƒ } | sŠt d# j t | ƒ t ˆ ƒ ƒ ƒ ‚ | j | ƒ q¾| | 7} q¦| j | ƒ | d 7} q¦W| } xG t | ƒ D]9 \ } } | d
 | | d
 k sÕt d$ j | ƒ ƒ ‚ qÕWt | ƒ t | ƒ k s?t d% j | ƒ ƒ ‚ | j d ƒ rft d& j | ƒ ƒ ‚ n  | rœ| g  d' d' g g k rœt d( j | ƒ ƒ ‚ n  | sÌt | ƒ d k sÌt d) j | ƒ ƒ ‚ n  | d* rt | ƒ d k r| d d d+ k rt  } xê t | ƒ D]Ü \ } } | d d, k r| d
 rH| d
 j d- ƒ s]t d. j | ƒ ƒ ‚ t } | d
 | | d
 k s�t d/ j | ƒ ƒ ‚ | d | | d k sÊ| d | | d d0 k sÊt ‚ | d | | d k sët ‚ qqW| st d1 j | ƒ ƒ ‚ n  | S(2   Ni    s   , R   i   t   *R   t   typeR(   t   is_nullableR-   R,   R*   t
   kwarg_onlyt   Tensors   ^(.*!)$t   outputt   _outt   dtypet
   ScalarTypet   layoutt   Layoutt   devicet   Devicet
   pin_memoryt   booli   s   c10::nulloptt   longt   TensorOptionst   optionss   {}s	   at::kLongc           sQ   xJ t  ˆ ƒ D]< \ } } t ‡  f d †  t  | ƒ Dƒ ƒ } | r ˆ | Sq Wd  S(   Nc         3  s%   |  ] \ } } ˆ  | | k Vq d  S(   N(    (   t   .0t   it   topt(   t   topt_representation(    s,   /torch/pytorch/aten/src/ATen/native_parse.pys	   <genexpr>û   s    (   t	   enumeratet   allR   (   RD   t   idxt   supported_toptt   matches(   t   corresponding_toptst   supported_topt_arguments(   RD   s,   /torch/pytorch/aten/src/ATen/native_parse.pyt   check_topt_representationù   s
    "c         S  s   |  d d k S(   NR(   R6   R8   R:   R<   (   R6   R8   R:   R<   (    (   t   argument(    (    s,   /torch/pytorch/aten/src/ATen/native_parse.pyt   is_tensor_option   s    s]   Unsupported combination of TensorOptions {}, the only currently supported combinations are {}s—   For func {} writeable keyword Tensor arguments need to have a matching return Tensor. Further, the ith-argument needs to correspond to the i-th return.sH   func {} must return at least as many Tensors as can be passed as output.s    Native function {} may not be suffixed with _out as we transition to a unified schema. Otherwise you will cause confusion amongst consumers of native functions.t   functionsü   Native functions with output MUST be declared with only the function variant; e.g., variants: function; otherwise you will tickle a Python argument binding bug (which usually manifests itself as the result variable being undefined.) The culprit was: {}sE   func {} is not marked as output yet contains output keyword argumentst   inplacet   voidt   selft   !sN   Inplace function "{}" needs to annotate Tensor argument named self as mutable.s`   Inplace function annotations of function {} need to match between input and correponding output.t   _returns7   Inplace function "{}" needs Tensor argument named self.(   R   R   R   RE   R   R   t   AssertionErrorR   R.   t   rstripR   t   appendR   R   t   gett   copyt   deepcopyt   updatet   rangeR"   R   t   endswithR!   (   t   argst   func_variantst   declarationt   func_returnt	   argumentsR2   t   arg_idxR%   R&   R'   R)   R(   R*   R+   R,   R-   t   argument_dictt	   is_out_fnt   arguments_outt   arguments_otherRM   RL   RN   t   new_argumentsRG   t   number_of_argumentsRD   RB   t   merged_argumentt
   found_self(    (   RJ   RK   s,   /torch/pytorch/aten/src/ATen/native_parse.pyt   parse_arguments˜   sî    "++


	

/%	
"
	!		0 "%c         C  s{  g  } |  d d k r6 |  d d k r6 |  d d !}  n  t  |  j d ƒ ƒ d k } x#t |  j d ƒ ƒ D]\ } } t | ƒ \ } } }	 }
 } } | } | | d j d ƒ d k rÁ | d	 } n  i | d
 6| d 6| d 6} | rï | | d <nm | d k r<| r<| r| j d ƒ s/t d j | d ƒ ƒ ‚ d | d <n  | sHd n d t | ƒ | d <t | d <| j	 | ƒ qg W| S(   Ni    t   (iÿÿÿÿt   )i   s   , t   funcs   ->RT   R0   R(   R-   t
   field_nameR3   RS   sR   Return Tensor of function "{}" flagged as inplace needs to be annotated as mutableRR   t   resultR4   (
   R   R   RE   R.   R]   RU   R"   R   R   RW   (   t   return_declRP   t	   func_declRb   t   multiple_argsRc   R%   R)   R(   R*   R+   R,   R-   t   return_nameRd   (    (    s,   /torch/pytorch/aten/src/ATen/native_parse.pyt   parse_return_argumentsL  s*     " 
c         C  s/   t  |  d ƒ � } t j | d t ƒSWd  QXd  S(   Nt   rR   (   t   opent   yamlt   loadR   (   t   patht   f(    (    s,   /torch/pytorch/aten/src/ATen/native_parse.pyt   parse_native_yamll  s    c         C  sK   |  rG x> t  | ƒ D]- \ } } d | k r | d |  | d <q q Wn  d  S(   NRp   (   RE   (   t   output_argumentst   return_argumentsRB   Rw   (    (    s,   /torch/pytorch/aten/src/ATen/native_parse.pyt   propagate_field_namesq  s    c         C  s+   t  g  |  d D] } d | d k ^ q ƒ S(   NRb   t   DimnameR0   (   t   any(   R`   R%   (    (    s,   /torch/pytorch/aten/src/ATen/native_parse.pyt   is_named_tensor_onlyw  s    c         C  s×  g  } xÊ|  D]Â} x¹t  | ƒ D]«} i d d 6} y?d | d | d <d | d k r� g  | d j d ƒ D] } | j ƒ  ^ ql \ } } n t d ƒ ‚ | j d d	 ƒ \ } }	 d
 | k rØ | j d
 d	 ƒ \ } }
 n d }
 |	 d d k st d j | d ƒ ƒ ‚ |	 d  }	 | j d | ƒ | d <| j d | ƒ | d <| j d |
 ƒ | d <t j d | ƒ d  k	 | d <t
 | | d | ƒ } t |	 | j d g  ƒ | | ƒ }	 g  |	 D] } | j d ƒ r­| ^ q­} t | | ƒ t | ƒ d k ró| n | | d <| j d d g ƒ | d <| j d t ƒ | d <| j d t ƒ | d <| j d t ƒ | d <| j d t ƒ | d <| j d t ƒ | d <| j d t ƒ | d <| j d t ƒ | d <| j d  t ƒ | d  <| j d! t ƒ | d! <| j d" d# ƒ | d" <| d" d. k st ‚ | j d& d ƒ | d& <| j d' |	 ƒ | d' <| j d( | d ƒ | d) <| j d* d ƒ | d* <| j | ƒ Wq  t k
 rÊ} d+ j d t j | ƒ d, t j | ƒ ƒ } t | d- t j ƒ| ‚ q  Xq  Wq W| S(/   Nt   nativet   modes   aten::Ro   t   schema_strings   ->s   Expected return declarationRm   i   t   .R   iÿÿÿÿRn   s   Expecting closing ) for {}R(   t   operator_namet   overload_names   (^__i|[^_]_$)RP   t   variantsR4   i    t   returnRO   t   requires_tensort   matches_jit_signaturet   cpu_halft   cpu_bfloat16t   cpu_boolt	   cuda_boolt
   deprecatedt   device_guardt   supports_named_tensort   use_c10_dispatchert   not   unboxed_onlyt   fullt   category_overrideRb   t   dispatcht   type_method_definition_dispatcht   python_modulesU   Exception raised in processing function:
{func}
Generated partial declaration:
{decl}t   declt   file(   R–   R—   R˜   (   R}   R   R   t	   ExceptionRU   R"   RX   R   t   searchR   Rv   Rl   R€   R   R   R   RW   t   pprintt   pformatt   printt   syst   stderr(   t   pathst   declarationsR{   Ro   R`   t   xRs   Rr   t   fn_nameRb   R‰   R   R~   t   et   msg(    (    s,   /torch/pytorch/aten/src/ATen/native_parse.pyt   run{  s\    5)
!("*(   t
   __future__R    R   Ry   R¡   R¤   RY   R   R   t   ImportErrorR.   Rl   Rv   R}   R€   Rƒ   R¬   (    (    (    s,   /torch/pytorch/aten/src/ATen/native_parse.pyt   <module>   s    		ƒ	´	 			