
    \hS              	          S r SSKrSSKJr  SSKJrJrJr  \R                  " S5      r	\	R                  \R                  5        \" S5      r\	R                  \R                  5        \(       aj  SSKr\R                   r\R$                  rS V s/ s H  n \R!                  U S5      PM     sn u  rrrS	 Vs/ s H  n\R%                  SS
US9PM     snu  rrrOSrSSKrSSKJr  SSKJ r J!r!J"r"J#r#  SSK$J%r%J&r&J'r'  S	 Vs/ s H  n\RQ                  USS5      PM     snu  r)r*r+\RX                  " S5      " \#5      r-S r.S r/S r0S r1S r2S r3S r4S r5\S 5       r6S r7S r8S r9S r:S r;S  r<S! r=S" r>S# r?S$ r@S% rAS& rBS' rCS( rDS) rES* rFS+ rGS, rHS- rIS. rJS/ rKS0 rLS1 rMS2 rNS3 rO\S4 5       rPS5 rQS6 rRS7 rSS8 rTS9 rUS: rVS; rWS< rXS= rYS> rZS? r[gs  sn f s  snf s  snf )@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theanoxyzfloatXXYZFF)nameT)S)xyzt)theano_codedim_handlingtheano_function   fc                     UR                  S0 5        [        5          [        U 40 UD6sSSS5        $ ! , (       d  f       g= f)zAWrapper for theano_code that uses a new, empty cache by default. cacheN)
setdefaultr   r   )exprkwargss     \/var/www/auris/envauris/lib/python3.13/site-packages/sympy/printing/tests/test_theanocode.pytheano_code_r   .   s1    
gr"		!4*6* 
"	!	!	   3
Ac                     UR                  S0 5        [        5          [        X40 UD6sSSS5        $ ! , (       d  f       g= f)zEWrapper for theano_function that uses a new, empty cache by default. r   N)r   r   r   )inputsoutputsr   s      r   theano_function_r"   4   s1    
gr"		!v9&9 
"	!	!r   c                     [        [        [        U 5      5      n[        R                  R
                  R                  U5      n[        R                  R
                  R                  X!5      u  p![        R                  R                  X!5      $ )zTransform 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-   ;   s`     L%()D
**


!
!$
'C

  &&s1IC::##C..    c                     [         R                  R                  5       R                  S5      nU R	                  5       n UR
                  R                  U 5        U $ )zSimplify a Theano Computation.

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

Returns
=======
theano.gof.FunctionGraph
fusion)r   compileget_default_mode	excludingr(   	optimizeroptimize)fgraphmodes     r   theano_simplifyr8   M   sC     >>**,66x@D\\^FNNF#Mr.   c                    [         [        [        R                  4n[	        X5      n[	        X5      nU(       d  U(       a  U(       a  U(       d  gX:H  $ [	        U [
        [        45      n[	        U[
        [        45      nU(       d  U(       aZ  U(       a  U(       a  [        U 5      [        U5      :w  a  g[        [        [        U 5      5      [        [        [        U5      5      :H  $ [        R                  R                  U SS9n[        R                  R                  USS9nSX4SX44 H-  u  pnUS:X  d  M  [        SU	< SU	< S	[        U
5      < S
35      e   Xx:H  $ )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tupler$   typer%   theqr   printing
debugprint	TypeError)r<   r=   numeric_typesa_is_numb_is_numa_is_seqb_is_seqastrbstrargnameargvalargstrs               r   rG   rG   ^   s     %+M!+H!+H 8Xv !eT]+H!eT]+H8X$q'T!W*<CaL!T#dA,%777 ??%%ae%4D??%%ae%4D &)!NS!N#CR< GT&\3  $D <r.   c                     [        [        [        [        5      5      (       d   e[        [        [        [
        5      5      (       d   e[        [        [        [        5      5      (       d   e[        [        [        [        5      5      (       d   e[        [        [        [        5      5      (       d   e[        [        [        [        5      5      (       d   eg)z}
Check that the example symbols in this module print to their Theano
equivalents, as many of the other tests depend on this.
N)rG   xtr   r   ytr   ztr   XtXYtYZtZ r.   r   test_example_symbolsr`      s    
 LO$$$$LO$$$$LO$$$$LO$$$$LO$$$$LO$$$$r.   c                  t   [        [        5      n [        U [        R                  [
        R                  45      (       d   eU R                  S:X  d   eU R                  [        R                  :X  d   e[        [        [        S0S9nUR                  S:X  d   eUR                  [        R                  :X  d   eg)z-Test printing a Symbol to a theano variable. r_   FbroadcastablesN)	r   r   rD   ttTensorVariabletsScalarVariablebroadcastabler   )xxxx2s     r   test_Symbolrl      s    	aBb2,,b.?.?@AAAAr!!!77aff
q!X
7C(((88qvvr.   c                      [        [        5      n [        U [        R                  5      (       d   eU R
                  S:X  d   eg)z3Test printing a MatrixSymbol to a theano variable. r   N)r   rZ   rD   re   rf   ri   )XXs    r   test_MatrixSymbolro      s8    	aBb"++,,,,~---r.   c                      / SQn U  H/  n[        [        5         [        [        [        U0S9  SSS5        M1     g! , (       d  f       MC  = f)z.Test MatrixSymbol with invalid broadcastable. )r_   rb   TTFFT)TTrc   N)r   
ValueErrorr   rZ   )bcsbcs     r   test_MatrixSymbol_wrong_dimsrw      s9     OCJAr73   s	   ;
A
	c                      [        [        5      n [        U [        R                  5      (       d   eU R
                  S:X  d   eU R                  S:X  d   eg)zFTest printing AppliedUndef instance, which works similarly to Symbol. r_   f_tN)r   ry   rD   re   rf   ri   r   )ftts    r   test_AppliedUndefr{      sK    
s
Cc2,,----"""88ur.   c                      [         [        -   n [        U 5      nUR                  R                  [
        R                  R                  :X  d   eg N)r   r   r   owneropr   tensoraddr   comps     r   test_addr      s5    q5DD::==FMM-----r.   c                  0   [        [        [        R                  " [        5      5      [
        R                  [        5      5      (       d   e[        [        [        R                  " [        5      5      [
        R                  [        5      5      (       d   eg r}   )rG   r   sysinr   re   rV   tanr_   r.   r   	test_trigr      sR    RVVAY'4444RVVAY'4444r.   c                     [         R                  " [        S-  [         R                  " [        5      -   5      [         R
                  " S[        -  5      -  n [        U 5      n[        R                  [        S-  [        R                  [        5      -   5      [        R                  S[        -  5      -  n[        X5      (       d   eg)z:Test printing a complex expression with multiple symbols.    N)r   expr   cosr   logr   r   re   rV   rW   rX   rG   )r   r   expecteds      r   	test_manyr      s}    66!Q$"#bffQqSk1DDvvb!ebffRj()BFF1R4L8Hr.   c                     S H1  n [        [        [        U 0S9R                  R                  U :X  a  M1   e   [        [        [        S0S9R                  R                  S;   d   e[        [        S-   [        S0S9R                  R                  S:X  d   e[        [        [        -   [        S[        S0S9R                  R                  S:X  d   eg)	z@Test specifying specific data types through the dtype argument. )float32float64int8int16int32int64dtypesr	   )r   r      r   r   N)r   r   rF   dtyper   )r   s    r   
test_dtyper      s    JAq%j166<<EEE K 1h-055;;?UUUU Aq)n5::@@IMMMAq)Q	&BCHHNNR[[[[r.   c                  r    [         [        4 H'  n S H  n[        X U0S9R                  U:X  a  M   e   M)     g)zFTest the "broadcastables" argument when printing symbol-like objects. )r_   rb   rq   r   rr   rc   N)r   ry   r   ri   )srv   s     r   test_broadcastablesr      s:     XHBb':HHBNNN I r.   c                      [         [        -   n / SQ/ SQ/ SQ/ SQ/ SQ/nU H.  u  p#n[        U [         U[        U0S9nUR                  U:X  a  M.   e   g)zFTest "broadcastable" attribute after applying element-wise binary op. )r_   r_   r_   )rb   rb   rb   )rq   rb   rb   )rs   r   r   )rr   r   r   rc   N)r   r   r   ri   )r   casesbc1bc2bc3r   s         r   test_broadcastingr      s^     q5D 	&%77E #D!S!S1AB!!S((( r.   c                  &   [         [        -  [        -  n [        U 5      n[	        UR
                  R                  [        R                  5      (       d   e[        U[        R                  [        5      R                  [        5      5      (       d   eg r}   )rZ   r\   r^   r   rD   r~   r   re   DotrG   rY   dotr[   r]   )r   expr_ts     r   test_MatMulr      s\    Q3q5D$Fflloorvv....r
r*++++r.   c                      [        [        [        R                  5      R                  R
                  [        R                  5      (       d   eg r}   )rD   r   rZ   Tr~   r   re   
DimShuffler_   r.   r   test_Transposer      s.    l133'--00"--@@@@r.   c                      [         [        -   [        -   n [        [	        U 5      R
                  R                  [        R                  5      (       d   eg r}   )	rZ   r\   r^   rD   r   r~   r   re   Elemwiser   s    r   test_MatAddr      s7    Q3q5Dl4(..112;;????r.   c                     [        [        [        R                  " S5      S-  5      [        R                  SS5      5      (       d   e[        [        [        R                  5      [        R                  SS5      5      (       d   eg )Nr      r   )rG   r   r   Integerre   true_divr   Halfr_   r.   r   test_Rationalsr     sY    RZZ]Q./Q1BCCCCQVV$bkk!Q&78888r.   c                  N    [        [        R                  " S5      5      S:X  d   eg )Nr   )r   r   r   r_   r.   r   test_Integersr     s    

1&!+++r.   c                  |    [         R                  " S5      n [        [         R                  " U 5      5      (       d   eg )Nn)r   Symbolr   	factorial)r   s    r   test_factorialr     s(    
		#AQ((((r.   c                     S n [        U " [        [        R                  " [        R                  " [
        5      [
        SS95      5      U " [        R                  [        R	                  [        5      [        5      5      5      (       d   eg )Nc                 *    [        [        U 5      5      $ r}   )r8   r-   r   s    r   <lambda>!test_Derivative.<locals>.<lambda>  s    	$8r.   Fevaluate)
rG   r   r   
Derivativer   r   r   gradre   rV   )simps    r   test_Derivativer     sZ    8D\"--q	1u"MNOV[[R013 3 3 3r.   c                  f    [        [        [        /[        [        -   /5      n U " SS5      S:X  d   eg)z+Test theano_function() with single output. r   r      Nr"   r   r   )r   s    r   test_theano_function_simpler     s*    !Q!A#'AQ7a<<r.   c                      [        [        [        /[        [        -   [        [        -
  /5      n U " SS5      u  pUS:X  d   eUS:X  d   eg)z.Test theano_function() with multiple outputs. r   r   r   Nr   )r   o1o2s      r   test_theano_function_multir     sA    !Q!A#qs,Aq!WFB7N78O8r.   c            	      r   [        [        [        /[        [        -   /S[        S[        S0S9n [        R                  R                  U " SS/SS/5      [        R                  " SS/5      -
  5      S:  d   e[        [        [        /[        [        -   /[        S[        S0SS	9n [        R                  " S5      R                  S5      nS[        R                  " S5      R                  S5      -  n[        R                  R                  U " X5      S[        R                  " S5      -  -
  5      S:  d   eg
)z0Test theano_function() vs Numpy implementation. r   r   )dimr   r   r   r      &.>)r   r   N)	r"   r   r   rB   linalgnormasarrayarangeastype)r   rj   yys      r   test_theano_function_numpyr   !  s    !Q!A#A!"Iq) <	>A99>>!QFQF+bjj!Q.@@ADHHH!Q!A#9a/K	 A	1		Y	'B	
299Q<y)	)B99>>!B)a		!n45<<<r.   c                     [         R                  " [        [        /[        [        [        -   [        -   //5      n [
        R                  " SS/SS//5      n[        [        [        [        /U /5      n[
        R                  R                  U" SSS5      U5        [        [        [        [        /U /SS9n[
        R                  R                  U" SSS5      U5        [        [        [        [        /X /5      n[        U" SSS5      [        / 5      5      (       d   e[
        R                  R                  U" SSS5      S   U5        [
        R                  R                  U" SSS5      S   U5        g )	N      ?       @g      @g      @T)scalarr   r   )r   Matrixr   r   r   rB   arrayr"   testingassert_allcloserD   rF   )mr   r   s      r   test_theano_function_matrixr   .  s   
		Aq6Aq1uqy>*+Axx#sc?%;<=H!QQC(AJJqc3/:!QQC5AJJqc3/:!QQF+AaS#&R1111JJqc3/2H=JJqc3/2H=r.   c                      [        [        /SS9[        S0:X  d   e[        [        [        /[        S[        S0S9[        S[        S0:X  d   e[        [        /[        S0S9[        S0:X  d   eg )	Nr   )r   r   r   )dimsrs   rb   rc   )r   r   r   r_   r.   r   test_dim_handlingr   :  st    #>'::::AaAq\2q-78.7J J J JQM:q(mKKKr.   c                     SSK n [        [        [        [        /[        [        -   /SS[        S[        S[        S0S9nU R
                  R                  U" SS/SS	/SS/5      U R                  " S	S
/5      -
  5      S:  d   e[        [        [        [        /[        [        -   /[        S[        S[        S0SSS9nU R                  " S5      R                  S5      nSU R                  " S5      R                  S5      -  nSU R                  " S5      R                  S5      -  nU R
                  R                  U" X#U5      SU R                  " S5      -  -
  5      S:  d   eg)zM
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   )
numpyr"   r   r   r   r   r   r   r   r   )rB   r   rj   r   zzs        r   test_theano_function_kwargsr   @  s,    !QQqSEq(y!Y9=	?A99>>!QFQFQF3bjj!Q6HHIDPPP!QQqSE !9aAyIx	9A 
1		Y	'B	
299Q<y)	)B	
299Q<y)	)B99>>!BB-!BIIaL.89D@@@r.   c                     [         [        /[         [        -   /SS/4[        [        /[        [        -   /SS/4[         [        /[         [        -   /[         S[        S0S/4[         [        /[         [        -   [         [        -
  /SSS/4[         [        [        [        /[         [        -   [        [        -   /SSS/4/n U  GHr  u  pp4S GHd  n[	        XX5S9n[        UR                  [        R                  R                  R                  5      (       d   eUR                  R                   VVs/ s HF  n[        R                  " UR                  R                   Vs/ s H  o(       a  SOSPM     sn5      PMH     n	nnU" U	6 n
[        U
[         5      (       d  U
/n
[#        U5      [#        U
5      :X  d   e[%        XJ5       Hh  u  pU(       a)  US:X  a#  [        U[        R&                  5      (       d   eM5  [        U[        R(                  5      (       d   eUR*                  U:X  a  Mh   e   GMg     GMu     gs  snf s  snnf )z1Test the "scalar" argument to theano_function(). Nr   r   r   rs   )r   r   r   )r   r   rZ   r\   r"   rD   r   r   r1   function_moduleFunctioninput_storagerB   onesrF   ri   r$   lenziprC   ndarrayndim)argsr    r!   in_dimsout_dimsr   r   irv   	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 wNA a//1O1O1X1XYYYY
 **888A !&&2F2FG2FBba2FGH8   IJj$//(\
 x=C
O3335a1f%eRYY7777 &eRZZ8888 ::?*? 6% $ /3 Hs   0.H>
H92H>
9H>
c                  &    [        [        S 5        g)zU
Passing an unknown keyword argument to theano_function() should raise an
exception.
c                  2    [        [        /[        S-   /SS9$ )Nr   r   )foobar)r"   r   r_   r.   r   r   0test_theano_function_bad_kwarg.<locals>.<lambda>  s    /acU1Er.   N)r   	Exceptionr_   r.   r   test_theano_function_bad_kwargr  {  s    
 9EFr.   c            	      X   [        [        SSS5      5      [        SSS5      :X  d   eS n [        S[        S0nU " [        [        [        [        5      US9[        [        [
        5      5      (       d   eU " [        [        S[        S5      US9[        S[        S5      5      (       d   eg )Nr   r   r   c                     S H=  n[        X5      n[        X5      nUb  Uc  Ub  Ub    gM)  M+  [        X45      (       a  M=    g   g)N)startstopstepFT)getattrrG   )s1s2attra1a2s        r   
theq_slicetest_slice.<locals>.theq_slice  sM    -D"B"BzRZ
bj  '1
"\\ . r.   r   r   )r   slicer   r   rV   rW   )r  r   s     r   
test_slicer    s    aA'5Aq>999	 !W%Fl5A;v>b"NNNNl5Aq>&A5BPQ?SSSSr.   c                  d  ^^	^
 SSK Jm  0 n [        R                  " SSS9n[        R                  " SX5      nUSSS	2S
SS24   n[        X0S9m	[        R                  S5      m
[        T	R                  R                  R                  5      [        T
T
T
5      [        T
T
T
5      4:X  d   eT	R                  R                  S   [        X S9:X  d   e[        UU	U
4S j[        SS5       5       5      (       d   e[        R                  " S5      n[        XDS0S9  S
USpvnX%Xg2   n[        X1SUS0S9m	g )Nr   )Constantr   TintegerrZ   r   r   r   r   r   r   r   r   c              3      >#    U  H4  nTR                   R                  U   R                  T" TU5      5      v   M6     g 7fr}   )r~   r    equals).0r   r  r[   r   s     r   	<genexpr>#test_MatrixSlice.<locals>.<genexpr>  s2     N+Qrxxq!((!Q88+s   <?   kr   r   )r   r  r   r   MatrixSymbolr   rg   ScalarrE   r~   r   idx_listr  r    allrange)r   r   rZ   r\   r#  r  r  r  r  r[   r   s           @@@r   test_MatrixSlicer)    s   E
		#t$A
Q"A	!Aa%1Q,A	a	%B
		'A%%&5Aq>5Aq>*JJJJ88??1a!==== N%1+NNNNN
		#Aw<(1aE	/A	aGQ 8	9Br.   c            
      8  ^ [         R                  " SSS9n S Vs/ s H  n[         R                  " XU 5      PM     snu  p#pE[        [        X#XE45      u  pgp[         R
                  " X#/XE//5      n
[	        U
5      m[        R                  S[        R                  SXg5      [        R                  SX5      5      [        R                  S[        R                  SXh5      [        R                  SXy5      5      /n[        U4S jU 5       5      (       d   eg s  snf )Nr   Tr  ABCDr   r   c              3   <   >#    U  H  n[        TU5      v   M     g 7fr}   )rG   )r  solutionBlockts     r   r   #test_BlockMatrix.<locals>.<genexpr>  s     @i(tFH%%is   )	r   r   r$  r%   r   BlockMatrixre   joinany)r   r   ABCDAtBtCtDtBlock	solutionsr.  s               @r   test_BlockMatrixr=    s    
		#t$A:@A&$"//$1-&AJA!a|4NBBNNQFQF+,E% FBGGAr.20BCBGGAr.20BCEI@i@@@@@ Bs   !Dc            	          Su  pSn[         R                  " SX5      n[         R                  " SX5      nX44nUR                  U-  nX1S-  US-  4U S-  U S-  4/XAS-  US-  4US-  US-  4/0nU Vs/ s H  n[         R                  " U/Xx   Q76 PM     n	nUR	                  [        [        XY5      5      5      n
[        [        XR/[        U5      -  5      5      n[        XV/U0 S9n[        U[         R                  " U
5      /U0 S9nU Vs/ s H9  n[        R                  R                  " UR                  6 R                  U5      PM;     nn[        R                  " X-  5      R!                  UR                  5      R                  U5      [        R"                  " U5      R                  U5      /nUS==   [        R$                  " UR                  5      S-  -  ss'   [        R&                  " U" U6 U" U6 SS	9(       d   eg s  snf s  snf )
N)r   r   r   r3  r4  r   )r   r   r   gh㈵>)rtol)r   r$  Iblockcutsubsdictr   r   r"   block_collapserB   randomrandshaper   r   reshapeeyer   allclose)r#  r   r   r3  r4  r    outputcutsizesr   	cutinputs	cutoutputr   r   fblockedr   ninputss                   r   "test_BlockMatrix_Inverse_executionrQ    s   DAE
Q"A
Q"ATFSSUFT1a4L1a4A,/T1a4L1a4A,/1H7=>v!Q--vI>DV!789I#fgc&k123F&CA):):9)E(F'-R9H @FFv!ryy~~qww'..u5vGFyy~%%agg.55e<vvay&(GAJ"''!''"4''J;;q'{Hg$6TBBB ? Gs   3#HA Hc                     [         R                  " S5      n [         R                  [         R                  4 H  nU" [         R                  " U 5      [         R
                  " U 5      * /[         R
                  " U 5      [         R                  " U 5      //5      n[        U5      n[        U[        R                  5      (       d   eUR                  R                  [        R                  :X  a  M   e   g )Ntheta)r   r   r   ImmutableMatrixr   r   r   rD   re   rf   r~   r   join_)r   
MatrixTyperZ   tXs       r   test_DenseMatrixrX    s    
		'Ayy""4"45
RVVAYJ/"&&)RVVAY1GHI!_"b//0000xx{{bhh&&&	 6r.   c                  ~   [         [        R                  " S5      4[        [        R                  " S/[        R
                  Q76 4[        [        R                  " S5      " [        R                  " S5      5      4/n U  H;  u  p0 n[        XS9n[        XS9UL d   e[        U0 S9ULd   e[        X#S9UL a  M;   e   g)zGTest single symbol-like objects are cached when printed by themselves. r   rZ   r   r   r  N)	r   r   r   rZ   r$  rG  ry   r   r   )pairsr  r  r   sts        r   test_cache_basicr\    s    
 
BIIcN	
BOOC*!''*+	bkk#ryy~./E "* B,222 Bb)333 B,222 r.   c                  H   SSK Jn   [        U 5      n U R                  5         [        [
        [        4 H2  n[        5          [        U5      n[        U5      UL d   e SSS5        M4     U R                  U5        g! , (       d  f       MW  = f! U R                  U5        f = f)zTest use of the global cache. r   )global_cacheN)
sympy.printing.theanocoder^  rC  clearr   rZ   ry   r   r   update)r^  backupr   r[  s       r   test_global_cacherc    s    6,F$QA') ^"1~+++ *)  	F# *) 	F#s#   .B A<B <
B	B B!c            	         [         R                  " S5      [         R                  " SSS5      [        /n 0 n0 nU  H%  n[	        X1S9nXBR                  5       ;  d   eXBU'   M'     [        [        [        [        UR                  5       5      5      5      [        U 5      :X  d   eUR                  5        H'  u  p4[        5          [        X1S9UL d   e SSS5        M)     g! , (       d  f       M;  = f)z
Test that symbol-like objects of different types (Symbol, MatrixSymbol,
AppliedUndef) are distinguished by the cache even if they have the same
name.
ry   r   r  N)r   r   r$  ry   r   valuesr   setr%   iditemsr   r   )symbolsr   printedr   r[  s        r   test_cache_types_distinctrk    s     yy1!=sCGEG!)))))
  s3r7>>+,-.#g,>>> #%q."444 &% !%%s   C
C-	c                      [         R                  " [        [        SS9n [        U 5      n[	        U[
        [
        -   5      (       d   e[	        U[
        [        [        5      -   5      (       a   eg)zZ
Test that a symbol is cached and reused when it appears in an expression
more than once.
Fr   N)r   Addr   r   rG   rV   r   s     r   test_symbols_are_created_oncern    sV    
 66!Q'DDb2gD"|A./////r.   c                     [         S-  [        [        R                  " [         5      -
  [        R                  " [
        [         [        -  -
  5      -  -   n U R                   Vs1 s H  oR                  iM     nn[        U 5      n[        5       n[        R                  R                  R                  U/5       H  nUR                  b  M  [        U[        R                  R                  R                   5      (       a  MG  UR                  U;   d   eUR                  U;  d   eUR#                  UR                  5        M     XB:X  d   egs  snf )zZ
Test caching on a complicated expression with multiple symbols appearing
multiple times.
r   N)r   r   r   r   r   r   free_symbolsr   r   rf  r   r&   r'   	ancestorsr~   rD   r  r   )r   r   symbol_namesr   seenvs         r   test_cache_complexru  '  s    
 6Q]bffQQY&777D$($5$56$5qFF$5L6$F 5DZZ''177?:a1A1A1J1J#K#K66\)))66%%%HHQVV 2  7s   #Ec                  R   [         R                  " S[        S:  4[        [        S:  4S5      n [        U 5      nUR                  R
                  [        R                  :X  d   e[        R                  [        S:  S[        R                  [        S:  [        S5      5      n[        X5      (       d   e[         R                  " [        [        S:  45      n [        U 5      n[        R                  [        S:  [        [        R                  5      n[        X5      (       d   e[         R                  " S[         R                  " [        S:  [        S:  5      4[        [         R                  " [        S:  [        S:  5      45      n [        U 5      n[        R                  [        R                  [        S:  [        S:  5      S[        R                  [        R                  [        S:  [        S:  5      [        [        R                  5      5      n[        X5      (       d   eg )Nr   r   )r   Tr   )r   	Piecewiser   r   r~   r   re   switchrV   rG   rB   nanAndOrand_or_)r   resultr   s      r   test_Piecewiser  ?  st   <<AaC1ac(I6D$F<<??bii'''yyAq"))BqD"a"89H!!!!<<AE
#D$FyyaRVV,H!!!!<<BFF1Q3!,-	
BEE!A#qsOD$FyyAbd+Q
		"&&Ar!t$b"&&13H!!!!r.   c                  >   [        [        [        R                  " [        [
        5      5      [        R                  [        [        5      5      (       d   e[        [        [        [
        :  5      [        [        :  5      (       d   e[        [        [        [
        :  5      [        [        :  5      (       d   e[        [        [        [
        :  5      [        [        :  5      (       d   e[        [        [        [
        :*  5      [        [        :*  5      (       d   eg r}   )
rG   r   r   Eqr   r   re   eqrV   rW   r_   r.   r   test_Relationalsr  U  s    RUU1a[)255R=9999QU#R"W----QU#R"W----Q!V$bBh////Q!V$bBh////r.   c                      [        5          [        [        [        S0S9[        [        [        S0S9pS S S 5        SSKJn  SSKJn  SSKJn  [        5          [        [        [        U" [        5      -  5      WW R                  5       -  5      (       d   e[        [        S[        -  5      X" S5      U" S	5      U" SS
5      -  -   -  5      (       d   e S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)N
complex128r   r   )	conjugate)as_tensor_variable)complexy      ?       @r   r   r   )r   r   r   r   $sympy.functions.elementary.complexesr  theano.tensorr  r  rG   conj)rV   rW   r  atvcplxs        r   test_complexfunctionsr  ^  s    		!a<(89<STVbRc;dB 
">7-		!L9Q<0"bggi.AAAAL$*BCS$q)9K0K,LMMMM 
"	! 
"	!
 
"	!s   (CA=C/
C,/
C=c                      [        5          [        / S/5      n S S S 5        W " 5       S:X  d   eg ! , (       d  f       N= f)Ny      ?      ?)r   r"   )tfs    r   test_constantfunctionsr  i  s2    		!b$( 
"4:: 
"	!s   /
=c                  4   [         R                  " S5      n [         R                  n[        R                  R                  [        U 5      [        R                  5        [        R                  R                  [        U5      [        R                  5        [        U 5      n[        R                  R                  [        U 5      UR                  5       5        [        U5      n[        R                  R                  [        U5      UR                  5       5        g)zH
Test that exp(1) prints without error and evaluates close to SymPy's E
r   N)
r   r   ErB   r   r   rA   er   eval)e_ae_br  s      r   	test_Exp1r  o  s     &&)C
$$CJJuSz2440JJuSz2440SAJJuSz16684SAJJuSz16684r.   )\__doc__loggingsympy.externalr   sympy.testing.pytestr   r   r   	getLoggertheanologgersetLevelCRITICALr   WARNINGr   rB   r   rg   r   re   rV   rW   rX   rY   r[   r]   disabledsympyr   sympy.core.singletonr   	sympy.abcr   r   r   r   r_  r   r   r   r$  rZ   r\   r^   r   ry   r   r"   r-   r8   rG   r`   rl   ro   rw   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=  rQ  rX  r\  rc  rk  rn  ru  r  r  r  r  r  )r   r   s   00r   <module>r     s<    ( E E  !89   g&& '	x	    goo & 
	B	B8=>"))D(+>JBBGLMu!"))Hn1)=uMJBB H  "      .3
3U2??1a#U
31a 	kk#q+:/$"-`
%	. 4 4.
5 
\O)$,A@
9,)3

=
>LA"(+TGT$:2A C C2'3.$$50	0 0",0N5m ?M 4s   G5G>G