ó
àÆ÷Xc           @` sS   d  d l  m Z m Z m Z d  d l Z d  d l Z d „  Z d „  Z d „  Z	 d S(   i    (   t   absolute_importt   print_functiont   divisionNc          ` s…   t  g ‰  ‡  f d †  }  t j j d ƒ } t j | g t j j | ƒ | g d t j j d |  ƒ ƒ} | d ƒ ˆ  d s t ‚ d S(   s@   
    Test the code snippet example that detects NaN values.
    c         ` s©   x¢ | j  D]— } t j | d ƒ j ƒ  r
 t d ƒ t j j | ƒ t d g  | j D] } | d ^ qS ƒ t d g  | j  D] } | d ^ q{ ƒ t	 ˆ  d <Pq
 q
 Wd  S(   Ni    s   *** NaN detected ***s   Inputs : %ss   Outputs: %s(
   t   outputst   npt   isnant   anyt   printt   theanot   printingt
   debugprintt   inputst   True(   t   it   nodet   fnt   outputt   input(   t   nan_detected(    sE   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_monitormode.pyt
   detect_nan   s    
((
t   xt   modet	   post_funci    N(	   t   FalseR   t   tensort   dscalart   functiont   logt   compilet   MonitorModet   AssertionError(   R   R   t   f(    (   R   sE   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_monitormode.pyt   test_detect_nan   s    	
%
c          ` s»   t  g ‰  ‡  f d †  }  t j j d ƒ } t j j d |  ƒ } | j d ƒ } t j | g t j j | ƒ | g d | ƒ} t	 | j
 j j ƒ d k s t ‚ | d ƒ ˆ  d s· t ‚ d S(	   s+   
    Test that we can remove optimizer
    c         ` s©   x¢ | j  D]— } t j | d ƒ j ƒ  r
 t d ƒ t j j | ƒ t d g  | j D] } | d ^ qS ƒ t d g  | j  D] } | d ^ q{ ƒ t	 ˆ  d <Pq
 q
 Wd  S(   Ni    s   *** NaN detected ***s   Inputs : %ss   Outputs: %s(
   R   R   R   R   R   R   R	   R
   R   R   (   R   R   R   R   R   (   R   (    sE   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_monitormode.pyR   %   s    
((
R   R   t   fusionR   i   i    N(   R   R   R   R   R   R   t	   excludingR   R   t   lent   makert   fgrapht   apply_nodesR   (   R   R   R   R   (    (   R   sE   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_monitormode.pyt   test_optimizer   s    	
%	!
c          ` s  t  g ‰  ‡  f d †  }  t j j d ƒ } t j j d |  ƒ } | j d d ƒ } t j j | | ƒ } t j j | ƒ | } t j	 | g | g d | ƒ} t
 | j j j ƒ d k s» t ‚ | j j j ƒ  d j j sÞ t ‚ | d	 d	 g ƒ ˆ  d	 sþ t ‚ d
 S(   sI   
    Test that we can remove optimizers including inplace optimizers
    c         ` s©   x¢ | j  D]— } t j | d ƒ j ƒ  r
 t d ƒ t j j | ƒ t d g  | j D] } | d ^ qS ƒ t d g  | j  D] } | d ^ q{ ƒ t	 ˆ  d <Pq
 q
 Wd  S(   Ni    s   *** NaN detected ***s   Inputs : %ss   Outputs: %s(
   R   R   R   R   R   R   R	   R
   R   R   (   R   R   R   R   R   (   R   (    sE   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_monitormode.pyR   B   s    
((
R   R   t   local_elemwise_fusiont   inplace_elemwise_optimizerR   i   iÿÿÿÿi    N(   R   R   R   t   vectorR   R   R"   t   outerR   R   R#   R$   R%   R&   R   t   toposortt   opt   destroy_map(   R   R   R   t   ot   outR   (    (   R   sE   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_monitormode.pyt   test_not_inplace<   s    	
			!#(
   t
   __future__R    R   R   t   numpyR   R   R    R'   R1   (    (    (    sE   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_monitormode.pyt   <module>   s
   		