
    gS                        d Z ddlZddlmZ ddlmZmZmZ  ej        d          Z	e	
                    ej                    ed          Ze	
                    ej                   er3ddlZej        Zej        Zd dD             \  ZZZd	 d
D             \  ZZZnd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' d d
D             \  Z(Z)Z*  ej+        d          e#          Z,d Z-d Z.d Z/d Z0d Z1d Z2d Z3d Z4ed             Z5d Z6d Z7d Z8d Z9d Z:d Z;d  Z<d! Z=d" Z>d# Z?d$ Z@d% ZAd& ZBd' ZCd( ZDd) ZEd* ZFd+ ZGd, ZHd- ZId. ZJd/ ZKd0 ZLd1 ZMd2 ZNed3             ZOd4 ZPd5 ZQd6 ZRd7 ZSd8 ZTd9 ZUd: ZVd; ZWd< ZXd= ZYd> ZZdS )?a  
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.
    N)import_module)raisesSKIPwarns_deprecated_sympyztheano.configdefaultstheanoc                 D    g | ]}t                               |d           S )floatX)ttscalar).0names     `/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/printing/tests/test_theanocode.py
<listcomp>r      s&    >>>"))D(++>>>    xyzc                 H    g | ]}t                               d d|           S )r	   FFr   )r
   tensorr   ns     r   r   r      s*    MMM!"))Hn1)==MMMr   XYZT)S)xyzt)theano_codedim_handlingtheano_functionc                 :    g | ]}t          j        |d d           S )   syMatrixSymbolr   s     r   r   r   (   s&    
3
3
32?1a##
3
3
3r   fc                     |                     di            t                      5  t          | fi |cddd           S # 1 swxY w Y   dS )zB Wrapper for theano_code that uses a new, empty cache by default. cacheN)
setdefaultr   r   )exprkwargss     r   theano_code_r,   .   s    
gr"""		!	! + +4**6**+ + + + + + + + + + + + + + + + + +s   ?AAc                     |                     di            t                      5  t          | |fi |cddd           S # 1 swxY w Y   dS )zF Wrapper for theano_function that uses a new, empty cache by default. r(   N)r)   r   r    )inputsoutputsr+   s      r   theano_function_r0   4   s    
gr"""		!	! : :vw99&99: : : : : : : : : : : : : : : : : :s   A  AAc                     t          t          t          |                     }t          j        j                            |          }t          j        j                            ||          \  }}t          j                            ||          S )z Transform SymPy expressions into Theano Computation.

    Parameters
    ==========
    exprs
        SymPy expressions

    Returns
    =======
    theano.gof.FunctionGraph
    )	listmapr,   r   gofgraphr.   cloneFunctionGraph)exprsoutsinss      r   	fgraph_ofr;   ;   si     L%(())D
*

!
!$
'
'C
 &&sD11IC:##C...r   c                     t           j                                                            d          }|                                 } |j                            |            | S )z Simplify a Theano Computation.

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

    Returns
    =======
    theano.gof.FunctionGraph
    fusion)r   compileget_default_mode	excludingr6   	optimizeroptimize)fgraphmodes     r   theano_simplifyrE   M   sM     >**,,66x@@D\\^^FNF###Mr   c                    t           t          t          j        f}t	          | |          }t	          ||          }|s|r|r|sdS | |k    S t	          | t
          t          f          }t	          |t
          t          f          }|s|rl|r"|r t          |           t          |          k    rdS t          t          t          |                     t          t          t          |                    k    S t          j                            | d          }t          j                            |d          }d| |fd||ffD ]2\  }	}
}|dk    r&t          d|	d|	d	t          |
          d
          3||k    S )a   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.
    Fstr)fileab ztheano.printing.debugprint(z) returned empty string (z is instance of ))intfloatnpnumber
isinstancetupler2   typer3   theqr   printing
debugprint	TypeError)rI   rJ   numeric_typesa_is_numb_is_numa_is_seqb_is_seqastrbstrargnameargvalargstrs               r   rT   rT   ^   s    %+M!]++H!]++H  8  	X 	5Av !eT]++H!eT]++H 88 8 	X 	$q''T!WW*<*<5CaLL!!T#dA,,%7%777 ?%%ae%44D?%%ae%44D &)!TNS!TN#C  R<<) 77GGGT&\\\\3    4<r   c                     t          t          t          t                              sJ t          t          t          t
                              sJ t          t          t          t                              sJ t          t          t          t                              sJ t          t          t          t                              sJ t          t          t          t                              sJ dS )z
    Check that the example symbols in this module print to their Theano
    equivalents, as many of the other tests depend on this.
    N)rT   xtr,   r   ytr   ztr   XtXYtYZtZ r   r   test_example_symbolsrm      s    
 LOO$$$$$LOO$$$$$LOO$$$$$LOO$$$$$LOO$$$$$LOO$$$$$$$r   c                  H   t          t                    } t          | t          j        t
          j        f          sJ | j        dk    sJ | j        t          j        k    sJ t          t          t          di          }|j        dk    sJ |j        t          j        k    sJ dS )z. Test printing a Symbol to a theano variable. rl   FbroadcastablesN)	r,   r   rQ   r
   TensorVariabletsScalarVariablebroadcastabler   )xxxx2s     r   test_Symbolrx      s    	aBb2,b.?@AAAAAr!!!!7af
q!X
7
7
7C((((8qvr   c                      t          t                    } t          | t          j                  sJ | j        dk    sJ dS )z4 Test printing a MatrixSymbol to a theano variable. r   N)r,   rg   rQ   r
   rr   ru   )XXs    r   test_MatrixSymbolr{      s@    	aBb"+,,,,,~------r   c                      g d} | D ]K}t          t                    5  t          t          t          |i           ddd           n# 1 swxY w Y   LdS )z/ Test MatrixSymbol with invalid broadcastable. )rl   ro   TTFFT)TTrp   N)r   
ValueErrorr,   rg   )bcsbcs     r   test_MatrixSymbol_wrong_dimsr      s     O
N
NC 4 4J 	4 	4Ar73333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	44 4s   AA	A	c                      t          t                    } t          | t          j                  sJ | j        dk    sJ | j        dk    sJ dS )zG Test printing AppliedUndef instance, which works similarly to Symbol. rl   f_tN)r,   r   rQ   r
   rr   ru   r   )ftts    r   test_AppliedUndefr      sU    
s

Cc2,-----""""8ur   c                      t           t          z   } t          |           }|j        j        t
          j        j        k    sJ d S N)r   r   r,   owneropr   r   addr*   comps     r   test_addr      s8    q5DD:=FM-------r   c                  R   t          t          t          j        t                              t
                              t                              sJ t          t          t          j        t                              t
                              t                              sJ d S r   )rT   r,   r$   sinr   r
   rc   tanrl   r   r   	test_trigr      sh    RVAYY''44444RVAYY''4444444r   c                     t          j        t          dz  t          j        t                    z             t          j        dt          z            z  } t          |           }t                              t          dz  t                              t                    z             t                              dt          z            z  }t          ||          sJ dS )z; Test printing a complex expression with multiple symbols.    N)r$   expr   cosr   logr   r,   r
   rc   rd   re   rT   )r*   r   expecteds      r   	test_manyr      s    6!Q$"##bfQqSkk1DDvvb!ebffRjj())BFF1R4LL8Hhr   c                     dD ]/} t          t          t          | i          j        j        | k    sJ 0t          t          t          di          j        j        dv sJ t          t          dz   t          di          j        j        dk    sJ t          t          t          z   t          dt          di          j        j        dk    sJ dS )	zA Test specifying specific data types through the dtype argument. )float32float64int8int16int32int64dtypesr	   )r   r      r   r   N)r,   r   rS   dtyper   )r   s    r   
test_dtyper      s    J F FAq%j1116<EEEEE 1h-0005;?UUUUU Aq)n555:@IMMMMAq)Q	&BCCCHNR[[[[[[[r   c                  n    t           t          fD ]%} dD ] }t          | | |i          j        |k    sJ !&dS )zG Test the "broadcastables" argument when printing symbol-like objects. )rl   ro   r}   r   r~   rp   N)r   r   r,   ru   )sr   s     r   test_broadcastablesr      sd     X O OH 	O 	OB1b':::HBNNNNN	OO Or   c                      t           t          z   } g dg dg dg dg dg}|D ]2\  }}}t          | t           |t          |i          }|j        |k    sJ 3dS )zG Test "broadcastable" attribute after applying element-wise binary op. )rl   rl   rl   )ro   ro   ro   )r}   ro   ro   )r   r   r   )r~   r   r   rp   N)r   r   r,   ru   )r*   casesbc1bc2bc3r   s         r   test_broadcastingr      s     q5D 	&&&%%%777777E  ) )S#D!S!S1ABBB!S((((() )r   c                  ,   t           t          z  t          z  } t          |           }t	          |j        j        t          j                  sJ t          |t                              t                                        t                              sJ d S r   )rg   ri   rk   r,   rQ   r   r   r
   DotrT   rf   dotrh   rj   )r*   expr_ts     r   test_MatMulr      sj    Q3q5D$Fflorv.....r

r**+++++++r   c                      t          t          t          j                  j        j        t          j                  sJ d S r   )rQ   r,   rg   Tr   r   r
   
DimShufflerl   r   r   test_Transposer      s0    l13''-0"-@@@@@@@r   c                      t           t          z   t          z   } t          t	          |           j        j        t          j                  sJ d S r   )	rg   ri   rk   rQ   r,   r   r   r
   Elemwiser*   s    r   test_MatAddr      s;    Q3q5Dl4((.12;???????r   c                  $   t          t          t          j        d          dz            t                              dd                    sJ t          t          t          j                  t                              dd                    sJ d S )Nr      r   )rT   r,   r$   Integerr
   true_divr   Halfrl   r   r   test_Rationalsr     so    RZ]]Q.//Q1B1BCCCCCQV$$bkk!Q&7&78888888r   c                  T    t          t          j        d                    dk    sJ d S )Nr   )r,   r$   r   rl   r   r   test_Integersr     s)    
1&&!++++++r   c                  t    t          j        d          } t          t          j        |                     sJ d S )Nr   )r$   Symbolr,   	factorial)r   s    r   test_factorialr     s1    
	#AQ(((((((r   c                  F   d } t           | t          t          j        t          j        t
                    t
          d                               | t                              t                              t                    t                                        sJ d S )Nc                 :    t          t          |                     S r   )rE   r;   r   s    r   <lambda>z!test_Derivative.<locals>.<lambda>  s    	$88 r   Fevaluate)
rT   r,   r$   
Derivativer   r   r   gradr
   rc   )simps    r   test_Derivativer     s    88D\"-q		1u"M"M"MNNOOV[[R00113 3 3 3 3 3 3r   c                  ~    t          t          t          gt          t          z   g          }  | dd          dk    sJ dS )z, Test theano_function() with single output. r   r      Nr0   r   r   )r&   s    r   test_theano_function_simpler     s6    !Q!A#''A1Q77a<<<<<<r   c                      t          t          t          gt          t          z   t          t          z
  g          }  | dd          \  }}|dk    sJ |dk    sJ dS )z/ Test theano_function() with multiple outputs. r   r   r   Nr   )r&   o1o2s      r   test_theano_function_multir     sR    !Q!A#qs,,AQq!WWFB7777888888r   c            	         t          t          t          gt          t          z   gdt          dt          di          } t          j                             | ddgddg          t          j        ddg          z
            dk     sJ t          t          t          gt          t          z   gt          dt          did	          } t          j        d                              d          }dt          j        d                              d          z  }t          j                             | ||          dt          j        d          z  z
            dk     sJ d
S )z1 Test theano_function() vs Numpy implementation. r   r   )dimr   r   r   r"      &.>)r   r   N)	r0   r   r   rO   linalgnormasarrayarangeastype)r&   rv   yys      r   test_theano_function_numpyr   !  s#   !Q!A#A!"Iq) <	> 	> 	>A9>>!!QFQF++bj!Q.@.@@AADHHHH!Q!A#9a/K	  	  	 A	1		Y	'	'B	
29Q<<y))	)B9>>!!B))a	!n455<<<<<<r   c                  R   t          j        t          t          gt          t          t          z   t          z   gg          } t          j        ddgddgg          }t          t          t          t          g| g          }t
          j        	                     |ddd          |           t          t          t          t          g| gd          }t
          j        	                     |ddd          |           t          t          t          t          g| | g          }t           |ddd          t          g                     sJ t
          j        	                     |ddd          d         |           t
          j        	                     |ddd          d         |           d S )	N      ?       @g      @g      @T)r   r   r   )r$   Matrixr   r   r   rO   arrayr0   testingassert_allcloserQ   rS   )mr   r&   s      r   test_theano_function_matrixr   .  sa   
	Aq6Aq1uqy>*++Ax#sc?%;<==H!QQC((AJqqc3//:::!QQC555AJqqc3//:::!QQF++AaaS#&&R11111Jqqc3//2H===Jqqc3//2H=====r   c                  "   t          t          gd          t          dik    sJ t          t          t          gt          dt          di          t          dt          dik    sJ t          t          gt          di          t          dik    sJ d S )	Nr   )r   r   r   )dimsr   ro   rp   )r   r   r   rl   r   r   test_dim_handlingr   :  s    ###>':::::AaAq\222q-78.7J J J J JQM:::q(mKKKKKKr   c                     ddl } t          t          t          t          gt          t          z   gddt          dt          dt          di          }| j                             |ddgdd	gddg           | j        d	d
g          z
            dk     sJ t          t          t          t          gt          t          z   gt          dt          dt          didd          } | j        d          	                    d          }d | j        d          	                    d          z  }d | j        d          	                    d          z  }| j                             ||||          d | j        d          z  z
            dk     sJ dS )zU
    Test passing additional kwargs from theano_function() to theano.function().
    r   Nr   ignorer   )r   on_unused_inputr   r   r   r"   r   r   )r   r   r   )
numpyr0   r   r   r   r   r   r   r   r   )rO   r&   rv   r   zzs        r   test_theano_function_kwargsr   @  sv    !QQqSEq(y!Y9=	? 	? 	?A9>>!!QFQFQF33jbj!Q6H6HHIIDPPPP!QQqSE !9aAyIx	9 	9 	9A 
1		Y	'	'B	
929Q<<y))	)B	
929Q<<y))	)B9>>!!BB--!IBIaLL.899D@@@@@@r   c            	         t           t          gt           t          z   gddgft          t          gt          t          z   gddgft           t          gt           t          z   gt           dt          didgft           t          gt           t          z   t           t          z
  gdddgft           t          t          t          gt           t          z   t          t          z   gdddgfg} | D ]\  }}}}dD ]}t	          ||||          }t          |j        t          j        j	        j
                  sJ d |j        j        D             } || }t          |t                    s|g}t          |          t          |          k    sJ t          ||          D ]S\  }	}
|r#|	dk    rt          |
t          j                  sJ *t          |
t          j                  sJ |
j        |	k    sJ TdS )z2 Test the "scalar" argument to theano_function(). Nr   r   r   r   )r   r   c                 ^    g | ]*}t          j        d  |j        j        D                       +S )c                     g | ]}|rd nd	S )r   r   rl   )r   r   s     r   r   z:test_theano_function_scalar.<locals>.<listcomp>.<listcomp>g  s     GGGBbaGGGr   )rO   onesrS   ru   )r   is     r   r   z/test_theano_function_scalar.<locals>.<listcomp>f  sF        GG!&2FGGGHH  r   )r   r   rg   ri   r0   rQ   r    r   r>   function_moduleFunctioninput_storager2   lenziprO   rP   ndarrayndim)argsr.   r/   in_dimsout_dimsr   r&   	in_values
out_valuesdvalues              r   test_theano_function_scalarr  Q  s    Q!a%$$
Q!a%$$
Q!a%1aA,,
Q!a%Q1v.
Q1Aq1u~taV4D /3 + +*(# 	+ 	+F wvNNNA a/1O1XYYYYY *8  I IJj$// *(\
 x==C
OO3333*55 	+ 	+5 +a1ff%eRY777777 &eRZ88888 :?????	+%	++ +r   c                  2    t          t          d            dS )za
    Passing an unknown keyword argument to theano_function() should raise an
    exception.
    c                  D    t          t          gt          dz   gd          S )Nr   r   )foobar)r0   r   rl   r   r   r   z0test_theano_function_bad_kwarg.<locals>.<lambda>  s    /acU1EEE r   N)r   	Exceptionrl   r   r   test_theano_function_bad_kwargr  {  s    
 9EEFFFFFr   c            	         t          t          ddd                    t          ddd          k    sJ d } t          dt          di} | t          t          t          t                    |          t          t          t
                              sJ  | t          t          dt          d          |          t          dt          d                    sJ d S )Nr   r   r   c                     dD ]A}t          | |          }t          ||          }|||| dS .t          ||          s dS BdS )N)startstopstepFT)getattrrT   )s1s2attra1a2s        r   
theq_sliceztest_slice.<locals>.theq_slice  sj    - 	 	DT""BT""BzRZ
bj 55"b\\ uutr   r   r   )r,   slicer   r   rc   rd   )r  r   s     r   
test_slicer    s    aA''5Aq>>9999	 	 	 !W%F:l5A;;v>>>b"NNNNN:l5Aq>>&AAA5BPQ??SSSSSSSr   c                    	
 ddl m i } t          j        dd          }t          j        d||          }|ddd	d
ddf         }t          ||           	t                              d          
t          	j	        j
        j                  t          


          t          


          fk    sJ 	j	        j        d         t          ||           k    sJ t          	
fdt          dd          D                       sJ t          j        d          }t          ||di           d
|d}}}||||         }t          ||d|di          	d S )Nr   )Constantr   Tintegerrg   r   r   r   r"   r   r   r(   r   c              3   v   K   | ]3}j         j        |                              |                    V  4d S r   )r   r.   equals)r   r   r   rh   r   s     r   	<genexpr>z#test_MatrixSlice.<locals>.<genexpr>  sD      NNQrxq!((!Q88NNNNNNr      kr   r   )r   r   r$   r   r%   r,   rs   ScalarrR   r   r   idx_listr  r.   allrange)r(   r   rg   ri   r(  r  r  r  r   rh   r   s           @@@r   test_MatrixSlicer-    sx   E
	#t$$$A
Q""A	!Aa%1Q,A	au	%	%	%B
		'A%&&5Aq>>5Aq>>*JJJJJ8?1au!=!=!===== NNNNNN%1++NNNNNNNN
	#AAw<((((1a4E	%T/A	aGQ 8	9	9	9BBBr   c            
      d  
 t          j        dd          fddD             \  } }}}t          t          | |||f          \  }}}}t          j        | |g||gg          }t          |          
t
                              dt
                              d||          t
                              d||                    t
                              dt
                              d||          t
                              d||                    g}	t          
fd|	D                       sJ d S )	Nr   Tr!  c                 <    g | ]}t          j        |          S rl   r#   )r   r   r   s     r   r   z$test_BlockMatrix.<locals>.<listcomp>  s'    AAA$"/$1--AAAr   ABCDr   r   c              3   8   K   | ]}t          |          V  d S r   )rT   )r   solutionBlockts     r   r&  z#test_BlockMatrix.<locals>.<genexpr>  s-      @@(tFH%%@@@@@@r   )r$   r   r3   r,   BlockMatrixr
   joinany)ABCDAtBtCtDtBlock	solutionsr3  r   s             @@r   test_BlockMatrixrA    s   
	#t$$$AAAAA&AAAJAq!Q1a|44NBBNQFQF+,,E%  FBGGAr2..2r0B0BCCBGGAr2..2r0B0BCCEI@@@@i@@@@@@@@@@r   c            	         d\  } }dt          j        d||           }t          j        d||          }||f}|j        |z  }||dz  |dz  f| dz  | dz  fg||dz  |dz  f|dz  |dz  fgifd|D             }|                    t	          t          ||                              }t	          t          |gt          |          z                      }t          ||g|i           }	t          |t          j        |          g|i           }
fd|D             }t          j
        || z                                |j                                                t          j        |                                        g}|d	xx         t          j        |j                  d
z  z  cc<   t          j         |	|  |
| d
          sJ d S )N)r   r"   r   r7  r8  r   c                 @    g | ]}t          j        |g|         R  S rl   )r$   blockcut)r   r   cutsizess     r   r   z6test_BlockMatrix_Inverse_execution.<locals>.<listcomp>  s/    >>>!Q-!--->>>r   )r   r(   c                 f    g | ]-}t          j        j        |j                                       .S rl   )rO   randomrandshaper   )r   r   r   s     r   r   z6test_BlockMatrix_Inverse_execution.<locals>.<listcomp>  s2    FFF!ry~qw'..u55FFFr   r   gh㈵>)rtol)r$   r%   Isubsdictr  r   r0   block_collapserO   r   reshaperI  r   eyer   allclose)r(  r   r7  r8  r.   output	cutinputs	cutoutputr   r&   fblockedninputsrE  r   s               @@r   "test_BlockMatrix_Inverse_executionrW    s   DAqE
Q""A
Q""ATFSUFQT1a4L1a4A,/QT1a4L1a4A,/1H>>>>v>>>IDVY!7!78899I#fugc&kk12233F&&CCCA):9)E)E(F'-R9 9 9H GFFFvFFFGy1~~%%ag..55e<<vayy&&(GAJJJ"'!'""4''JJJ;qq'{HHg$6TBBBBBBBBr   c                     t          j        d          } t           j        t           j        fD ]} |t          j        |           t          j        |            gt          j        |           t          j        |           gg          }t          |          }t          |t          j	                  sJ |j
        j        t          j        k    sJ d S )Ntheta)r$   r   r   ImmutableMatrixr   r   r,   rQ   r
   rr   r   r   join_)r   
MatrixTyperg   tXs       r   test_DenseMatrixr^    s    
	'Ay""45 ' '
JRVAYYJ/"&))RVAYY1GHII!__"b/00000x{bh&&&&&	' 'r   c                     t           t          j        d          ft          t          j        dgt          j        R  ft           t          j        d          t          j        d                    fg} | D ]W\  }}i }t          ||          }t          ||          |u sJ t          |i           |usJ t          ||          |u sJ XdS )zH Test single symbol-like objects are cached when printed by themselves. r   rg   r&   r   r#  N)	r   r$   r   rg   r%   rI  r   r   r,   )pairsr  r  r(   sts        r   test_cache_basicrb    s    
 
BIcNN	
BOC*!'***+	bk#ry~~../E  3 3B"E*** Be,,,2222 Bb)))3333 Be,,,222223 3r   c                  z   ddl m}  t          |           }	 |                                  t          t
          t          fD ]K}t                      5  t          |          }t          |          |u sJ 	 ddd           n# 1 swxY w Y   L	 | 	                    |           dS # | 	                    |           w xY w)z Test use of the global cache. r   )global_cacheN)
sympy.printing.theanocoderd  rM  clearr   rg   r   r   r   update)rd  backupr   ra  s       r   test_global_cacheri    s   666666,F$Q 	, 	,A')) , , ^^"1~~+++++, , , , , , , , , , , , , , ,	, 	F#####F####s/   8B# #A?3B# ?B	B# B	B# #B:c            	      (   t          j        d          t          j        ddd          t          g} i }i }| D ]0}t	          ||          }||                                vsJ |||<   1t          t          t          t          |                                                              t          |           k    sJ |
                                D ]A\  }}t                      5  t          ||          |u sJ 	 ddd           n# 1 swxY w Y   BdS )z
    Test that symbol-like objects of different types (Symbol, MatrixSymbol,
    AppliedUndef) are distinguished by the cache even if they have the same
    name.
    r   r"   r#  N)r$   r   r%   r   r,   valuesr   setr3   iditemsr   r   )symbolsr(   printedr   ra  s        r   test_cache_types_distinctrq    s`    y1!=!=sCGEG  !5)))))))))

 s3r7>>++,,--..#g,,>>>>  5 52#%% 	5 	5q..."44444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	55 5s   #DD
	D
	c                      t          j        t          t          d          } t          |           }t	          |t
          t
          z             sJ t	          |t
          t          t                    z             rJ dS )zf
    Test that a symbol is cached and reused when it appears in an expression
    more than once.
    Fr   N)r$   Addr   r,   rT   rc   r   s     r   test_symbols_are_created_oncert    sh    
 6!Q'''DDb2gD"|A.///////r   c                  $   t           dz  t          t          j        t                     z
  t          j        t
          t           t          z  z
            z  z   } d | j        D             }t          |           }t                      }t          j
        j                            |g          D ]]}|j        Tt          |t          j
        j        j                  s0|j        |v sJ |j        |vsJ |                    |j                   ^||k    sJ dS )zf
    Test caching on a complicated expression with multiple symbols appearing
    multiple times.
    r   c                     h | ]	}|j         
S rl   r   )r   r   s     r   	<setcomp>z%test_cache_complex.<locals>.<setcomp>-  s    666qAF666r   N)r   r   r$   r   r   r   free_symbolsr,   rl  r   r4   r5   	ancestorsr   rQ   r   r   r   )r*   symbol_namesr   seenvs        r   test_cache_complexr}  '  s    
 6Q]bfQQY&7&777D66D$5666L$F 55DZ''11  7?:a1A1J#K#K?6\))))6%%%%HHQV <r   c                     t          j        dt          dk     ft          t          dk     fd          } t          |           }|j        j        t          j        k    sJ t                              t          dk     dt                              t          dk     t          d                    }t          ||          sJ t          j        t          t          dk     f          } t          |           }t                              t          dk     t          t          j                  }t          ||          sJ t          j        dt          j        t          dk    t          dk               ft          t          j        t          dk    t          dk               f          } t          |           }t                              t                              t          dk    t          dk               dt                              t                              t          dk    t          dk               t          t          j                            }t          ||          sJ d S )Nr   r   )r   Tr   )r$   	Piecewiser   r,   r   r   r
   switchrc   rT   rO   nanAndOrand_or_)r*   resultr   s      r   test_Piecewiser  ?  s   <AaC1ac(I66D$F<?bi''''yyAq"))BqD"a"8"899H!!!!!<AE
