ó
V^c           @   s÷   d  d l  Z  d  d l Z d d l m Z d d d d d d	 g Z y d  d
 l m Z Wn3 e k
 r d  d l m Z e d d  j Z n Xy d  d l	 m
 Z Wn! e k
 rÁ d  d l	 m Z n Xe d d  Z d Z d   Z d   Z d   Z d S(   i˙˙˙˙Ni   (   t   nested_dictt   CodeTemplatet   IDENT_REGEXt
   YamlLoaderR    t   split_name_paramst   write(   R   (   t   import_modulet   code_templates   aten/src/ATen/code_template.py(   t   CLoader(   t   Loadert   @s   generated from ${filename}s   (^|\W){}($|\W)c         C   s4   t  j d |   j   \ } } } | | j d  f S(   Ns   (\w+)(\.\w+)?\((.*)\)s   , (   t   ret   matcht   groupst   split(   t	   prototypet   namet   overload_namet   params(    (    s   tools/autograd/utils.pyR   '   s    !c         C   sL   |  j  d  r, |  j  d  r, |  d  }  n  |  j  d  rH |  d  }  n  |  S(   Nt   _t   __i˙˙˙˙t   _outiü˙˙˙(   t   endswith(   t   api_name(    (    s   tools/autograd/utils.pyt   uninplace_api_name1   s
    c         C   sÓ   t  j d | j  | d <t j j |  |  } y( t | d   } | j   } Wd  QXWn t k
 ro d  } n X| j |  } | | k rÁ t | d  " } d j
 |  GH| j |  Wd  QXn d j
 |  GHd  S(   Nt   filenamet   generated_commentt   rt   ws
   Writing {}s   Skipped writing {}(   t   GENERATED_COMMENTt
   substituteR   t   ost   patht   joint   opent   readt   IOErrort   Nonet   formatR   (   t   dirnameR   t   templatet   envR    t   ft   old_valt   new_val(    (    s   tools/autograd/utils.pyR   9   s    
(   R   R   R    t   __all__t   src.ATen.code_templateR   t   ImportErrort   tools.shared.module_loaderR   t   yamlR   R   R	   R   R   R   R   R   (    (    (    s   tools/autograd/utils.pyt   <module>   s&   	
	