ó
àÆ÷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 Z d  d l Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z m Z d  d l m Z d  d	 l m Z d
 e f d „  ƒ  YZ d e j f d „  ƒ  YZ d S(   i    (   t   absolute_importt   print_functiont   divisionN(   t   SkipTest(   t   config(   t   scalar(   t   tensor(   t   Applyt   Op(   t   utils(   t	   _allcloset   IncOneCc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   s+   An Op with only a C (c_code) implementationc         C` s1   t  j | ƒ } | j ƒ  } t |  | g | g ƒ S(   N(   R   t	   as_scalart   typeR   (   t   selft   inputt   output(    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt	   make_node   s    c         C` s   d S(   Ni   (   i   (    (   R   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   c_code_cache_version   s    c         C` s   | \ } | \ } d t  ƒ  S(   Ns   %(z)s = %(x)s + 1;(   t   locals(   R   t   nodet   namet   inputst   outputst   subt   xt   z(    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   c_code!   s    		(    (   t   __name__t
   __module__t   __doc__t	   __props__R   R   R   (    (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyR      s
   		t   TestComputeTestValuec           B` s   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C` sN  t  j j } z.d t  j _ t j d ƒ } t j j d d ƒ j t j	 ƒ | j
 _ t j d ƒ } t j j d d ƒ j t j	 ƒ | j
 _ t j | | ƒ } t | j
 d ƒ s± t ‚ t  j | | g | ƒ } t | | j
 j | j
 j ƒ | j
 j ƒ sù t ‚ t j j d d ƒ j t j	 ƒ | j
 _ |  j t t j | | ƒ Wd  | t  j _ Xd  S(	   Nt   raiseR   i   i   t   yi   t
   test_valuei   (   t   theanoR   t   compute_test_valuet   Tt   matrixt   npt   randomt   randt   astypet   floatXt   tagR#   t   dott   hasattrt   AssertionErrort   functionR
   t   assertRaisest
   ValueError(   R   t   orig_compute_test_valueR   R"   R   t   f(    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   test_variable_only)   s    '''c         C` s  t  j j } zò t j d ƒ } t j d ƒ } t j j d d ƒ j t j	 ƒ | j
 _ d t  j _ t j | | ƒ } t | j
 d ƒ s‹ t ‚ d t  j _ |  j t t j | | ƒ d t  j _ t j d	 t ƒ z |  j t t j | | ƒ Wd  t j d
 t ƒ XWd  | t  j _ Xd  S(   NR   R"   i   i   t   offR#   R!   t   warnt   errort   default(   R$   R   R%   R&   R'   R(   R)   R*   R+   R,   R-   R#   R.   R/   R0   R2   R3   t   warningst   simplefiltert   UserWarning(   R   R4   R   R"   R   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   test_compute_flag@   s     'c         C` sŽ  t  j j } znd t  j _ t j d ƒ } t j j d d ƒ j t j	 ƒ | j
 _ t j d ƒ } t j j d d ƒ j t j	 ƒ | j
 _ t  j t j j d d ƒ j t j	 ƒ ƒ } t j t j | | ƒ | ƒ } t | j
 d ƒ sç t ‚ t  j | | g | ƒ } t | | j
 j | j
 j ƒ | j
 j ƒ s/t ‚ d	 „  } | j t j j d
 d ƒ j t j	 ƒ ƒ |  j t | | | | ƒ Wd  | t  j _ Xd  S(   NR!   R   i   i   R"   i   i   R#   c         S` s   t  j t  j |  | ƒ | ƒ S(   N(   R&   R.   (   R   R"   R   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyR5   q   s    i   (   R$   R   R%   R&   R'   R(   R)   R*   R+   R,   R-   R#   t   sharedR.   R/   R0   R1   R
   t	   set_valueR2   R3   (   R   R4   R   R"   R   t   outt   tfR5   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   test_string_var]   s$    ''*	(c         C` s:  t  j j } zd t  j _ t j d ƒ } t j j d d ƒ j t j	 ƒ | j
 _ t  j t j j d d ƒ j t j	 ƒ d ƒ } t j | | ƒ } t | j
 d ƒ s¨ t ‚ t  j | g | ƒ } t | | j
 j ƒ | j
 j ƒ sä t ‚ | j t j j d d ƒ j t j	 ƒ ƒ |  j t t j | | ƒ Wd  | t  j _ Xd  S(	   NR!   R   i   i   i   R"   R#   i   (   R$   R   R%   R&   R'   R(   R)   R*   R+   R,   R-   R#   R?   R.   R/   R0   R1   R
   R@   R2   R3   (   R   R4   R   R"   R   R5   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   test_sharedz   s    '$	'(c         C` s  t  j j } zò d t  j _ t j j d d ƒ j t j ƒ } t  j t j j d d ƒ j t j ƒ d ƒ } t	 j
 | | ƒ } t | j d ƒ s“ t ‚ t  j g  | ƒ } t | ƒ  | j j ƒ sÃ t ‚ t j j d d ƒ j t j ƒ } |  j t t	 j
 | | ƒ Wd  | t  j _ Xd  S(   NR!   i   i   i   R"   R#   i   (   R$   R   R%   R(   R)   R*   R+   R,   R?   R&   R.   R/   R-   R0   R1   R
   R#   R2   R3   (   R   R4   R   R"   R   R5   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   test_ndarray   s    !$	!c         C` s³   t  j j } z“ d t  j _ t  j t j j d d ƒ j t j ƒ d ƒ } | d d } t	 | j
 d ƒ sn t ‚ t  j g  | ƒ } t | ƒ  | j
 j ƒ sž t ‚ Wd  | t  j _ Xd  S(   NR!   i    i   R   i   i   R#   (   R$   R   R%   R?   R(   R)   R*   R+   R,   R/   R-   R0   R1   R
   R#   (   R   R4   R   R   R5   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   test_empty_elemwise¥   s    $	"c         C` s  t  j j } zþ d t  j _ t j t j j d d ƒ d t j ƒ} t  j	 t j j d d ƒ j
 t j ƒ d ƒ } t j | | ƒ } t | j d ƒ s™ t ‚ t  j g  | ƒ } t | ƒ  | j j ƒ sÉ t ‚ t j t j j d d ƒ d t j ƒ} |  j t t j | | ƒ Wd  | t  j _ Xd  S(	   NR!   i   i   t   dtypei   R"   R#   i   (   R$   R   R%   R&   t   constantR(   R)   R*   R,   R?   R+   R.   R/   R-   R0   R1   R
   R#   R2   R3   (   R   R4   R   R"   R   R5   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   test_constant¶   s    '$	'c         C` s   t  j j } z} d t  j _ t j d ƒ } t j j d d ƒ | j _	 t j
 d ƒ } t j j d d ƒ | j _	 |  j t t j | | ƒ Wd  | t  j _ Xd  S(   NR!   R   i   i   R"   i   (   R$   R   R%   R&   t   fmatrixR(   R)   R*   R-   R#   t   dmatrixR2   t	   TypeErrorR.   (   R   R4   R   R"   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   test_incorrect_typeË   s    c         C` s—   t  j j } zw d t _ t j ƒ  } t j d d t j ƒ| j _	 t j ƒ  } t j d d t j ƒ| j _	 |  j
 t | j | ƒ Wd  | t  j _ Xd  S(   NR!   i   i   RG   (   i   i   (   i   i   (   R$   R   R%   R&   R'   R(   t   zerosR,   R-   R#   R2   R3   t   __mul__(   R   R4   R   R"   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   test_overided_functionÚ   s    	c      	   C` sÜ   t  j j } z¼ d t  j _ t j d ƒ } t j d ƒ } d | j _ t j	 j
 d ƒ j t j ƒ | j _ d „  } t  j d | d t j | ƒ d	 | d
 | ƒ \ } } | d } t | j d ƒ sÇ t ‚ Wd | t  j _ Xd S(   s=   
        Test the compute_test_value mechanism Scan.
        R!   t   kt   Ai   i   c         S` s   |  | S(   N(    (   t   prior_resultRR   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   fxõ   s    t   fnt   outputs_infot   non_sequencest   n_stepsiÿÿÿÿR#   N(   R$   R   R%   R&   t   iscalart   vectorR-   R#   R(   R)   R*   R+   R,   t   scant	   ones_likeR/   R0   (   R   R4   RQ   RR   RT   t   resultt   updatest   final_result(    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt	   test_scanè   s    $	
c      	   C` sD  t  j j } z$d t  j _ t j d ƒ } t j d ƒ } d | j _ t j	 j
 d d ƒ j t j ƒ | j _ d „  } y; t  j d | d t j | ƒ d	 | d
 | ƒ t s¯ t ‚ Wn| t k
 r.t j ƒ  d } t j | ƒ d } d } t j j | d ƒ d | k st | ƒ ‚ | d d k s/t ‚ n XWd  | t  j _ Xd  S(   NR!   RQ   RR   i   i   c         S` s   t  j |  | ƒ S(   N(   R&   R.   (   RS   RR   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyRT     s    RU   RV   RW   RX   i   iûÿÿÿs   test_compute_test_value.pyi    i   RT   (   R$   R   R%   R&   RY   R'   R-   R#   R(   R)   R*   R+   R,   R[   R\   t   FalseR0   R3   t   syst   exc_infot	   tracebackt
   extract_tbt   ost   patht   split(   R   R4   RQ   RR   RT   t   tbt
   frame_infot   expected(    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   test_scan_err1  s,    '		,c         C` s<  t  j j } zd t  j _ t j d ƒ } t j d ƒ } d | j _ t j	 j
 d d ƒ j t j ƒ | j _ d „  } |  j t t  j d | d t j | j ƒ d	 | d
 | ƒy> t  j d | d t j | j ƒ d	 | d
 | ƒ t sé t ‚ Wn: t k
 r&} t | ƒ j d ƒ s't t | ƒ ƒ ‚ n XWd  | t  j _ Xd  S(   NR!   RQ   RR   i   i   c         S` s   t  j |  | ƒ S(   N(   R&   R.   (   RS   RR   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyRT   5  s    RU   RV   RW   RX   s   could not broadcast input(   R$   R   R%   R&   RY   R'   R-   R#   R(   R)   R*   R+   R,   R2   R3   R[   R\   Ra   R0   t   strt
   startswith(   R   R4   RQ   RR   RT   t   e(    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   test_scan_err2)  s0    '				/c      
   C` sÞ   d t  f d „  ƒ  Y} t j j } z¨ d t j _ t j d ƒ } d | j _ | ƒ  | ƒ } |  j t	 t
 j f | j j j | j d d g d i d	 d
 6ƒ t | j d ƒ s± t ‚ | j j d k sÉ t ‚ Wd  | t j _ Xd  S(   Nt   IncOnePythonc           B` s&   e  Z d  Z d Z d „  Z d „  Z RS(   s1   An Op with only a Python (perform) implementationc         S` s1   t  j | ƒ } | j ƒ  } t |  | g | g ƒ S(   N(   R   R   R   R   (   R   R   R   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyR   S  s    c         S` s$   | \ } | \ } | d | d <d  S(   Ni   i    (    (   R   R   R   R   R   R   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   performX  s    		(    (   R   R   R   R   R   Rr   (    (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyRq   O  s   	R!   t   ii   t   oR   R   t    t   failR#   i   (   R   R$   R   R%   R   t   int32R-   R#   R2   t   NotImplementedErrorR	   t   MethodNotDefinedt   ownert   opR   R/   R0   (   R   Rq   R4   Rs   Rt   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   test_no_c_codeN  s     c         C` sÖ   t  j j s t d ƒ ‚ n  t  j j } z› d t  j _ t j d ƒ } d | j _ t	 ƒ  | ƒ } |  j
 t t j f | j j j | j d d  g ƒ t | j d ƒ s© t ‚ | j j d k sÁ t ‚ Wd  | t  j _ Xd  S(   Ns0   G++ not available, so we need to skip this test.R!   Rs   i   i    R#   i   (   R$   R   t   cxxR   R%   R   Rw   R-   R#   R   R2   Rx   R	   Ry   Rz   R{   Rr   t   NoneR/   R0   (   R   R4   Rs   Rt   (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   test_no_performr  s    c         C` ss   t  j j } zS d t  j _ t  j t j d d t j ƒƒ j d d ƒ } t  j g  d | g ƒWd  | t  j _ Xd  S(   NR!   i   RG   R   i    R   (   i   (	   R$   R   R%   R?   R(   RN   R,   t
   dimshuffleR1   (   R   R4   t   init_Mu1(    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt    test_disabled_during_compilationŒ  s    '(   R   R   R6   R>   RC   RD   RE   RF   RI   RM   RP   R`   Rl   Rp   R|   R   R‚   (    (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyR    '   s   											$	%	$	(   t
   __future__R    R   R   Rf   Rb   Rd   R;   t   numpyR(   t   nose.plugins.skipR   t   unittestR$   R   R   R   R&   t
   theano.gofR   R   R	   t   theano.tensor.basicR
   R   t   TestCaseR    (    (    (    sH   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_compute_test_value.pyt   <module>   s    