
    gR                     D   d Z ddlZddlmZ ddlmZmZ ddlmZ  ej	        d          Z
e
                    ej                    ed          Ze
                    ej                   erRddlZej        ZddlmZ dd	lmZ dd
lmZ ddlmZmZ ddlmZ ddlm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m0Z0m1Z1m2Z2 d dD             \  Z3Z4Z5  e(j6        d          e/          Z7d Z8d Z9d Z:d Z;d Z<d Z=d Z>d Z?ed              Z@d! ZAd" ZBd# ZCd$ ZDd% ZEd& ZFd' ZGd( ZHd) ZId* ZJd+ ZKd, ZLd- ZMd. ZNd/ ZOd0 ZPd1 ZQd2 ZRd3 ZSd4 ZTd5 ZUd6 ZVd7 ZWd8 ZXd9 ZYed:             ZZd; Z[d< Z\d= Z]d> Z^d? Z_d@ Z`dA ZadB ZbdC ZcdD ZddS )Ea  
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)ignore_warningszaesara.configdefaultsaesara)
ScalarType)Variable)TensorVariable)Elemwise
DimShuffle)Dot)true_dividec                 D    g | ]}t                               |d           S )floatX)aetscalar).0names     `/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/printing/tests/test_aesaracode.py
<listcomp>r   #   s&    ???#**T8,,???    xyzc                 H    g | ]}t                               d d|           S )r   FFr   )r   tensorr   ns     r   r   r   $   s*    NNN1#**X~A*>>NNNr   XYZT)S)xyzt)aesara_codedim_handlingaesara_functionc                 :    g | ]}t          j        |d d           S )   syMatrixSymbolr   s     r   r   r   2   s&    
3
3
32?1a##
3
3
3r   fc                 H    |                     di            t          | fi |S )zB Wrapper for aesara_code that uses a new, empty cache by default. cache)
setdefaultr%   )exprkwargss     r   aesara_code_r3   8   s.    
gr"""t&&v&&&r   c                 J    |                     di            t          | |fi |S )zF Wrapper for aesara_function that uses a new, empty cache by default. r/   )r0   r'   )inputsoutputsr2   s      r   aesara_function_r7   =   s0    
gr"""6755f555r   c                  B   t          t          t          |                     }t          t          j        j                            |                    }t          j        j                            ||          \  }}t          j        j        	                    ||          S )z Transform SymPy expressions into Aesara Computation.

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

    Returns
    =======
    aesara.graph.fg.FunctionGraph
    )
listmapr3   r   graphbasicgraph_inputsclonefgFunctionGraph)exprsoutsinss      r   	fgraph_ofrD   C   ss     L%(())D
v|!..t44
5
5C"((d33IC<?((d333r   c                     t           j                                                            d          }|                                 } |j                            |            | S )z Simplify a Aesara Computation.

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

    Returns
    =======
    aesara.graph.fg.FunctionGraph
    fusion)r   compileget_default_mode	excludingr>   	optimizerrewrite)fgraphmodes     r   aesara_simplifyrN   U   sM     >**,,66x@@D\\^^FN6"""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 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tupler9   typer:   theqr   printing
debugprint	TypeError)rR   rS   numeric_typesa_is_numb_is_numa_is_seqb_is_seqastrbstrargnameargvalargstrs               r   r]   r]   f   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 Aesara
    equivalents, as many of the other tests depend on this.
    N)r]   xtr3   r!   ytr"   ztr#   XtXYtYZtZ r   r   test_example_symbolsrv      s    
 LOO$$$$$LOO$$$$$LOO$$$$$LOO$$$$$LOO$$$$$LOO$$$$$$$r   c                  &   t          t                    } t          | t                    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 aesara variable. ru   FbroadcastablesN)r3   r!   rZ   r	   broadcastabler   )xxxx2s     r   test_Symbolr~      s    	aBb(#####r!!!!7af
q!X
7
7
7C((((8qvr   c                  v    t          t                    } t          | t                    sJ | j        dk    sJ dS )z4 Test printing a MatrixSymbol to a aesara variable. r   N)r3   rp   rZ   r
   r{   )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. )ru   rx   TTFFT)TTry   N)r   
ValueErrorr3   rp   )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                    sJ | j        dk    sJ | j        dk    sJ dS )zG Test printing AppliedUndef instance, which works similarly to Symbol. ru   f_tN)r3   r   rZ   r
   r{   r   )ftts    r   test_AppliedUndefr      sR    
s

Cc>*****""""8ur   c                      t           t          z   } t          |           }|j        j        t
          j        j        k    sJ d S N)r!   r"   r3   owneropr   r   addr1   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   )r]   r3   r+   sinr!   r   rl   tanru   r   r   	test_trigr      sh    RVAYY''55555RVAYY''5555555r   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#   r3   r   rl   rm   rn   r]   )r1   r   expecteds      r   	test_manyr      s    6!Q$"##bfQqSkk1DDwwr1uswwr{{*++cggadmm;H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)r3   r!   r\   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. )ru   rx   r   r   r   ry   N)r!   r   r3   r{   )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. )ru   ru   ru   )rx   rx   rx   )r   rx   rx   )r   r   r   )r   r   r   ry   N)r!   r"   r3   r{   )r1   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                    sJ t          |t          
                    t                    
                    t                              sJ d S r   )rp   rr   rt   r3   rZ   r   r   r   r]   ro   dotrq   rs   )r1   expr_ts     r   test_MatMulr      sh    Q3q5D$Fflos+++++r

r**+++++++r   c                  v    t          t          t          j                  j        j        t                    sJ d S r   )rZ   r3   rp   Tr   r   r   ru   r   r   test_Transposer     s.    l13''-0*=======r   c                      t           t          z   t          z   } t          t	          |           j        j        t                    sJ d S r   )rp   rr   rt   rZ   r3   r   r   r   r1   s    r   test_MatAddr     s9    Q3q5Dl4((.18<<<<<<<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   )r]   r3   r+   Integerr   r    Halfru   r   r   test_Rationalsr     sg    RZ]]Q.//Q1B1BCCCCCQV$$k!Q&7&78888888r   c                  T    t          t          j        d                    dk    sJ d S )Nr   )r3   r+   r   ru   r   r   test_Integersr     s)    
1&&!++++++r   c                  t    t          j        d          } t          t          j        |                     sJ d S )Nr   )r+   Symbolr3   	factorial)r   s    r   test_factorialr     s1    
	#AQ(((((((r   c                     t          t                    5  d } t           | t          t	          j        t	          j        t                    t          d                               | t          	                    t                              t                    t                                        sJ 	 d d d            d S # 1 swxY w Y   d S )Nc                 :    t          t          |                     S r   )rN   rD   r   s    r   <lambda>z!test_Derivative.<locals>.<lambda>  s    OIdOO<< r   Fevaluate)r   UserWarningr]   r3   r+   
Derivativer   r!   r   gradr   rl   )simps    r   test_Derivativer     s    		%	% 8 8<<DDbmBF1IIq5&Q&Q&QRRSSDSWWR[["55668 8 	8 	8 	8 	88 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8s   B!CCCc                  ~    t          t          t          gt          t          z   g          }  | dd          dk    sJ dS )z, Test aesara_function() with single output. r   r      Nr7   r!   r"   )r-   s    r   test_aesara_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 aesara_function() with multiple outputs. r   r   r   Nr   )r-   o1o2s      r   test_aesara_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 aesara_function() vs Numpy implementation. r   r   )dimr   r   r   r)      &.>)r   r   N)	r7   r!   r"   rX   linalgnormasarrayarangeastype)r-   r|   yys      r   test_aesara_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#   rX   arrayr7   testingassert_allcloserZ   r\   )mr   r-   s      r   test_aesara_function_matrixr   7  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   rx   ry   )r&   r!   r"   ru   r   r   test_dim_handlingr   C  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 aesara_function() to aesara.function().
    r   Nr   ignorer   )r   on_unused_inputr   r   r   r)   r   r   )r   r   r   )
numpyr7   r!   r"   r#   r   r   r   r   r   )rX   r-   r|   r   zzs        r   test_aesara_function_kwargsr   I  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            	         ddl m}  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        |           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 TdS )	z2 Test the "scalar" argument to aesara_function(). r   )FunctionNr   r   r   )r   r   c                 ^    g | ]*}t          j        d  |j        j        D                       +S )c                     g | ]}|rd nd	S )r   r   ru   )r   r   s     r   r   z:test_aesara_function_scalar.<locals>.<listcomp>.<listcomp>q  s     GGGBbaGGGr   )rX   onesr\   r{   )r   is     r   r   z/test_aesara_function_scalar.<locals>.<listcomp>p  sF        GG!&2FGGGHH  r   )aesara.compile.function.typesr   r!   r"   rp   rr   r7   rZ   r'   input_storager9   lenziprX   rY   ndarrayndim)r   argsr5   r6   in_dimsout_dimsr   r-   	in_values
out_valuesdvalues               r   test_aesara_function_scalarr  Z  s   666666 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/::::: *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 aesara_function() should raise an
    exception.
    c                  D    t          t          gt          dz   gd          S )Nr   r   )foobar)r7   r!   ru   r   r   r   z0test_aesara_function_bad_kwarg.<locals>.<lambda>  s    /acU1EEE r   N)r   	Exceptionru   r   r   test_aesara_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)getattrr]   )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   )r3   slicer!   r"   rl   rm   )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                    	 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   Tintegerrp   r   r   r   r)   r   r   r/   r   r   c              3   N   K   | ]}j         j        |         j        |k    V   d S r   )r   r5   data)r   r   rq   s     r   	<genexpr>z#test_MatrixSlice.<locals>.<genexpr>  s4      AArxq!&!+AAAAAAr      kr   r   )r+   r   r,   r3   r   r[   r   r   idx_listr   r5   allrange)
r/   r   rp   rr   r   r*  r  r  r  rq   s
            @r   test_MatrixSlicer.    sZ   E
	#t$$$A
Q""A	!Aa%1Q,A	au	%	%	%B7A%&&5Aq>>5Aq>>*JJJJJ8?1au!=!=!===== AAAAU1a[[AAAAAAAA
	#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 ru   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   )r]   )r   solutionBlockts     r   r(  z#test_BlockMatrix.<locals>.<genexpr>  s-      @@(tFH%%@@@@@@r   )r+   r   r:   r3   BlockMatrixr   joinany)ABCDAtBtCtDtBlock	solutionsr4  r   s             @@r   test_BlockMatrixrB    s   
	#t$$$AAAAA&AAAJAq!Q1a|44NBBNQFQF+,,E%  F!SXXaR00#((1b"2E2EFF!SXXaR00#((1b"2E2EFFH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   r8  r9  r   c                 @    g | ]}t          j        |g|         R  S ru   )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 ru   )rX   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  r7   block_collapserX   r   reshaperJ  r   eyer   allclose)r*  r   r8  r9  r5   output	cutinputs	cutoutputr   r-   fblockedninputsrF  r   s               @@r   "test_BlockMatrix_Inverse_executionrX    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                     ddl m}  t          j        d          }t          j        t          j        fD ]} |t          j        |          t          j        |           gt          j        |          t          j        |          gg          }t          |          }t          |t                    sJ t          |j        j        |           sJ d S )Nr   )Jointheta)aesara.tensor.basicrZ  r+   r   r   ImmutableMatrixr   r   r3   rZ   r
   r   r   )rZ  r$   
MatrixTyperp   tXs        r   test_DenseMatrixr`    s    ((((((
	'Ay""45 - -
JRVAYYJ/"&))RVAYY1GHII!__"n-----"(+t,,,,,,	- -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!   rp   r-   r$   r%  N)	r!   r+   r   rp   r,   rJ  r   r   r3   )pairsr  r  r/   sts        r   test_cache_basicrd    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                  ,   ddl m}  t          |           }	 |                                  t          t
          t          fD ]$}t          |          }t          |          |u sJ %	 |                     |           dS # |                     |           w xY w)z Test use of the global cache. r   )global_cacheN)	sympy.printing.aesaracoderf  rN  clearr!   rp   r   r%   update)rf  backupr   rc  s       r   test_global_cacherk    s    666666,F
$Q 	( 	(AQBq>>R'''''	( 	F#####F####s   AA< <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 ]\  }}t          ||          |u sJ d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   r3   valuesr  setr:   iditemsr%   )symbolsr/   printedr   rc  s        r   test_cache_types_distinctrs    s     y1!=!=sCGEG  !5)))))))))

 s3r7>>++,,--..#g,,>>>>  1 121E***b000001 1r   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!   r3   r]   rl   r   s     r   test_symbols_are_created_oncerv  $  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 ru   r   )r   r   s     r   	<setcomp>z%test_cache_complex.<locals>.<setcomp>5  s    666qAF666r   N)r!   r"   r+   r   r   r#   free_symbolsr3   rn  r   r;   r<   	ancestorsr   rZ   Constantr   r   )r1   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\))6(33  7?:a1C1L#M#M?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!   r3   r   r   r   switchrl   r]   rX   nanAndOrand_or_)r1   resultr   s      r   test_Piecewiser  G  s   <AaC1ac(I66D$F<?cj((((zz"Q$3::bdB#:#:;;H!!!!!<AE
##D$Fzz"q&"bf--H!!!!!<BF1Q3!,,-	
BE!A#qsOO D$Fzz#((2a41--q

3772a4A&&BF335 5H!!!!!!!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   )
r]   r3   r+   Eqr!   r"   r   eqrl   rm   ru   r   r   test_Relationalsr  ]  s    RU1a[[))366"b>>:::::QU##R"W-----QU##R"W-----Q!V$$bBh/////Q!V$$bBh///////r   c            
         t           dt          di} t          t           |           t          t          |           }}ddlm} ddlm} ddlm} t          t          t           |t                     z  |           ||	                                z            sJ t          t          dt           z            | |d           |d	           |dd
          z  z   z            sJ d S )N
complex128r   r   )	conjugate)as_tensor_variable)complexy      ?       @r   r   r   )
r!   r"   r%   $sympy.functions.elementary.complexesr  aesara.tensorr  r  r]   conj)r   rl   rm   r  atvcplxs         r   test_complexfunctionsr  f  s    a-F6***K&,I,I,IB>>>>>>777777------AiillN6:::B		NKKKKKT1H%%r33s88CCHHTT!AYY4F+F'GHHHHHHHr   c                  H    t          g dg          }  |             dk    sJ d S )Ny      ?      ?)r'   )tfs    r   test_constantfunctionsr  p  s*    	TF	#	#B244::::::r   )e__doc__loggingsympy.externalr   sympy.testing.pytestr   r   sympy.utilities.exceptionsr   	getLoggeraesaraloggersetLevelCRITICALr   WARNINGr   rX   r   r   aesara.scalar.basicr   aesara.graph.basicr	   aesara.tensor.varr
   aesara.tensor.elemwiser   r   aesara.tensor.mathr   rg  r   rl   rm   rn   ro   rq   rs   disabledsympyr+   sympy.core.singletonr    	sympy.abcr!   r"   r#   r$   r%   r&   r'   rp   rr   rt   r   r   r3   r7   rD   rN   r]   rv   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r!  r.  rB  rX  r`  rd  rk  rs  rv  r  r  r  r  r  ru   r   r   <module>r     s     ( ( ( ( ( ( - - - - - - - - 6 6 6 6 6 6 !w !899   g& ' ' '	x	 	    go & & & 
 
-C......++++++000000;;;;;;;;&&&&&&555555?????JBBNNNNNJBBB H     " " " " " "                                  4
3U
3
3
31a kbk#q' ' '
6 6 64 4 4$  "- - -`
% 
% 
%	 	 	. . . 4 4 4  . . .
6 6 6     
\ 
\ 
\O O O) ) )$, , ,> > >= = =
9 9 9, , ,) ) )8 8 8  
  
= 
= 
=
> 
> 
>L L LA A A")+ )+ )+VG G GT T T$: : :.A A A C C C2- - -3 3 3.$ $ $"1 1 1.	0 	0 	0     0" " ",0 0 0I I I    r   