ó
àÆ÷Xc           @` s«   d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l	 m
 Z
 d d l j Z d d l m Z d e j f d „  ƒ  YZ e d k r§ e j ƒ  n  d S(	   s   
Test of memory profiling

i    (   t   absolute_importt   print_functiont   divisionN(   t   StringIO(   t   ifelset   Test_profilingc           B` s    e  Z d  Z d „  Z d „  Z RS(   s<   
    Test of Theano profiling with min_peak_memory=True
    c      	   C` s  t  j j } t  j j } t  j j j } z+t t  j _ t t  j _ t t  j j _ g  t d ƒ D] } t j	 d | ƒ ^ q^ } g  } | g  t t
 | ƒ d ƒ D]0 } t j | | | | d ƒ j d d ƒ ^ q 7} | g  t t
 | ƒ d ƒ D] } | | | | d ^ qî 7} t  j t d t ƒ} t  j j d k rAd	 } n d  } t  j | | d
 | d d d | ƒ}	 g  t t
 | ƒ ƒ D] } t j d d d ƒd ^ q~}
 |	 |
 Œ  t ƒ  } |	 j j | ƒ | j ƒ  } g  | j d ƒ D] } d | k râ| ^ qâ} g  | j d ƒ D] } d | k r| ^ q} t  j j d k r»d | k s^t | | f ƒ ‚ d | k s|t | | f ƒ ‚ d | k sšt | | f ƒ ‚ d | k sQt | | f ƒ ‚ n– d | k sÙt | | f ƒ ‚ d | k s÷t | | f ƒ ‚ d | k st | | f ƒ ‚ d | k s3t | | f ƒ ‚ d | k sQt | | f ƒ ‚ Wd  | t  j _ | t  j _ | t  j j _ Xd  S(   Ni   s   val%ii   t   axist
   gpu_checkst	   DebugModet
   DEBUG_MODEt   FAST_COMPILEt   FAST_RUNt   profilet   namet   test_profilingt   modei   t   dtypet   float32s   
s   Max if linkers   Minimum peakt   cpus   CPU: 4112KB (8204KB)s   CPU: 8204KB (12296KB)s   CPU: 8208KBs6   Minimum peak from all valid apply node order is 4104KBs   CPU: 16KB (16KB)s   GPU: 8204KB (8204KB)s   GPU: 12300KB (12300KB)s   GPU: 8212KBs6   Minimum peak from all valid apply node order is 4116KB(   R   R	   R
   (   t   theanot   configR   t   profile_memoryt	   profilingt   min_peak_memoryt   Truet   ranget   Tt   fvectort   lent   outert   sumt   ProfileStatst   FalseR   t   Nonet   functiont   npt   arangeR   t   summaryt   getvaluet   splitt   devicet   AssertionError(   t   selft   config1t   config2t   config3t   it   xt   zt   pt   mt   ft   inpt   buft
   the_stringt   lt   lines1t   lines2(    (    sC   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_profiling.pyR      sN    ,Q=		8
	..c      	   C` s;  t  j j } t  j j } zt t  j _ t t  j _ t j d d ƒ \ } } t j d d ƒ \ } } t t j | | ƒ | d | d ƒ } t  j	 t
 d t
 ƒ} t  j j d k r¹ d
 }	 n d  }	 t  j | | | | g | d | d d d |	 ƒ}
 d } d } d } d } |
 | | | | ƒ Wd  | t  j _ | t  j _ Xd  S(   Nt   at   bR/   t   yi   R   R   R	   R
   R   R   R   t   test_ifelseR   g        g      ð?i
   i   (   s	   DebugModes
   DEBUG_MODEs   FAST_COMPILE(   R   R   R   R   R   R   t   scalarsR   t   ltR   R    R   R!   R"   (   R*   R+   R,   R:   R;   R/   R<   R0   R1   R2   t   f_ifelset   val1t   val2t   big_mat1t   big_mat2(    (    sC   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_profiling.pyR=   M   s*    &	'	(   t   __name__t
   __module__t   __doc__R   R=   (    (    (    sC   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_profiling.pyR      s   	7t   __main__(   RG   t
   __future__R    R   R   t   unittestt   numpyR#   R   t	   six.movesR   t   theano.tensort   tensorR   t   theano.ifelseR   t   TestCaseR   RE   t   main(    (    (    sC   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_profiling.pyt   <module>   s   _