ó
àÆ÷Xc           @` s^  d  d l  m Z m Z m Z d  d l m 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 m Z d  d l m Z m Z m Z d  d l m Z d  d	 l m Z d
 „  Z d e f d „  ƒ  YZ e ƒ  Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e ƒ  Z  d e f d „  ƒ  YZ! e! ƒ  Z" d e f d „  ƒ  YZ# e# ƒ  Z$ d e f d „  ƒ  YZ% e% ƒ  Z& d „  Z' d „  Z( d „  Z) d „  Z* d „  Z+ d „  Z, d  „  Z- d! „  Z. d" „  Z/ d# „  Z0 d$ „  Z1 d% e2 f d& „  ƒ  YZ3 d' „  Z4 d( „  Z5 d) „  Z6 d* e f d+ „  ƒ  YZ7 e7 ƒ  Z8 d, „  Z9 d- „  Z: d S(.   i    (   t   absolute_importt   print_functiont   division(   t   SkipTestN(   t   PerformLinker(   t   CLinkert
   DualLinkert   OpWiseCLinker(   t   Type(   t   Variablet   Applyt   Constant(   t   Op(   t   fgc         C` s   t  |  t ƒ s t ‚ |  S(   N(   t
   isinstanceR	   t   AssertionError(   t   x(    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   as_variable   s    t   TDoublec           B` sn   e  Z e e d  „ Z e d „ Z d „  Z d „  Z e d „ Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z RS(
   c         C` s
   t  | ƒ S(   N(   t   float(   t   selft   datat   strictt   allow_downcast(    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   filter   s    c         C` s   d t  ƒ  S(   Ns*   double %(name)s; void* %(name)s_bad_thing;(   t   locals(   R   t   namet   subt   check_input(    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt	   c_declare   s    c         C` s   d t  ƒ  S(   Nsy   
        %(name)s = 0;
        %(name)s_bad_thing = malloc(100000);
        //printf("Initializing %(name)s\n");
        (   R   (   R   R   R   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   c_init   s    c         C` s
   t  | ƒ S(   N(   t   str(   R   R   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt	   c_literal#   s    c         C` s   d t  t ƒ  |  S(   Ns  
        if (!PyFloat_Check(py_%(name)s)) {
            PyErr_SetString(PyExc_TypeError, "not a double!");
            %(fail)s
        }
        %(name)s = PyFloat_AsDouble(py_%(name)s);
        %(name)s_bad_thing = NULL;
        //printf("Extracting %(name)s\n");
        (   t   dictR   (   R   R   R   R   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt	   c_extract&   s    	c         C` s   d t  ƒ  S(   NsÃ   
        Py_XDECREF(py_%(name)s);
        py_%(name)s = PyFloat_FromDouble(%(name)s);
        if (!py_%(name)s)
            py_%(name)s = Py_None;
        //printf("Syncing %(name)s\n");
        (   R   (   R   R   R   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   c_sync1   s    c         C` s   d t  ƒ  S(   Ns{   
        //printf("Cleaning up %(name)s\n");
        if (%(name)s_bad_thing)
            free(%(name)s_bad_thing);
        (   R   (   R   R   R   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt	   c_cleanup:   s    c         C` s   d S(   Ni   (   i   (    (   R   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   c_code_cache_versionA   s    c         C` s   t  |  ƒ t  | ƒ k S(   N(   t   type(   R   t   other(    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   __eq__D   s    c         C` s   t  t |  ƒ ƒ S(   N(   t   hashR&   (   R   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   __hash__G   s    (   t   __name__t
   __module__t   FalseR   t   TrueR   R   R    R"   R#   R$   R%   R(   R*   (    (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyR      s   							c         C` s   t  t d  d  d |  ƒS(   NR   (   R	   t   tdoublet   None(   R   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   doubleM   s    t   MyOpc           B` s;   e  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   t   ninR   c         C` s   | |  _  | |  _ d  S(   N(   R3   R   (   R   R3   R   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   __init__U   s    	c         G` s…   t  | ƒ |  j k s t ‚ t t t | ƒ ƒ } x, | D]$ } | j t k	 r7 t d ƒ ‚ q7 q7 Wt	 |  j
 d ƒ g } t |  | | ƒ S(   Ns   Error 1t   _R(   t   lenR3   R   t   listt   mapR   R&   R/   t	   ExceptionR1   R   R
   (   R   t   inputst   inputt   outputs(    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt	   make_nodeY   s    c         C` s   |  j  S(   N(   R   (   R   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   __str__b   s    c         C` s    | \ } |  j  | Œ  | d <d  S(   Ni    (   t   impl(   R   t   nodeR:   t   out_t   out(    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   performe   s    	c         C` s   d S(   Ni   (   i   (    (   R   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyR%   i   s    (   s   nins   name(   R+   R,   t	   __props__R4   R=   R>   RC   R%   (    (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyR2   Q   s   					t   Binaryc           B` s   e  Z d  „  Z RS(   c         C` s   t  j |  d |  j j ƒ d  S(   Ni   (   R2   R4   t	   __class__R+   (   R   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyR4   s   s    (   R+   R,   R4   (    (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyRE   r   s   t   Addc           B` s   e  Z d  „  Z d „  Z RS(   c   	      C` s    | \ } } | \ } d t  ƒ  S(   Ns   %(z)s = %(x)s + %(y)s;(   R   (	   R   R@   R   t   inpRB   R   R   t   yt   z(    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   c_codex   s    	c         C` s   | | S(   N(    (   R   R   RI   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyR?   }   s    (   R+   R,   RK   R?   (    (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyRG   w   s   	t   BadSubc           B` s   e  Z d  „  Z d „  Z RS(   c   	      C` s    | \ } } | \ } d t  ƒ  S(   Ns   %(z)s = %(x)s - %(y)s;(   R   (	   R   R@   R   RH   RB   R   R   RI   RJ   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyRK   ƒ   s    	c         C` s   d S(   Niöÿÿÿ(    (   R   R   RI   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyR?   ˆ   s    (   R+   R,   RK   R?   (    (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyRL   ‚   s   	t   Mulc           B` s   e  Z d  „  Z d „  Z RS(   c   	      C` s    | \ } } | \ } d t  ƒ  S(   Ns   %(z)s = %(x)s * %(y)s;(   R   (	   R   R@   R   RH   RB   R   R   RI   RJ   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyRK   Ž   s    	c         C` s   | | S(   N(    (   R   R   RI   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyR?   “   s    (   R+   R,   RK   R?   (    (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyRM      s   	t   Divc           B` s   e  Z d  „  Z d „  Z RS(   c   	      C` s    | \ } } | \ } d t  ƒ  S(   Ns   %(z)s = %(x)s / %(y)s;(   R   (	   R   R@   R   RH   RB   R   R   RI   RJ   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyRK   ™   s    	c         C` s   | | S(   N(    (   R   R   RI   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyR?   ž   s    (   R+   R,   RK   R?   (    (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyRN   ˜   s   	c          C` s1   t  d ƒ }  t  d ƒ } t  d ƒ } |  | | f S(   NR   RI   RJ   (   R1   (   R   RI   RJ   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyR:   £   s    c         C` s   t  j |  | ƒ } | S(   N(   R   t   FunctionGraph(   R:   R<   t   e(    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   Envª   s    c          C` s¾   t  j j s t d ƒ ‚ n  t ƒ  \ }  } } t t t |  | ƒ t |  | ƒ ƒ t t |  | ƒ | ƒ ƒ } t	 ƒ  j
 t |  | | g | g ƒ ƒ } | j ƒ  } | d d d ƒ d k sº t ‚ d  S(   Ns0   G++ not available, so we need to skip this test.g       @(   t   theanot   configt   cxxR   R:   t   addt   mult   divt   bad_subR   t   acceptRQ   t   make_functionR   (   R   RI   RJ   RP   t   lnkt   fn(    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   test_clinker_straightforward³   s    <'c          C` sï   t  j j s t d ƒ ‚ n  t ƒ  \ }  } } t t d ƒ } t t t |  | ƒ t	 |  | ƒ ƒ t
 t
 |  | ƒ | ƒ ƒ } t ƒ  j t |  | g | g ƒ ƒ } | j ƒ  } t | d d ƒ d ƒ d k  sÍ t ‚ | j ƒ  } d | k së t ‚ d  S(   Ns0   G++ not available, so we need to skip this test.g"GBtk~@g       @g•È‘Ýš¿?g•Ö&è.>s
   4.12345678(   RR   RS   RT   R   R:   R   R/   RU   RV   RW   RX   R   RY   RQ   RZ   t   absR   t   code_gen(   R   RI   RJ   RP   R[   R\   t   code(    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   test_clinker_literal_inlining½   s    <$%c       
   C` s+  t  j j s t d ƒ ‚ n  t  j d d ƒ }  t  j j ƒ  } t  j j ƒ  } t j	 d d d g d d d g d	 d
 d g g d t  j j
 ƒ} t j	 d d d g d t  j j
 ƒ} xv | | d t j d ƒ | d t j d ƒ g D]B } t  j d | | g d | g d d d |  ƒ } | | | ƒ } qá Wd  S(   Ns0   G++ not available, so we need to skip this test.t   linkert   cg&pën®M@gòk®ø³LŸ¾gä¥ˆ¼?Å¾gzùBmÀLî?g¤.cTcS ¿gîqEI@Å¾gOXâeS ¿g.9î”Öð?t   dtypeg\[4o®M@g8íœ†úð?g"/RÅàî?i    i   R:   R<   t   on_unused_inputt   ignoret   mode(   RR   RS   RT   R   t   Modet   tensort   matrixt   vectort   npt   arrayt   floatXt   identityt   function(   Rg   t   At   input1t
   normal_svdt   orientationit   out1t	   benchmark(    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   test_clinker_literal_cacheÌ   s&    			c          C` s‹   t  j j s t d ƒ ‚ n  t ƒ  \ }  } } t j |  | ƒ } t ƒ  j t	 | j | j
 ƒ ƒ } | j ƒ  } | d d ƒ d k s‡ t ‚ d  S(   Ns0   G++ not available, so we need to skip this test.g       @g      @i	   (   RR   RS   RT   R   R:   RU   R=   R   RY   RQ   R<   RZ   R   (   R   RI   RJ   R@   R[   R\   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   test_clinker_single_nodeé   s    !c          C` s‹   t  j j s t d ƒ ‚ n  t ƒ  \ }  } } t |  |  ƒ } t ƒ  j t |  |  g | g ƒ ƒ } | j	 ƒ  } | d d ƒ d k s‡ t
 ‚ d  S(   Ns0   G++ not available, so we need to skip this test.g       @i   (   RR   RS   RT   R   R:   RU   R   RY   RQ   RZ   R   (   R   RI   RJ   RP   R[   R\   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   test_clinker_dupsó   s    $c          C` s‘   t  j j s t d ƒ ‚ n  t ƒ  \ }  } } t |  | ƒ } t ƒ  j t |  | | g | g ƒ ƒ } | j	 ƒ  } | d d d ƒ d k s t
 ‚ d  S(   Ns0   G++ not available, so we need to skip this test.g       @g      ø?g      ð?g      @(   RR   RS   RT   R   R:   RU   R   RY   RQ   RZ   R   (   R   RI   RJ   RP   R[   R\   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   test_clinker_not_used_inputsÿ   s    'c          C` s£   t  j j s t d ƒ ‚ n  t ƒ  \ }  } } t t | | ƒ t |  | ƒ ƒ } t ƒ  j t	 |  | | g | g ƒ ƒ } | j
 ƒ  } | d d d ƒ d k sŸ t ‚ d  S(   Ns0   G++ not available, so we need to skip this test.g      ð?g       @g      @g       @(   RR   RS   RT   R   R:   RU   RV   R   RY   RQ   RZ   R   (   R   RI   RJ   RP   R[   R\   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   test_clinker_dups_inner
  s    !'c          C` sÐ   t  ƒ  \ }  } } t t t |  | ƒ t |  | ƒ ƒ t t |  | ƒ | ƒ ƒ } t ƒ  j t |  | | g | g ƒ ƒ } | j ƒ  } t	 j
 j r® | d d d ƒ d k sÌ t ‚ n | d d d ƒ d k sÌ t ‚ d  S(   Ng       @iúÿÿÿ(   R:   RU   RV   RW   RX   R   RY   RQ   RZ   RR   RS   RT   R   (   R   RI   RJ   RP   R[   R\   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt"   test_opwiseclinker_straightforward  s    <'!c          C` s   t  ƒ  \ }  } } t t d d d ƒ}  t t |  | ƒ t | | ƒ ƒ } t ƒ  j t | | g | g ƒ ƒ } | j ƒ  } | d d ƒ } | d k s™ t	 ‚ d  S(   NgÍÌÌÌÌÌ@R   R   g      ø?g      @gš™™™™™.@(
   R:   R   R/   RU   RV   R   RY   RQ   RZ   R   (   R   RI   RJ   RP   R[   R\   t   res(    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   test_opwiseclinker_constant&  s    !$t   MyExcc           B` s   e  Z RS(    (   R+   R,   (    (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyR   0  s   c         C` s@   |  d | d k r< t  d i |  d d 6| d d 6ƒ ‚ n  d  S(   Ni    s   Output mismatch.t   performlinkert   clinker(   R   (   R   RI   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   _my_checker4  s    c          C` s”   t  ƒ  \ }  } } t t |  | ƒ t | | ƒ ƒ } t d t ƒ j t |  | | g | g ƒ ƒ } | j ƒ  } | d d d ƒ } | d k s t ‚ d  S(   Nt   checkergÍÌÌÌÌÌ@g      ø?g      @gš™™™™™.@(	   R:   RU   RV   R   R‚   RY   RQ   RZ   R   (   R   RI   RJ   RP   R[   R\   R}   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   test_duallinker_straightforward>  s    !-c          C` sW  t  j j s t d ƒ ‚ n  t ƒ  \ }  } } t t |  | ƒ t | | ƒ ƒ } t |  | | g | g ƒ } t d t	 ƒ j
 | ƒ } | j ƒ  } t ƒ  j
 | ƒ j ƒ  d d d ƒ d k s½ t ‚ t ƒ  j
 | ƒ j ƒ  d d d ƒ d k sí t ‚ t ƒ  j
 | ƒ j ƒ  d d d ƒ d k st ‚ y  | d d d ƒ t d ƒ ‚ Wn t k
 rR} n Xd  S(	   Ns0   G++ not available, so we need to skip this test.Rƒ   g      ð?g       @g      @g      Àg      $Às*   An exception should have been raised here!(   RR   RS   RT   R   R:   RX   RV   RQ   R   R‚   RY   RZ   R   R   R   R   R9   R   (   R   RI   RJ   RP   t   gR[   R\   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   test_duallinker_mismatchG  s    !000t   AddFailc           B` s   e  Z d  „  Z d „  Z RS(   c   
      C` s*   | \ } } | \ } | d }	 d t  ƒ  S(   Nt   failsm   %(z)s = %(x)s + %(y)s;
            PyErr_SetString(PyExc_RuntimeError, "failing here");
            %(fail)s;(   R   (
   R   R@   R   RH   RB   R   R   RI   RJ   Rˆ   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyRK   h  s    	
c         C` s   | | S(   N(    (   R   R   RI   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyR?   p  s    (   R+   R,   RK   R?   (    (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyR‡   g  s   	c          C` sÓ   t  j j s t d ƒ ‚ n  t ƒ  \ }  } } t t d d d ƒ}  t t |  | ƒ t | | ƒ ƒ } t	 ƒ  j
 t | | g | g ƒ ƒ } | j ƒ  } y | d d ƒ Wn t k
 rÂ t d ƒ d  SXd sÏ t ‚ d  S(	   Ns0   G++ not available, so we need to skip this test.gÍÌÌÌÌÌ@R   R   g      ø?g      @s   Yay, TEST PASSEDi    (   RR   RS   RT   R   R:   R   R/   t   add_failRV   R   RY   RQ   RZ   t   RuntimeErrort   printR   (   R   RI   RJ   RP   R[   R\   (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   test_c_fail_erroru  s    !$
c          C` s×  t  j j s t d ƒ ‚ n  t  j j d ƒ }  t  j d ƒ } d | _ t  j j	 ƒ  } t  j
 d | ƒ } t  j |  g | d | | |  f g d | ƒ} t  j |  g | d | | |  f g ƒ} | d ƒ } | d ƒ } | | k oë d k n st | | f ƒ ‚ | d ƒ } | | k s,t | | f ƒ ‚ | d ƒ } | d ƒ } | | k o[d k n srt | | f ƒ ‚ | d	 ƒ }	 |	 | k sœt |	 | f ƒ ‚ | d ƒ } | d ƒ } | | k oËd
 k n sât | | f ƒ ‚ t  j t j d	 d d ƒƒ }
 d |
 _ t  j |  g |
 d |
 |
 |  f g d | ƒ} t  j |  g |
 d |
 |
 |  f g ƒ} | d ƒ } | d ƒ } t j | d k ƒ s˜t | ƒ ‚ t j | d k ƒ s¹t | ƒ ‚ | d ƒ } t j | | k ƒ sìt | | f ƒ ‚ | d ƒ } | d ƒ } t j | d k ƒ s%t | ƒ ‚ t j | d k ƒ sFt | ƒ ‚ | d	 ƒ } t j | | k ƒ syt | | f ƒ ‚ | d ƒ } | d ƒ } t j | d
 k ƒ s²t | ƒ ‚ t j | d
 k ƒ sÓt | ƒ ‚ d  S(   Ns   Need cxx for this testt   inci    t   stateRb   t   updatesRg   i   i   i   Rd   t   int32t   vstate(   RR   RS   RT   R   Ri   t   iscalart   sharedR   t   gofR   Rh   Rp   R   Rl   t   zerost   all(   R   RŽ   Rb   Rg   t   fR…   t   f0t   g0t   f2t   g3R‘   t   fvt   gvt   fv0t   gv0t   fv2t   gv3(    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   test_shared_input_output…  sX    	%	(...	%	(!!'!!'!(;   t
   __future__R    R   R   t   nose.plugins.skipR   t   numpyRl   RR   t   theano.gof.linkR   t   theano.gof.ccR   R   R   t   theano.gof.typeR   t   theano.gof.graphR	   R
   R   t   theano.gof.opR   t
   theano.gofR   R   R   R/   R1   R2   RE   RG   RU   RL   RX   RM   RV   RN   RW   R:   RQ   R]   Ra   Rw   Rx   Ry   Rz   R{   R|   R~   R9   R   R‚   R„   R†   R‡   R‰   RŒ   R¢   (    (    (    s8   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_cc.pyt   <module>   sT   	5		!								
			
					
	
			 		