ó
¡¼™\c           @   s;  d  Z  d d l Z d d l m Z d d l m Z m Z e j d ƒ Z e j	 e j
 ƒ e d ƒ Z e j	 e j ƒ e rd d l Z e j Z e j Z g  d D] Z e j e d ƒ ^ qž \ Z Z Z g  d	 D]$ Z e j d e e f d
 e ƒ^ qÌ \ Z Z Z n e Z d d l Z d d l m  Z  d d l! m" Z" m# Z# m$ Z$ m% Z% d d l& m' Z' m( Z( m) Z) g  d	 D] Z e j* e d d ƒ ^ qi\ Z+ Z, Z- e j. d ƒ e% ƒ Z/ d „  Z0 d „  Z1 d „  Z2 d „  Z3 d „  Z4 d „  Z5 d „  Z6 d „  Z7 e d „  ƒ Z8 d „  Z9 d „  Z: d „  Z; d „  Z< d „  Z= d „  Z> d „  Z? d  „  Z@ d! „  ZA d" „  ZB d# „  ZC d$ „  ZD d% „  ZE d& „  ZF d' „  ZG d( „  ZH d) „  ZI d* „  ZJ d+ „  ZK d, „  ZL d- „  ZM d. „  ZN d/ „  ZO d0 „  ZP d1 „  ZQ e d2 „  ƒ ZR d3 „  ZS d4 „  ZT d5 „  ZU d6 „  ZV d7 „  ZW d8 „  ZX d9 „  ZY d: „  ZZ d S(;   sˆ  
