
    \h\S              	          S r SSKrSSKJr  SSKJrJrJr  SSKJ	r	  \R                  " S5      r\R                  \R                  5        \" S5      r\R                  \R                  5        \(       a  SSKr\R$                  rSSKJr  SS	KJr  SS
KJr  SSKJrJr  SSKJr  SSKJ r   S V s/ s H  n \RC                  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/J0r0J1r1  SSKJ2r2J3r3J4r4  S Vs/ s H  n\*Rk                  USS5      PM     snu  r6r7r8\*Rr                  " S5      " \15      r:S r;S r<S r=S r>S r?S r@S rAS  rB\S! 5       rCS" rDS# rES$ rFS% rGS& rHS' rIS( rJS) rKS* rLS+ rMS, rNS- rOS. rPS/ rQS0 rRS1 rSS2 rTS3 rUS4 rVS5 rWS6 rXS7 rYS8 rZS9 r[S: r\\S; 5       r]S< r^S= r_S> r`S? raS@ rbSA rcSB rdSC reSD rfSE rggs  sn f s  snf s  snf )Fa  
Important note on tests in this module - the Aesara 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 aesara_code_ and
aesara_function_ functions defined below which default to using a new, empty
cache instead.
    N)import_module)raisesSKIPwarns_deprecated_sympy)ignore_warningszaesara.configdefaultsaesara)