##D$FyyaRV,,H!!!!!<BF1Q3!,,-	
BE!A#qsOO D$FyyAbd++Q
		"&&Ar!t$$b"&113 3H!!!!!!!r   c                     t          t          t          j        t          t
                              t                              t          t                              sJ t          t          t          t
          k              t          t          k              sJ t          t          t          t
          k               t          t          k               sJ t          t          t          t
          k              t          t          k              sJ t          t          t          t
          k              t          t          k              sJ d S r   )
rT   r,   r$   Eqr   r   r
   eqrc   rd   rl   r   r   test_Relationalsr  U  s    RU1a[[))255R==99999QU##R"W-----QU##R"W-----Q!V$$bBh/////Q!V$$bBh///////r   c                  f   t                      5  t          t          t          di          t          t          t          di          }} d d d            n# 1 swxY w Y   ddlm} ddlm} ddlm} t                      5  t          t          t           |t                    z            || 
                                z            sJ t          t          dt          z            |  |d           |d	           |dd
          z  z   z            sJ 	 d d d            d S # 1 swxY w Y   d S )N
complex128r   r   )	conjugate)as_tensor_variable)complexy      ?       @r   r   r   )r   r,   r   r   $sympy.functions.elementary.complexesr  theano.tensorr  r  rT   conj)rc   rd   r  atvcplxs        r   test_complexfunctionsr  ^  s   		!	! e ea<(8999<STVbRc;d;d;dBe e e e e e e e e e e e e e e>>>>>>777777------		!	! N NL99Q<<00"bggii.AAAAAL$**BCS$$q))9K0K,LMMMMMMN N N N N N N N N N N N N N N N N Ns$   ;AAABD&&D*-D*c                      t                      5  t          g dg          } d d d            n# 1 swxY w Y    |             dk    sJ d S )Ny      ?      ?)r   r0   )tfs    r   test_constantfunctionsr  i  s    		!	! ) )b$(() ) ) ) ) ) ) ) ) ) ) ) ) ) )244::::::s   -11c                  Z   t          j        d          } t           j        }t          j                            t          |           t          j                   t          j                            t          |          t          j                   t          |           }t          j                            t          |           |	                                           t          |          }t          j                            t          |          |	                                           dS )zP
    Test that exp(1) prints without error and evaluates close to SymPy's E
    r   N)
