ó
àÆ÷Xc           @` sÖ  d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 m
 Z
 d  d l m Z m Z m Z d  d l Z d  d l m Z d  d l m Z e j d ƒ Z d e f d	 „  ƒ  YZ e j d
 d ƒ Z e d „ Z e e d e ƒZ d „  Z e ƒ  Z e r&e j n e j i e j d e j  j! e j  j" d ƒ ƒ d ƒ d 6e j d d ƒ d 6e j d d ƒ d 6e j d d ƒ d 6e j d d ƒ d 6e# e j$ ƒ  ƒ d 6ƒ Z% e% j& e ƒ e j' ƒ  Z( e( j& e ƒ d e) f d „  ƒ  YZ* e+ d „ Z, g  Z- e d „ Z. d „  Z/ d e) f d „  ƒ  YZ0 e0 ƒ  Z1 e1 e d „ Z2 d e) f d  „  ƒ  YZ3 d! e3 f d" „  ƒ  YZ4 d# e3 f d$ „  ƒ  YZ5 d e d% „ Z7 d e d& „ Z8 d e d' „ Z9 d e d( „ Z: d S()   i    (   t   absolute_importt   print_functiont   divisionN(   t   wraps(   t   StringIOt   PY3t	   iteritems(   t   configparser(   t   string_typess   theano.configparsert   TheanoConfigWarningc           B` s    e  Z d  d „ Z e e ƒ Z RS(   i    c         C` s   t  j | |  d | d ƒd  S(   Nt
   stackleveli   (   t   warningst   warn(   t   clst   messageR
   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyR      s    (   t   __name__t
   __module__R   t   classmethod(    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyR	      s   t   THEANO_FLAGSt    c         C` s»   i  } t  j  |  d t ƒ} d | _ t | _ x‡ | D] } | j ƒ  } | sR q4 n  | j d d ƒ } t | ƒ d k r | r³ t j d | d d d ƒq³ q4 | \ } } | | | <q4 W| S(   sT   
    Parses a config string (comma-separated key=value components) into a dict.
    t   posixt   ,t   =i   s)   Config key '%s' has no value, ignoring iti    R
   (	   t   shlext   Truet
   whitespacet   whitespace_splitt   stript   splitt   lenR	   R   (   t   config_stringt   issue_warningst   config_dictt   my_splittert   kv_pairt   kv_tuplet   kt   v(    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   parse_config_string"   s$    		R   c          C` s   g  t  j d d ƒ j t  j ƒ D] }  t  j j |  ƒ ^ q } t  j d ƒ d  k r} t j d k r} | j	 t  j j d ƒ ƒ n  | S(   Nt   THEANORCs   ~/.theanorct   win32s   ~/.theanorc.txt(
   t   ost   getenvR   t   pathsept   patht
   expandusert   Nonet   syst   platformt   append(   t   st   rval(    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   config_files_from_theanorcB   s
    :$t   USERt   ~iÿÿÿÿt   LSCRATCHt   TMPDIRt   TEMPt   TMPt   PIDt   change_flagsc           B` s5   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z RS(   s‚   
    Use this as a decorator or context manager to change the value of
    Theano config variables.

    Useful during tests.
    c         K` s   t  ƒ  } t  | ƒ } | j | ƒ xb | D]Z } g  t j j D] } | j | k r< | ^ q< } t | ƒ d k su t ‚ | d | | <q) W| |  _ | |  _	 d  S(   Ni   i    (
   t   dictt   updatet   theanoR   t   _config_var_listt   fullnameR   t   AssertionErrort   confst   new_vals(   t   selft   argst   kwargsRC   R$   R%   t   l(    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   __init__e   s    		c         ` s"   t  ˆ  ƒ ‡  ‡ f d †  ƒ } | S(   Nc          ` s   ˆ  ˆ  |  | Ž  SWd  QXd  S(   N(    (   RF   RG   (   t   fRE   (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   resr   s    (   R   (   RE   RJ   RK   (    (   RJ   RE   s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   __call__q   s    c         C` s˜   i  |  _  x6 t |  j ƒ D]% \ } } | j t d  ƒ |  j  | <q Wy; x4 t |  j ƒ D]# \ } } | j d  |  j | ƒ qU WWn |  j ƒ  ‚  n Xd  S(   N(	   t   old_valsR   RC   t   __get__R   R.   t   __set__RD   t   __exit__(   RE   R$   R%   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt	   __enter__x   s    	
c         G` s;   x4 t  |  j ƒ D]# \ } } | j d  |  j | ƒ q Wd  S(   N(   R   RC   RO   R.   RM   (   RE   RF   R$   R%   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyRP   ƒ   s    (    (   R   R   t   __doc__RI   RL   RQ   RP   (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyR<   ^   s
   		c         C` s   y | r t  j |  ƒ St  |  SWn t k
 r2 n X|  j d d ƒ } t | ƒ d k rf t |  ƒ ‚ n  t | ƒ d k r‡ | \ } } n d |  } } y< y t j | | ƒ SWn! t j k
 rÎ t	 j | | ƒ SXWn) t j
 t j f k
 rû t |  ƒ ‚ n Xd S(   sÞ   Return the overriding config value for a key.
    A successful search returns a string value.
    An unsuccessful search raises a KeyError

    The (decreasing) priority order is:
    - THEANO_FLAGS
    - ~./theanorc

    t   .i   i   t   globalN(   t   THEANO_FLAGS_DICTt   popt   KeyErrort   rsplitR   t
   theano_cfgt   gett   ConfigParsert   InterpolationErrort   theano_raw_cfgt   NoOptionErrort   NoSectionError(   t   keyt
   delete_keyt
   key_tokenst   sectiont   option(    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   fetch_val_for_keyˆ   s&    c         C` ss   xl t  D]d } t | d | ƒ| r< t d | j d | ƒn  t d | j t d  ƒ d | ƒt d d | ƒq Wd  S(   Nt   files	       Doc: s       Value: R   (   R@   t   printt   docRN   R   R.   (   t   thingt   buft	   print_doct   cv(    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   _config_print±   s    c       	   C` sy   t  g  t D] }  |  j r
 |  ^ q
 d d „  ƒ} t j j j d j g  | D]% } d | j | j	 t
 d ƒ f ^ qJ ƒ ƒ S(   s  
    Return a string md5 of the current config options. It should be such that
    we can safely assume that two different config setups will lead to two
    different strings.

    We only take into account config options for which `in_c_key` is True.
    R`   c         S` s   |  j  S(   N(   RA   (   Rl   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   <lambda>Ã   s    s   
s   %s = %sN(   t   sortedR@   t   in_c_keyR?   t   goft   utilst   hash_from_codet   joinRA   RN   R   R.   (   t   ct   all_optsRl   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   get_config_md5º   s    %t   TheanoConfigParserc           B` s   e  Z e Z e d  „ Z RS(   c         C` s)   t  ƒ  } t |  j | d | ƒ| j ƒ  S(   NRk   (   R   Rm   t	   __class__t   getvalue(   RE   Rk   t   sio(    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   __str__Ì   s    	(   R   R   R   t   _i_am_a_config_classR|   (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyRx   È   s   c         C` s¼  | t  k r |  | _ n  |  j d ƒ } t | ƒ d k rï t | | d ƒ s d t f d „  ƒ  Y} t | j | d | ƒ  ƒ n  t | | d ƒ } t | d t	 ƒ s´ t
 | t ƒ rÆ t d | ƒ ‚ n  t d j | d ƒ | | d | d	 | ƒSt | |  ƒ rt d
 | j ƒ ‚ n  | | _ | | _ t | j ƒ sS| j | t | ƒ d t ƒnA y- t | j ƒ | j | t | ƒ d t ƒWn t k
 r“n Xt | j | d | ƒ t j | ƒ d S(   s¶  Add a new variable to theano.config

    :type name: string for form "[section0.[section1.[etc]]].option"
    :param name: the full name for this configuration variable.

    :type doc: string
    :param doc: What does this variable specify?

    :type configparam: ConfigParam instance
    :param configparam: an object for getting and setting this configuration
        parameter

    :type root: object
    :param root: used for recursive calls -- do not provide an argument for
        this parameter.

    :type in_c_key: boolean
    :param in_c_key: If True, then whenever this config option changes, the
    key associated to compiled C modules also changes, i.e. it may trigger a
    compilation of these modules (this compilation will only be partial if it
    turns out that the generated C code is unchanged). Set this option to False
    only if you are confident this option should not affect C code compilation.

    :returns: None
    RS   i   i    t   SubObjc           B` s   e  Z e Z RS(    (   R   R   R   R}   (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyR~   	  s   R}   s4   Internal config nodes must be config class instancest   rootRp   s   This name is already takenRa   N(   t   configRA   R   R   t   hasattrt   objectt   setattrRy   t   getattrt   Falset
   isinstancet   typet	   TypeErrort   AddConfigVarRt   t   AttributeErrorRh   Rp   t   callablet   defaultRN   R   Re   RW   R@   R1   (   t   nameRh   t   configparamR   Rp   t   sectionsR~   t   newroot(    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyR‰   â   s:    		 t   ConfigParamc           B` s,   e  Z d e d  „ Z e d „ Z d „  Z RS(   c         C` s(   | |  _  | |  _ | |  _ t |  _ d S(   s¥   
        If allow_override is False, we can't change the value after the import
        of Theano. So the value should be the same during all the execution.
        N(   RŒ   t   filtert   allow_overrideR   t
   is_default(   RE   RŒ   R’   R“   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyRI   -  s    			c         C` s–   | d  k r |  St |  d ƒ s y" t |  j d | ƒ} t |  _ Wn8 t k
 r{ t |  j ƒ ro |  j ƒ  } q| |  j } n X|  j	 | | ƒ n  |  j
 S(   Nt   valRa   (   R.   R   Re   RA   R…   R”   RW   R‹   RŒ   RO   R•   (   RE   R   t   type_Ra   t   val_str(    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyRN   @  s    	c         C` sS   |  j  r( t |  d ƒ r( t d ƒ ‚ n  |  j rF |  j | ƒ |  _ n	 | |  _ d  S(   NR•   sE   Can't change the value of this config parameter after initialization!(   R“   R   t	   ExceptionR’   R•   (   RE   R   R•   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyRO   Q  s    	N(   R   R   R.   R   RI   R…   RN   RO   (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyR‘   +  s   t   EnumStrc           B` s   e  Z d  „  Z d „  Z RS(   c         ` s­   | ˆ _  | f | ˆ _ x; ˆ j D]0 } t | t ƒ s# t d | t | ƒ ƒ ‚ q# q# W| j d d  ƒ ‰  ‡  ‡ f d †  } | j d t ƒ } t	 t
 ˆ ƒ j | | | ƒ d  S(   Ns7   Valid values for an EnumStr parameter should be stringst   convertc         ` sK   ˆ  r ˆ  |  ƒ }  n  |  ˆ j  k r( |  St d |  ˆ j ˆ j  f ƒ ‚ d  S(   NsJ   Invalid value ("%s") for configuration variable "%s". Valid options are %s(   t   allt
   ValueErrorRA   (   R•   (   Rš   RE   (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyR’   j  s    R“   (   RŒ   R›   R†   R   Rœ   R‡   RZ   R.   R   t   superR™   RI   (   RE   RŒ   t   optionsRG   R•   R’   t   over(    (   Rš   RE   s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyRI   ^  s    	
c         C` s   d |  j  |  j f S(   Ns   %s (%s) (   RA   R›   (   RE   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyR|   w  s    (   R   R   RI   R|   (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyR™   ]  s   	t
   TypedParamc           B` s    e  Z d e d  „ Z d „  Z RS(   c         ` sA   ˆ ˆ _  ‡  ‡ ‡ f d †  } t t ˆ ƒ j | | d | ƒd  S(   Nc         ` sK   ˆ |  ƒ } t  ˆ  ƒ rG ˆ  | ƒ r( | St d |  ˆ j f |  ƒ ‚ n  | S(   Ns3   Invalid value (%s) for configuration variable "%s".(   R‹   Rœ   RA   (   R•   t   cast_val(   t   is_validt   mytypeRE   (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyR’     s    R“   (   R£   R   R    RI   (   RE   RŒ   R£   R¢   R“   R’   (    (   R¢   R£   RE   s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyRI   |  s    	c         C` s   d |  j  |  j f S(   Ns   %s (%s) (   RA   R£   (   RE   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyR|   Ž  s    N(   R   R   R.   R   RI   R|   (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyR    {  s   c         C` s   t  |  t | d | ƒS(   NR“   (   R    t   str(   RŒ   R¢   R“   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   StrParam’  s    c         C` s   t  |  t | d | ƒS(   NR“   (   R    t   int(   RŒ   R¢   R“   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   IntParam–  s    c         C` s   t  |  t | d | ƒS(   NR“   (   R    t   float(   RŒ   R¢   R“   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt
   FloatParamš  s    c         C` s=   d „  } d „  } | d  k r' | } n  t |  | | d | ƒS(   Nc         S` s<   |  d d d t  g k r t  S|  d d d t g k r8 t Sd  S(   NR…   t   falset   0R   t   truet   1(   R…   R   (   R2   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   booltype¡  s    c      	   S` s0   |  d d d d d d t  t g k r( t St  Sd  S(   NR…   Rª   R«   R   R¬   R­   (   R…   R   (   R2   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   is_valid_bool§  s    $R“   (   R.   R    (   RŒ   R¢   R“   R®   R¯   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt	   BoolParamž  s    			(;   t
   __future__R    R   R   t   loggingR)   R   R/   R   t	   functoolsR   t   sixR   R   R   R?   t   theano.compatR   R[   R   t	   getLoggert   _loggert   WarningR	   R*   R   R   R&   RU   R4   t   config_filest   SafeConfigParserR,   R   R-   R¤   t   getpidRY   t   readt   RawConfigParserR]   R‚   R<   R…   Re   R@   Rm   Rw   Rx   R€   R‰   R‘   R™   R    R.   R¥   R§   R©   R°   (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/configparser.pyt   <module>   sV   			2*&		
	I2