ScalarType)Variable)TensorVariable)Elemwise
DimShuffle)Dot)true_dividexyzfloatXXYZFF)nameT)S)xyzt)aesara_codedim_handlingaesara_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 aesara_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_aesaracode.pyaesara_code_r%   8   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 aesara_function that uses a new, empty cache by default. r    N)r!   r   r   )inputsoutputsr#   s      r$   aesara_function_r*   >   s1    
gr"		!v9&9 
"	!	!r&   c                  @   [        [        [        U 5      5      n[        [        R                  R
                  R                  U5      5      n[        R                  R
                  R                  X!5      u  p![        R                  R                  R                  X!5      $ )zTransform SymPy expressions into Aesara Computation.

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

Returns
=======
aesara.graph.fg.FunctionGraph
)
listmapr%   r   graphbasicgraph_inputsclonefgFunctionGraph)exprsoutsinss      r$   	fgraph_ofr7   E   si     L%()D
v||!!..t4
5C""((3IC<<??((33    c                     [         R                  R                  5       R                  S5      nU R	                  5       n UR
                  R                  U 5        U $ )zSimplify a Aesara Computation.

Parameters
==========
fgraph : aesara.graph.fg.FunctionGraph

Returns
=======
aesara.graph.fg.FunctionGraph
fusion)r   compileget_default_mode	excludingr1   	optimizerrewrite)fgraphmodes     r$   aesara_simplifyrB   W   sC     >>**,66x@D\\^FNN6"Mr8   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 Aesara 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aesara.printing.debugprint(z) returned empty string (z is instance of ))intfloatnpnumber
isinstancetupler,   typer-   theqr   printing
debugprint	TypeError)rF   rG   numeric_typesa_is_numb_is_numa_is_seqb_is_seqastrbstrargnameargvalargstrs               r$   rQ   rQ   h   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 <r8   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 Aesara
equivalents, as many of the other tests depend on this.
N)rQ   xtr%   r   ytr   ztr   XtXYtYZtZ r8   r$   test_example_symbolsrj      s    
 LO$$$$LO$$$$LO$$$$LO$$$$LO$$$$LO$$$$r8   c                  @   [        [        5      n [        U [        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 aesara variable. ri   FbroadcastablesN)r%   r   rN   r
   broadcastabler   )xxxx2s     r$   test_Symbolrr      s    	aBb(####r!!!77aff
q!X
7C(((88qvvr8   c                  t    [        [        5      n [        U [        5      (       d   eU R                  S:X  d   eg)z3Test printing a MatrixSymbol to a aesara variable. r   N)r%   rd   rN   r   ro   )XXs    r$   test_MatrixSymbolru      s2    	aBb.))))~---r8   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. )ri   rl   TTFFT)TTrm   N)r   
ValueErrorr%   rd   )bcsbcs     r$   test_MatrixSymbol_wrong_dimsr}      s9     OCJAr73   s	   ;
A
	c                      [        [        5      n [        U [        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. ri   f_tN)r%   r   rN   r   ro   r   )ftts    r$   test_AppliedUndefr      sE    
s
Cc>****"""88ur8   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-----r8   c                  0   [        [        [        R                  " [        5      5      [
        R                  [        5      5      (       d   e[        [        [        R                  " [        5      5      [
        R                  [        5      5      (       d   eg r   )rQ   r%   sysinr   aetr`   tanri   r8   r$   	test_trigr      sR    RVVAY'5555RVVAY'5555r8   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%   r   r`   ra   rb   rQ   )r"   r   expecteds      r$   	test_manyr      s}    66!Q$"#bffQqSk1DDwwr1uswwr{*+cggadm;Hr8   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   rP   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[[[[r8   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. )ri   rl   rw   r   rx   rm   N)r   r   r%   ro   )sr|   s     r$   test_broadcastablesr      s:     XHBb':HHBNNN I r8   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. )ri   ri   ri   )rl   rl   rl   )rw   rl   rl   )ry   r   r   )rx   r   r   rm   N)r   r   r%   ro   )r"   casesbc1bc2bc3r   s         r$   test_broadcastingr      s^     q5D 	&%77E #D!S!S1AB!!S((( r8   c                     [         [        -  [        -  n [        U 5      n[	        UR
                  R                  [        5      (       d   e[        U[        R                  [        5      R                  [        5      5      (       d   eg r   )rd   rf   rh   r%   rN   r   r   r   rQ   rc   dotre   rg   )r"   expr_ts     r$   test_MatMulr      sX    Q3q5D$Fflloos++++r
r*++++r8   c                      [        [        [        R                  5      R                  R
                  [        5      (       d   eg r   )rN   r%   rd   Tr   r   r   ri   r8   r$   test_Transposer     s*    l133'--00*====r8   c                      [         [        -   [        -   n [        [	        U 5      R
                  R                  [        5      (       d   eg r   )rd   rf   rh   rN   r%   r   r   r   r"   s    r$   test_MatAddr   	  s3    Q3q5Dl4(..118<<<<r8   c                      [        [        [        R                  " S5      S-  5      [	        SS5      5      (       d   e[        [        [
        R                  5      [	        SS5      5      (       d   eg )Nr      r   )rQ   r%   r   Integerr   r   Halfri   r8   r$   test_Rationalsr     sQ    RZZ]Q./Q1BCCCCQVV$k!Q&78888r8   c                  N    [        [        R                  " S5      5      S:X  d   eg )Nr   )r%   r   r   ri   r8   r$   test_Integersr     s    

1&!+++r8   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((((r8   c                  l   [        [        5         S n [        U " [        [        R
                  " [        R                  " [        5      [        SS95      5      U " [        R                  [        R                  [        5      [        5      5      5      (       d   e S S S 5        g ! , (       d  f       g = f)Nc                 *    [        [        U 5      5      $ r   )rB   r7   r   s    r$   <lambda>!test_Derivative.<locals>.<lambda>  s    OIdO<r8   Fevaluate)r   UserWarningrQ   r%   r   
Derivativer   r   r   gradr   r`   )simps    r$   test_Derivativer     sn    		%<DbmmBFF1Iq5&QRSSWWR["568 8 	8 8 
&	%	%s   BB%%
B3c                  f    [        [        [        /[        [        -   /5      n U " SS5      S:X  d   eg)z+Test aesara_function() with single output. r   r      Nr*   r   r   )r   s    r$   test_aesara_function_simpler      s*    !Q!A#'AQ7a<<r8   c                      [        [        [        /[        [        -   [        [        -
  /5      n U " SS5      u  pUS:X  d   eUS:X  d   eg)z.Test aesara_function() with multiple outputs. r   r   r   Nr   )r   o1o2s      r$   test_aesara_function_multir   %  sA    !Q!A#qs,Aq!WFB7N78O8r8   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 aesara_function() vs Numpy implementation. r   r   )dimr   r   r   r      &.>)r   r   N)	r*   r   r   rL   linalgnormasarrayarangeastype)r   rp   yys      r$   test_aesara_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<<<r8   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   rL   arrayr*   testingassert_allcloserN   rP   )mr   r   s      r$   test_aesara_function_matrixr   9  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=r8   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   )dimsry   rl   rm   )r   r   r   ri   r8   r$   test_dim_handlingr   E  st    #>'::::AaAq\2q-78.7J J J JQM:q(mKKKr8   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 aesara_function() to aesara.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   )rL   r   rp   r   zzs        r$   test_aesara_function_kwargsr   K  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@@@r8   c                  P   SSK Jn   [        [        /[        [        -   /SS/4[        [
        /[        [
        -   /SS/4[        [        /[        [        -   /[        S[        S0S/4[        [        /[        [        -   [        [        -
  /SSS/4[        [        [        [
        /[        [        -   [        [
        -   /SSS/4/nU GHP  u  p#pES GHB  n[        X#XFS9n[        UR                  U 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[!        X[5       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ME     GMS     gs  sn	f s  sn	nf )	z1Test the "scalar" argument to aesara_function(). r   )FunctionNr   r   ry   )r   r   r   )aesara.compile.function.typesr   r   r   rd   rf   r*   rN   r   input_storagerL   onesrP   ro   r,   lenziprM   ndarrayndim)r   argsr(   r)   in_dimsout_dimsr   r   ir|   	in_values
out_valuesdvalues                 r$   test_aesara_function_scalarr  \  s   6 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//::::
 **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   .H"
HH"
H"
c                  &    [        [        S 5        g)zU
Passing an unknown keyword argument to aesara_function() should raise an
exception.
c                  2    [        [        /[        S-   /SS9$ )Nr   r   )foobar)r*   r   ri   r8   r$   r   0test_aesara_function_bad_kwarg.<locals>.<lambda>  s    /acU1Er8   N)r   	Exceptionri   r8   r$   test_aesara_function_bad_kwargr    s    
 9EFr8   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)getattrrQ   )s1s2attra1a2s        r$   
theq_slicetest_slice.<locals>.theq_slice  sM    -D"B"BzRZ
bj  '1
"\\ . r8   r   r   )r%   slicer   r   r`   ra   )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Sr8   c                  8  ^	 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	[	        S5      n[        T	R                  R                  R                  5      [        XDU5      [        XDU5      4:X  d   eT	R                  R                  S   [        X S9:X  d   e[        U	4S j[        SS5       5       5      (       d   e[         R                  " S5      n[        XUS0S9  SUSpnX&Xx2   n[        X1SUS0S9m	g )Nr   Tintegerrd   r   r   r   r   r   r   r    r   r   c              3   p   >#    U  H+  nTR                   R                  U   R                  U:H  v   M-     g 7fr   )r   r(   data).0r  re   s     r$   	<genexpr>#test_MatrixSlice.<locals>.<genexpr>  s)     A[rxxq!&&!+[s   36   kr   r   )r   r   MatrixSymbolr%   r	   rO   r   r   idx_listr  r(   allrange)
r    r   rd   rf   r   r&  r  r  r  re   s
            @r$   test_MatrixSlicer+    s	   E
		#t$A
Q"A	!Aa%1Q,A	a	%B7A%%&5q>5q>*JJJJ88??1a!==== AU1a[AAAAA
		#Aw<(1aE	/A	aGQ 8	9Br8   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   )rQ   )r"  solutionBlockts     r$   r#  #test_BlockMatrix.<locals>.<genexpr>  s     @i(tFH%%is   )	r   r   r'  r-   r%   BlockMatrixr   joinany)r   r   ABCDAtBtCtDtBlock	solutionsr0  s               @r$   test_BlockMatrixr?    s    
		#t$A:@A&$"//$1-&AJA!a|4NBBNNQFQF+,E% F!SXXa0#((1b2EF!SXXa0#((1b2EFH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   r5  r6  r   )r   r    r   gh㈵>)rtol)r   r'  Iblockcutsubsdictr   r   r*   block_collapserL   randomrandshaper   r   reshapeeyer   allclose)r&  r   r   r5  r6  r(   outputcutsizesr  	cutinputs	cutoutputr   r   fblockedr   ninputss                   r$   "test_BlockMatrix_Inverse_executionrS    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                     SSK Jn   [        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[        5      (       d   e[        UR                  R                  U 5      (       a  M   e   g )Nr   )Jointheta)aesara.tensor.basicrU  r   r   r   ImmutableMatrixr   r   r%   rN   r   r   r   )rU  r   
MatrixTyperd   tXs        r$   test_DenseMatrixr[    s    (
		'Ayy""4"45
RVVAYJ/"&&)RVVAY1GHI!_"n----"((++t,,,,	 6r8   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   rd   r   r   r  N)	r   r   r   rd   r'  rI  r   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 r8   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.aesaracodera  rE  clearr   rd   r   r   r   update)ra  backupr   r^  s       r$   test_global_cacherf    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.
r   r   r  N)r   r   r'  r   r%   valuesr   setr-   iditemsr   r   )symbolsr    printedr   r^  s        r$   test_cache_types_distinctrn    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%   rQ   r`   r   s     r$   test_symbols_are_created_oncerq  (  sV    
 66!Q'DDb2gD"|A./////r8   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%   ri  r   r.   r/   	ancestorsr   rN   Constantr   )r"   r   symbol_namesr   seenvs         r$   test_cache_complexry  3  s    
 6Q]bffQQY&777D$($5$56$5qFF$5L6$F 5D\\))6(377?:a1C1C1L1L#M#M66\)))66%%%HHQVV 4  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   r   switchr`   rQ   rL   nanAndOrand_or_)r"   resultr   s      r$   test_Piecewiser  K  st   <<AaC1ac(I6D$F<<??cjj(((zz"Q$3::bdB#:;H!!!!<<AE
#D$Fzz"q&"bff-H!!!!<<BFF1Q3!,-	
BEE!A#qsOD$Fzz#((2a41-q

3772a4A&BFF35H!!!!r8   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   )
rQ   r%   r   Eqr   r   r   eqr`   ra   ri   r8   r$   test_Relationalsr  a  s    RUU1a[)366"b>::::QU#R"W----QU#R"W----Q!V$bBh////Q!V$bBh////r8   c                     [         S[        S0n [        5          [        [         U S9[        [        U 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      -  U S9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  aesara.tensorr  r  rQ   conj)r   r`   ra   r  atvcplxs         r$   test_complexfunctionsr  j  s    a-F		!Qv.Af0MB 
">7-		!K)A,v>BGGIOOOOKq)2s3xCa8J/J+KLLLL 
"	! 
"	!
 
"	!s   CA<C0
C-0
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  v  s2    		!R' 
"4:: 
"	!s   /
=)h__doc__loggingsympy.externalr   sympy.testing.pytestr   r   r   sympy.utilities.exceptionsr   	getLoggeraesaraloggersetLevelCRITICALr   WARNINGr   rL   r   r   aesara.scalar.basicr	   aesara.graph.basicr
   aesara.tensor.varr   aesara.tensor.elemwiser   r   aesara.tensor.mathr   rb  r   r   r`   ra   rb   rc   re   rg   disabledsympyr   sympy.core.singletonr   	sympy.abcr   r   r   r   r   r   r   r'  rd   rf   rh   r   r   r%   r*   r7   rB   rQ   rj   rr   ru   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?  rS  r[  r_  rf  rn  rq  ry  r  r  r  r  )r   r   s   00r$   <module>r     sD    ( E E 6   !89   g&& '	x	    goo & 

--C.+0;&59>?#**T8,?JBBHMN1#**X~A*>NJBB H  "      .3
3U2??1a#U
31a 	kk#q+:4$"-`
%	. 4 4.
6 
\O)$,>=
9,)8

=
>LA")+VGT$:.A C C2-3.$$50	0 0",0	Mg @N 4s   .G,G1G6