Important note on tests in this module - the Theano printing functions use a
global cache by default, which means that tests using it will modify global
state and thus not be independent from each other. Instead of using the "cache"
keyword argument each time, this module uses the theano_code_ and
theano_function_ functions defined below which default to using a new, empty
cache instead.
iÿÿÿÿN(   t   import_module(   t   raisest   SKIPs   theano.configdefaultst   theanot   xyzt   floatXt   XYZt   name(   t   S(   t   xt   yt   zt   t(   t   theano_codet   dim_handlingt   theano_functioni   t   fc         K   s   | j  d i  ƒ t |  |  S(   sB    Wrapper for theano_code that uses a new, empty cache by default. t   cache(   t
   setdefaultR   (   t   exprt   kwargs(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   theano_code_.   s    c         K   s    | j  d i  ƒ t |  | |  S(   sF    Wrapper for theano_function that uses a new, empty cache by default. R   (   R   R   (   t   inputst   outputsR   (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   theano_function_3   s    c          G   s[   t  t t |  ƒ ƒ } t j j j | ƒ } t j j j | | ƒ \ } } t j j | | ƒ S(   s³    Transform SymPy expressions into Theano Computation.

    Parameters
    ==========
    exprs
        Sympy expressions

    Returns
    =======
    theano.gof.FunctionGraph
    (	   t   listt   mapR   R   t   goft   graphR   t   clonet   FunctionGraph(   t   exprst   outst   ins(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt	   fgraph_of9   s    c         C   s8   t  j j ƒ  j d ƒ } |  j ƒ  }  | j j |  ƒ |  S(   sŸ    Simplify a Theano Computation.

    Parameters
    ==========
    fgraph : theano.gof.FunctionGraph

    Returns
    =======
    theano.gof.FunctionGraph
    t   fusion(   R   t   compilet   get_default_modet	   excludingR   t	   optimizert   optimize(   t   fgrapht   mode(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   theano_simplifyK   s    c         C   sw  t  t t j f } t |  | ƒ } t | | ƒ } | s< | rV | oE | sL t S|  | k St |  t t f ƒ } t | t t f ƒ } | sŒ | rÝ | o• | s± t |  ƒ t | ƒ k rµ t St t	 t
 |  ƒ ƒ t t	 t
 | ƒ ƒ k St j j |  d d ƒ} t j j | d d ƒ} x] d |  | f d | | f g D]= \ }	 }
 } | d k r,t d |	 |	 t |
 ƒ f ƒ ‚ q,q,W| | k S(   sæ   Test two Theano objects for equality.

    Also accepts numeric types and lists/tuples of supported types.

    Note - debugprint() has a bug where it will accept numeric types but does
    not respect the "file" argument and in this case and instead prints the number
    to stdout and returns an empty string. This can lead to tests passing where
    they should fail because any two numbers will always compare as equal. To
    prevent this we treat numbers as a separate case.
    t   filet   strt   at   bt    sK   theano.printing.debugprint(%s) returned empty string (%s is instance of %r)(   t   intt   floatt   npt   numbert
   isinstancet   Falset   tupleR   t   typeR   t   theqR   t   printingt
   debugprintt	   TypeError(   R.   R/   t   numeric_typest   a_is_numt   b_is_numt   a_is_seqt   b_is_seqt   astrt   bstrt   argnamet   argvalt   argstr(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyR9   \   s*    
%(. c           C   s¦   t  t t t ƒ ƒ s t ‚ t  t t t ƒ ƒ s6 t ‚ t  t t t ƒ ƒ sQ t ‚ t  t	 t t
 ƒ ƒ sl t ‚ t  t t t ƒ ƒ s‡ t ‚ t  t t t ƒ ƒ s¢ t ‚ d S(   s‰   
    Check that the example symbols in this module print to their Theano
    equivalents, as many of the other tests depend on this.
    N(   R9   t   xtR   R	   t   AssertionErrort   ytR
   t   ztR   t   Xtt   Xt   Ytt   Yt   Ztt   Z(    (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_example_symbolsŒ   s    c          C   sª   t  t ƒ }  t |  t j t j f ƒ s- t ‚ |  j d k sB t ‚ |  j	 t j	 k sZ t ‚ t  t d i t
 f t 6ƒ} | j t
 f k sŽ t ‚ | j	 t j	 k s¦ t ‚ d S(   s.    Test printing a Symbol to a theano variable. t   broadcastablesN(    (   R   R	   R5   t   ttt   TensorVariablet   tst   ScalarVariableRH   t   broadcastableR   R6   (   t   xxt   xx2(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_Symbol™   s    !c          C   sC   t  t ƒ }  t |  t j ƒ s$ t ‚ |  j t t f k s? t ‚ d S(   s4    Test printing a MatrixSymbol to a theano variable. N(   R   RL   R5   RS   RT   RH   RW   R6   (   t   XX(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_MatrixSymbol¤   s    c          C   so   d t  f t f t t  f t  t f t t f g }  x8 |  D]0 } t t ƒ  t t d i | t 6ƒWd QXq7 Wd S(   s/    Test MatrixSymbol with invalid broadcastable. RR   N(    (   R6   t   TrueR   t
   ValueErrorR   RL   (   t   bcst   bc(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_MatrixSymbol_wrong_dimsª   s    0c          C   sR   t  t ƒ }  t |  t j ƒ s$ t ‚ |  j d k s9 t ‚ |  j d k sN t ‚ d S(   sG    Test printing AppliedUndef instance, which works similarly to Symbol. t   f_tN(    (   R   Rb   R5   RS   RT   RH   RW   R   (   t   ftt(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_AppliedUndef²   s    c          C   s8   t  t }  t |  ƒ } | j j t j j k s4 t ‚ d  S(   N(	   R	   R
   R   t   ownert   opR   t   tensort   addRH   (   R   t   comp(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_addº   s    
c           C   s^   t  t t j t ƒ ƒ t j t ƒ ƒ s- t ‚ t  t t j t ƒ ƒ t j t ƒ ƒ sZ t ‚ d  S(   N(	   R9   R   t   syt   sinR	   RS   RG   RH   t   tan(    (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt	   test_trig¿   s    -c          C   s‡   t  j t d t  j t ƒ ƒ t  j d t ƒ }  t |  ƒ } t j t	 d t j t
 ƒ ƒ t j d t ƒ } t | | ƒ sƒ t ‚ d S(   s;    Test printing a complex expression with multiple symbols. i   N(   Rk   t   expR	   t   cosR
   t   logR   R   RS   RG   RI   RJ   R9   RH   (   R   Ri   t   expected(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt	   test_manyÃ   s    11c          C   sâ   xK d d d d d d g D]1 }  t  t d i |  t 6ƒj j |  k s t ‚ q Wt  t d i d t 6ƒj j d k sy t ‚ t  t d	 d i d t 6ƒj j d k s¨ t ‚ t  t t d i d t 6d t 6ƒj j d k sÞ t ‚ d
 S(   sA    Test specifying specific data types through the dtype argument. t   float32t   float64t   int8t   int16t   int32t   int64t   dtypesR   i   N(   Rt   Ru   (   R   R	   R8   t   dtypeRH   R
   (   R{   (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt
   test_dtypeË   s
    /+/c          C   su   xn t  t g D]` }  xW d t f t f t t f t t f g D]. } t |  d i | |  6ƒj | k s; t ‚ q; Wq Wd S(   sG    Test the "broadcastables" argument when printing symbol-like objects. RR   N(    (   R	   Rb   R6   R]   R   RW   RH   (   t   sR`   (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_broadcastablesØ   s    .c          C   sÕ   t  t }  d d d g t f t f t f g t f t f t f g t t f t t f t t f g t t f t t f t t f g g } xL | D]D \ } } } t |  d i | t  6| t 6ƒ} | j | k s‰ t ‚ q‰ Wd S(   sG    Test "broadcastable" attribute after applying element-wise binary op. RR   N(    (    (    (   R	   R
   R6   R]   R   RW   RH   (   R   t   casest   bc1t   bc2t   bc3Ri   (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_broadcastingâ   s    
$ c          C   sc   t  t t }  t |  ƒ } t | j j t j ƒ s8 t	 ‚ t
 | t j t ƒ j t ƒ ƒ s_ t	 ‚ d  S(   N(   RL   RN   RP   R   R5   Re   Rf   RS   t   DotRH   R9   RK   t   dotRM   RO   (   R   t   expr_t(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_MatMulô   s    c           C   s+   t  t t j ƒ j j t j ƒ s' t ‚ d  S(   N(	   R5   R   RL   t   TRe   Rf   RS   t
   DimShuffleRH   (    (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_Transposeú   s    c          C   s6   t  t t }  t t |  ƒ j j t j ƒ s2 t	 ‚ d  S(   N(
   RL   RN   RP   R5   R   Re   Rf   RS   t   ElemwiseRH   (   R   (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_MatAddý   s    c           C   sb   t  t t j d ƒ d ƒ t j d d ƒ ƒ s4 t ‚ t  t t j ƒ t j d d ƒ ƒ s^ t ‚ d  S(   Ni   i   i   (	   R9   R   Rk   t   IntegerRS   t   true_divRH   R   t   Half(    (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_Rationals  s    4c           C   s%   t  t j d ƒ ƒ d k s! t ‚ d  S(   Ni   (   R   Rk   R   RH   (    (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_Integers  s    c          C   s.   t  j d ƒ }  t t  j |  ƒ ƒ s* t ‚ d  S(   Nt   n(   Rk   t   SymbolR   t	   factorialRH   (   R’   (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_factorial	  s    c          C   sd   d „  }  t  |  t t j t j t ƒ t d t ƒƒ ƒ |  t j t	 j t
 ƒ t
 ƒ ƒ ƒ s` t ‚ d  S(   Nc         S   s   t  t |  ƒ ƒ S(   N(   R+   R"   (   R   (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   <lambda>  R0   t   evaluate(   R9   R   Rk   t
   DerivativeRl   R	   R6   R   t   gradRS   RG   RH   (   t   simp(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_Derivative  s    	-c          C   s;   t  t t g t t g ƒ }  |  d d ƒ d k s7 t ‚ d S(   s,    Test theano_function() with single output. i   i   i   N(   R   R	   R
   RH   (   R   (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_theano_function_simple  s    c          C   s`   t  t t g t t t t g ƒ }  |  d d ƒ \ } } | d k sJ t ‚ | d k s\ t ‚ d S(   s/    Test theano_function() with multiple outputs. i   i   i   iÿÿÿÿN(   R   R	   R
   RH   (   R   t   o1t   o2(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_theano_function_multi  s    #c       	   C   s"  t  t t g t t g d d d i d t 6d t 6ƒ}  t j j |  d d g d d g ƒ t j d d g ƒ ƒ d	 k  s| t ‚ t  t t g t t g d i d t 6d t 6d d ƒ}  t j d ƒ j	 d ƒ } d t j d ƒ j	 d ƒ } t j j |  | | ƒ d t j d ƒ ƒ d	 k  st ‚ d
 S(   s1    Test theano_function() vs Numpy implementation. t   dimi   Rz   Ru   i   i   i   i   g•Ö&è.>N(
   R   R	   R
   R3   t   linalgt   normt   asarrayRH   t   aranget   astype(   R   RX   t   yy(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_theano_function_numpy  s    F-	c          C   sS  t  j t t g t t t t g g ƒ }  t j d d g d d g g ƒ } t t t t g |  g ƒ } t j j	 | d d d ƒ | ƒ t t t t g |  g d t
 ƒ} t j j	 | d d d ƒ | ƒ t t t t g |  |  g ƒ } t | d d d ƒ t g  ƒ ƒ s	t ‚ t j j	 | d d d ƒ d | ƒ t j j	 | d d d ƒ d | ƒ d  S(	   Ng      ð?g       @g      @t   scalari    i   g      @g      @(   Rk   t   MatrixR	   R
   R   R3   t   arrayR   t   testingt   assert_allcloseR]   R5   R8   RH   (   t   mRr   R   (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_theano_function_matrix,  s    )!!'#c           C   s³   t  t g d d ƒi t t f t 6k s. t ‚ t  t t g d i d t 6d t 6ƒi t t f t 6t t f t 6k sz t ‚ t  t g d i t f t 6ƒi t f t 6k s¯ t ‚ d  S(   NR    i   t   dimsi   RR   (   R   R	   R6   RH   R
   R]   (    (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_dim_handling8  s    .3c          C   sv  d d l  }  t t t t g t t g d d d d d i d t 6d t 6d t 6ƒ} |  j j | d d	 g d
 d g d d g ƒ |  j d d g ƒ ƒ d k  s¡ t ‚ t t t t g t t g d i d t 6d t 6d t 6d d d d ƒ} |  j	 d
 ƒ j
 d ƒ } d	 |  j	 d
 ƒ j
 d ƒ } d	 |  j	 d
 ƒ j
 d ƒ } |  j j | | | | ƒ d
 |  j	 d
 ƒ ƒ d k  srt ‚ d S(   sU   
    Test passing additional kwargs from theano_function() to theano.function().
    iÿÿÿÿNR    i   t   on_unused_inputt   ignoreRz   Ru   i   i   i   i    i   g•Ö&è.>(   t   numpyR   R	   R
   R   R¡   R¢   R£   RH   R¤   R¥   (   R3   R   RX   R¦   t   zz(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_theano_function_kwargs>  s    (Oc       	   C   sI  t  t g t  t g d d g f t t g t t g d d g f t  t g t  t g i d t  6d t 6d g f t  t g t  t t  t g d d d g f t  t t t g t  t t t g d d d g f g }  xy|  D]q\ } } } } x\t t g D]N} t | | d | d | ƒ} t | j	 t
 j j j ƒ s1t ‚ g  | j	 j D]: } t j g  | j j D] } | rid n d ^ qWƒ ^ q>}	 | |	 Œ  }
 t |
 t ƒ s¥|
 g }
 n  t | ƒ t |
 ƒ k sÃt ‚ xw t | |
 ƒ D]f \ } } | r| d k rt | t j ƒ s9t ‚ qÓt | t j ƒ s$t ‚ | j | k sÓt ‚ qÓWqï WqÐ Wd S(   s2    Test the "scalar" argument to theano_function(). i    i   i   R¯   R¨   i   N(   R	   R
   t   NoneRL   RN   R6   R]   R   R5   R   R   R$   t   function_modulet   FunctionRH   t   input_storageR3   t   onesR8   RW   R   t   lent   zipR4   t   ndarrayt   ndim(   t   argsR   R   t   in_dimst   out_dimsR¨   R   t   iR`   t	   in_valuest
   out_valuest   dt   value(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_theano_function_scalarO  s(    -)5!Jc           C   s   t  t d „  ƒ d S(   sa   
    Passing an unknown keyword argument to theano_function() should raise an
    exception.
    c           S   s   t  t g t d g d d ƒS(   Ni   t   foobari   (   R   R	   (    (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyR–   ~  R0   N(   R   t	   Exception(    (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_theano_function_bad_kwargy  s    c          C   s½   t  t d d d ƒ ƒ t d d d ƒ k s0 t ‚ d „  }  i d t 6d t 6} |  t  t t t ƒ d | ƒt t t ƒ ƒ s€ t ‚ |  t  t d t d ƒ d | ƒt d t d ƒ ƒ s¹ t ‚ d  S(   Ni   i   i   c         S   s†   x d d d g D]n } t  |  | ƒ } t  | | ƒ } | d  k sL | d  k rk | d  k pa | d  k s~ t Sq t | | ƒ s t Sq Wt S(   Nt   startt   stopt   step(   t   getattrR¶   R6   R9   R]   (   t   s1t   s2t   attrt   a1t   a2(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt
   theq_slice„  s    Rx   Rz   (   R   t   sliceRH   R	   R
   RG   RI   (   RÔ   Rz   (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt
   test_slice  s
    0	3c    	         sŽ  d d l  m ‰  i  }  t j d d t ƒ} t j d | | ƒ } | d d d … d	 d
 d … f } t | d |  ƒ‰ t j d ƒ ‰ t	 ˆ j
 j j ƒ t ˆ ˆ ˆ ƒ t ˆ ˆ ˆ ƒ f k sÂ t ‚ ˆ j
 j d t | d |  ƒk sê t ‚ t ‡  ‡ ‡ f d †  t d d ƒ Dƒ ƒ st ‚ t j d ƒ } t | d i d | 6ƒ} d	 | d } } } | | | | … } t | d i d | 6d | 6ƒ‰ d  S(   Niÿÿÿÿ(   t   ConstantR’   t   integerRL   i   i   i   i   i   i   R   Ry   i    c         3   s1   |  ]' } ˆ j  j | j ˆ  ˆ | ƒ ƒ Vq d  S(   N(   Re   R   t   equals(   t   .0RÂ   (   R×   RM   R}   (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pys	   <genexpr>£  s    i   t   kRz   Rx   (   R   R×   Rk   R“   R]   t   MatrixSymbolR   RU   t   ScalarR7   Re   Rf   t   idx_listRÕ   RH   R   t   allt   range(	   R   R’   RL   RN   RÛ   t   ktRË   RÌ   RÍ   (    (   R×   RM   R}   sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_MatrixSlice“  s    "?(1c             s)  t  j d d t ƒ}  g  d D] } t  j | |  |  ƒ ^ q \ } } } } t t | | | | f ƒ \ } } } }	 t  j | | g | | g g ƒ }
 t |
 ƒ ‰  t j d t j d | | ƒ t j d | |	 ƒ ƒ t j d t j d | | ƒ t j d | |	 ƒ ƒ g } t	 ‡  f d †  | Dƒ ƒ s%t
 ‚ d  S(   NR’   RØ   t   ABCDi    i   c         3   s   |  ] } t  ˆ  | ƒ Vq d  S(   N(   R9   (   RÚ   t   solution(   t   Blockt(    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pys	   <genexpr>´  s    (   Rk   R“   R]   RÜ   R   R   t   BlockMatrixRS   t   joint   anyRH   (   R’   R   t   At   Bt   Ct   Dt   Att   Btt   Ctt   Dtt   Blockt	   solutions(    (   Rå   sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_BlockMatrix¬  s    4'!06c          C   s  d \ }  } d } t  j d | |  ƒ } t  j d | | ƒ } | | f } | j | } i | d | d f |  d |  d f g | 6| d | d f | d | d f g | 6} g  | D] } t  j | | | Œ ^ q´ }	 | j t t | |	 ƒ ƒ ƒ }
 t t | | g t | ƒ ƒ ƒ } t | | g d | d i  ƒ} t | t  j	 |
 ƒ g d | d i  ƒ} g  | D]$ } t
 j j | j Œ  j | ƒ ^ qb} t
 j | |  ƒ j | j ƒ j | ƒ t
 j | ƒ j | ƒ g } | d c t
 j | j ƒ d	 7<t
 j | | Œ  | | Œ  d
 d	 ƒst ‚ d  S(   Ni   i   Rt   Ré   Rê   Rz   R   i   gñhãˆµøä>t   rtol(   i   i   (   Rk   RÜ   t   It   blockcutt   subst   dictR¼   R»   R   t   block_collapseR3   t   randomt   randt   shapeR¥   R¤   t   reshapet   eyeRº   t   allcloseRH   (   RÛ   R’   R{   Ré   Rê   R   t   outputt   cutsizesRÂ   t	   cutinputst	   cutoutputRz   R   t   fblockedR	   t   ninputs(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt"   test_BlockMatrix_Inverse_execution¶  s&    ,,)"1% c          C   s²   t  j d ƒ }  xœ t  j t  j g D]ˆ } | t  j |  ƒ t  j |  ƒ g t  j |  ƒ t  j |  ƒ g g ƒ } t | ƒ } t | t j	 ƒ s t
 ‚ | j j t j k s" t
 ‚ q" Wd  S(   Nt   theta(   Rk   R“   R©   t   ImmutableMatrixRp   Rl   R   R5   RS   RT   RH   Re   Rf   t   join_(   R   t
   MatrixTypeRL   t   tX(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_DenseMatrixÐ  s    Cc          C   sÞ   t  t j d ƒ f t t j d t j Œ f t t j d ƒ t j d ƒ ƒ f g }  x† |  D]~ \ } } i  } t | d | ƒ} t | d | ƒ| k sš t	 ‚ t | d i  ƒ| k	 s¸ t	 ‚ t | d | ƒ| k sX t	 ‚ qX Wd S(   sH    Test single symbol-like objects are cached when printed by themselves. R	   RL   R   R   R   N(
   R	   Rk   R“   RL   RÜ   Rü   Rb   R¸   R   RH   (   t   pairsRÏ   RÐ   R   t   st(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_cache_basicÙ  s    'c          C   s}   d d l  m }  t |  ƒ } zL |  j ƒ  x; t t t g D]* } t | ƒ } t | ƒ | k s9 t ‚ q9 WWd |  j	 | ƒ Xd S(   s    Test use of the global cache. iÿÿÿÿ(   t   global_cacheN(
   t   sympy.printing.theanocodeR  Rø   t   clearR	   RL   Rb   R   RH   t   update(   R  t   backupR}   R  (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_global_cacheð  s    
 c          C   sê   t  j d ƒ t  j d d d ƒ t g }  i  } i  } xB |  D]: } t | d | ƒ} | | j ƒ  k sj t ‚ | | | <q: Wt t t	 t
 | j ƒ  ƒ ƒ ƒ t |  ƒ k s« t ‚ x8 | j ƒ  D]* \ } } t | d | ƒ| k s¸ t ‚ q¸ Wd S(   s§   
    Test that symbol-like objects of different types (Symbol, MatrixSymbol,
    AppliedUndef) are distinguished by the cache even if they have the same
    name.
    Rb   i   R   N(   Rk   R“   RÜ   Rb   R   t   valuesRH   R»   t   setR   t   idt   itemsR   (   t   symbolsR   t   printedR}   R  (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_cache_types_distinct  s    '3c          C   sa   t  j t t d t ƒ}  t |  ƒ } t | t t ƒ s= t ‚ t | t t t ƒ ƒ s] t ‚ d S(   sf   
    Test that a symbol is cached and reused when it appears in an expression
    more than once.
    R—   N(   Rk   t   AddR	   R6   R   R9   RG   RH   (   R   Ri   (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_symbols_are_created_once  s    c          C   sö   t  d t t j t  ƒ t j t t  t ƒ }  d „  |  j Dƒ } t |  ƒ } t ƒ  } x… t	 j
 j j | g ƒ D]k } | j d k rq t | t	 j
 j j ƒ rq | j | k s´ t ‚ | j | k sÉ t ‚ | j | j ƒ qq qq W| | k sò t ‚ d S(   sf   
    Test caching on a complicated expression with multiple symbols appearing
    multiple times.
    i   c         S   s   h  |  ] } | j  ’ q S(    (   R   (   RÚ   R}   (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pys	   <setcomp>)  s   	 N(   R	   R
   Rk   Ro   Rl   R   t   free_symbolsR   R  R   R   R   t	   ancestorsRe   R¶   R5   R×   R   RH   Rh   (   R   t   symbol_namesR†   t   seent   v(    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_cache_complex#  s    0	(c          C   sÃ  t  j d t d k  f t t d k  f d t f ƒ }  t |  ƒ } | j j t j k sZ t	 ‚ t j t
 d k  d t j t
 d k  t
 d ƒ ƒ } t | | ƒ sŸ t	 ‚ t  j t t d k  f ƒ }  t |  ƒ } t j t
 d k  t
 t j ƒ } t | | ƒ sù t	 ‚ t  j d t  j t d k t d k  ƒ f t t  j t d k t d k  ƒ f ƒ }  t |  ƒ } t j t j t
 d k t
 d k  ƒ d t j t j t
 d k t
 d k  ƒ t
 t j ƒ ƒ } t | | ƒ s¿t	 ‚ d  S(   Ni    i   i   (   Rk   t	   PiecewiseR	   R]   R   Re   Rf   RS   t   switchRH   RG   R9   R3   t   nant   Andt   Ort   and_t   or_(   R   t   resultRr   (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_Piecewise;  s    30''$3c           C   sÓ   t  t t j t t ƒ ƒ t j t t	 ƒ ƒ s3 t
 ‚ t  t t t k ƒ t t	 k ƒ sZ t
 ‚ t  t t t k  ƒ t t	 k  ƒ s t
 ‚ t  t t t k ƒ t t	 k ƒ s¨ t
 ‚ t  t t t k ƒ t t	 k ƒ sÏ t
 ‚ d  S(   N(   R9   R   Rk   t   EqR	   R
   RS   t   eqRG   RI   RH   (    (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   test_RelationalsQ  s
    3'''([   t   __doc__t   loggingt   sympy.externalR    t   sympy.utilities.pytestR   R   t	   getLoggert   theanologgert   setLevelt   CRITICALR   t   WARNINGR³   R3   R¨   RU   Rg   RS   R   RG   RI   RJ   R’   R6   RK   RM   RO   R]   t   disabledt   sympyRk   R   t	   sympy.abcR	   R
   R   R   R  R   R   R   RÜ   RL   RN   RP   R¸   Rb   R   R   R"   R+   R9   RQ   RZ   R\   Ra   Rd   Rj   Rn   Rs   R|   R~   Rƒ   R‡   RŠ   RŒ   R   R‘   R•   R›   Rœ   RŸ   R§   R®   R°   Rµ   RÇ   RÊ   RÖ   Râ   Ró   R  R  R  R  R  R  R$  R-  R0  (    (    (    sC   lib/python2.7/site-packages/sympy/printing/tests/test_theanocode.pyt   <module>   s~   		.="1					0									
															*				
								