r$   r   ErO   r   r   rN   er,   eval)e_ae_br  s      r   	test_Exp1r  o  s     &))C
$CJuSzz24000JuSzz24000SAJuSzz16688444SAJuSzz1668844444r   )[__doc__loggingsympy.externalr   sympy.testing.pytestr   r   r   	getLoggertheanologgersetLevelCRITICALr   WARNINGr   rO   r   rs   r   r
   rc   rd   re   rf   rh   rj   disabledsympyr$   sympy.core.singletonr   	sympy.abcr   r   r   r   re  r   r   r    rg   ri   rk   r   r   r,   r0   r;   rE   rT   rm   rx   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-  rA  rW  r^  rb  ri  rq  rt  r}  r  r  r  r  r  rl   r   r   <module>r     s     ( ( ( ( ( ( E E E E E E E E E E w !899   g& ' ' '	x	 	    go & & & 
 	B	B>>>>>JBBMMuMMMJBBB H     " " " " " "                                  4
3U
3
3
31a kbk#q+ + +: : :/ / /$  "- - -`
% 
% 
%	 	 	. . . 4 4 4  . . .
5 5 5     
\ 
\ 
\O O O) ) )$, , ,A A A@ @ @
9 9 9, , ,) ) )3 3 3  
  
= 
= 
=
> 
> 
>L L LA A A"(+ (+ (+TG G GT T T$: : :2A A A C C C2' ' '3 3 3.$ $ $$5 5 50	0 	0 	0     0" " ",0 0 0N N N  5 5 5 5 5r   