a
    {d>                     @   sB  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lmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d d	lmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% d d
l&m'Z'm(Z( d dl)m*Z*m+Z+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1 d dl2m3Z3 d dl4m5Z5m6Z6 d dl7m8Z8m9Z9 d dl:m;Z;m<Z< d dl=m>Z>m?Z?m@Z@mAZAmBZB d dlCmDZD d dlEmFZF ed\ZGZHZIe;dZJdd ZKdd ZLdd ZMdd ZNdd ZOd d! ZPd"d# ZQd$d% ZRd&d' ZSd(d) ZTG d*d+ d+eZUd,d- ZVd.d/ ZWd0d1 ZXd2d3 ZYd4d5 ZZd6d7 Z[d8d9 Z\d:d; Z]d<d= Z^d>d? Z_d@dA Z`dBdC ZadDS )E    )
Assignment)none)expm1log1p)cosm1)MatrixSolve)
ExprModsymbolsEqLeGtzooooRationalPow)pi)S)acosKroneckerDelta	PiecewisesignsqrtMinMaxcotacschaseccoth)AndOr)SparseMatrixMatrixSymbolIdentity)MpmathPrinterPythonCodePrinterpycodeSymPyPrinter)TensorflowPrinter)NumPyPrinterSciPyPrinter)raisesskip)IndexedBaseIdx)ArraySymbolArrayDiagonalArrayContraction	ZeroArrayOneArray)import_module)loggammazx y zpc                  C   s  t  } | jrJ | tt dks&J | ttddks>J | ttt dksXJ | tt tdksrJ | tttdksJ | tttdksJ | dtt  d	ksJ | jrJ | td
ksJ | jddhiksJ | tt	dd dks
J | t
tdks"J | jdddhiks:J | ttdksRJ | ttdksjJ | ttdksJ | ttdksJ | ttdksJ | ttddksJ | tdttdfdtdkfdksJ | tdttdfdttdfdddks*J | ttdksBJ | td dksZJ | tttdkstJ | d d!ksJ | ddgd"ksJ | tttd#ksJ | tttd$ksJ d S )%Nzx**y   zx % 2z-(x % y)z(-x) % yzx and yzx or y   z	1/(x + y)zmath.pimathr   math.sqrt(x)r   zmath.acos(x)z1/math.tan(x)z9(math.exp(x) + math.exp(-x))/(math.exp(x) - math.exp(-x))zmath.acos(1/x)z&math.log(math.sqrt(1 + x**(-2)) + 1/x)zx = 2r      z/((1) if (x == 0) else (2) if (x > 6) else None)   Fevaluatez/((2) if (x <= 0) else (3) if (x > 0) else None)z((0.0 if x == 0 else math.copysign(1, x))r   r8   zp[0, 1]z(1 if x == y else 0)r7   r<   z(2, 3)z[2, 3]z	min(x, y)z	max(x, y))r%   module_importsdoprintxyr	   r   r    r   r   r   r   r   r   r   r   r   r   r   r   r   r   r6   r   r   r   prntr rG   i/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/sympy/printing/tests/test_pycode.pytest_PythonCodePrinter   sL    




rI   c                  C   s&   t  } | jdksJ ttdd  d S )Npython3c                   S   s   t ddiS )NstandardZpython4)r%   rG   rG   rG   rH   <lambda>M       z1test_PythonCodePrinter_standard.<locals>.<lambda>)r%   rK   r+   
ValueErrorrE   rG   rG   rH   test_PythonCodePrinter_standardH   s    rO   c                  C   s   t  } | ttdksJ | tdddks4J | tjdksHJ | tjdks\J | tjdkspJ | tj	dksJ | tj
d	ksJ | tjd
ksJ | tjdksJ | ttdksJ d S )Nzmpmath.sign(x)r8   r7   zmpmath.mpf(1)/mpmath.mpf(2)zmpmath.ez	mpmath.piz
mpmath.phizmpmath.eulerz
mpmath.nanz
mpmath.infzmpmath.ninfzmpmath.loggamma(x))r$   rB   r   rC   r   r   Exp1PiGoldenRatio
EulerGammaNaNInfinityNegativeInfinityr5   )r6   rG   rG   rH   test_MpmathPrinterP   s    rW   c               	   C   s  ddl m}  ddlm} ddlm}m}m} ddlm	} ddl
m} ddlm} ddlm}m}	 dd	lm}
m} t }|ttd
ksJ tddd}tddd}tddd}tddd}||d dksJ ||d dksJ |tddksJ tddd}tddd}|t||dks0J |t||| dksNJ ||	dddkshJ ||dddksJ ||dd| |
|f|
| dksJ ||||dksJ ||||d ksJ |||d!ksJ |||d"ksJ |||d#ks(J |||d$ks@J |td d%ksXJ |td& d'kspJ tddd(d)}||d*ksJ |tjd+ksJ |tjd,ksJ |tjd-ksJ |tj d.ksJ |tj!d/ks J |tj"d0ksJ d S )1Nr   )Lambda)Adjoint)
DiagMatrixDiagonalMatrix
DiagonalOf)FunctionMatrix)HadamardProduct)KroneckerProduct)	OneMatrix
ZeroMatrix)abznumpy.sign(x)Ar7   BCr8      Dr<      znumpy.linalg.inv(A)znumpy.linalg.matrix_power(A, 5)znumpy.eye(3)rC   rD   znumpy.linalg.solve(A, x)znumpy.linalg.solve(A, x) + yznumpy.zeros((2, 3))znumpy.ones((2, 3))z.numpy.fromfunction(lambda a, b: a + b, (4, 5))znumpy.multiply(A, B)znumpy.kron(A, B)z#numpy.conjugate(numpy.transpose(A))z%numpy.reshape(numpy.diag(A), (-1, 1))znumpy.diagflat(C)z"numpy.multiply(D, numpy.eye(3, 4))z	x**(-1.0)z	x**(-2.0)Fr=   z	2**(-1.0)numpy.eznumpy.piznumpy.euler_gammaz	numpy.nanz
numpy.PINFz
numpy.NINF)#Zsympy.core.functionrX   Z"sympy.matrices.expressions.adjointrY   Z#sympy.matrices.expressions.diagonalrZ   r[   r\   Z%sympy.matrices.expressions.funcmatrixr]   Z#sympy.matrices.expressions.hadamardr^   Z$sympy.matrices.expressions.kroneckerr_   Z"sympy.matrices.expressions.specialr`   ra   Z	sympy.abcrb   rc   r)   rB   r   rC   r"   r#   r   r   r   rP   rQ   rS   rT   rU   rV   )rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   r6   rd   re   rf   rh   uvexprrG   rG   rH   test_NumPyPrinter_   sT    
rp   c                  C   s   t d} | std ddlm}m} ddlm} |dt d td d	t d }|t|d}|| dddg d
k	 s~J |ddksJ |td td }|t|d}|| dddg dk	 sJ |ddksJ d S )Nnumpyznumpy not installed.r   )r   r   )lambdifyg?r<   r8   g      ?)g      ?g      ?g      @ri   r7   rj   )r8   r   r8      @   )
r4   r,   Z(sympy.functions.elementary.miscellaneousr   r   Zsympy.utilities.lambdifyrr   rC   Zlinspaceall)rq   r   r   rr   expr1funcrG   rG   rH   test_issue_18770   s     ""rx   c                  C   s   t  } tt}d| jvsJ | |dks.J d| jv s<J tdd | jD rTJ tddddi}| |d	ksvJ d
| jv sJ | tjdksJ | tj	dksJ | tj
dksJ d S )Nrq   znumpy.arccos(x)c                 s   s   | ]}| d V  qdS )ZscipyN)
startswith).0mrG   rG   rH   	<genexpr>   rM   z$test_SciPyPrinter.<locals>.<genexpr>r7   rg   r?   r<   z8scipy.sparse.coo_matrix(([3], ([0], [1])), shape=(2, 5))zscipy.sparsezscipy.constants.golden_ratiozscipy.constants.pirl   )r*   r   rC   rA   rB   anyr!   r   rR   rQ   rP   )r6   ro   ZsmatrG   rG   rH   test_SciPyPrinter   s    r~   c                     s<   t d\ tt fdd t  } | dv s8J d S )Nzif elsec                      s   t   ddS )NT)Zerror_on_reserved)r&   rG   s1s2rG   rH   rL      rM   z,test_pycode_reserved_words.<locals>.<lambda>)zelse_ + if_zif_ + else_)r
   r+   rN   r&   )Zpy_strrG   r   rH   test_pycode_reserved_words   s    r   c                  C   sB   t d\} }}| | }t|dks&J || }t|dks>J d S )Nza_{b} b a_{11}za_b*bza_11*b)r
   r&   )Za_brc   Za_11ro   rG   rG   rH   test_issue_20762   s
    r   c                  C   sv  t  } | jttdddks J | jdtt dddks>J t ddi} | jttddd	ksdJ | jdtt ddd
ksJ t } | jttdddksJ | jttdddksJ t } | jttdddksJ | jttddd	ksJ t } | jttdddksJ | jttddd	ks4J t } | jttdddksVJ | jttddd	ksrJ d S )NF)Zrationalr:   r8   z1/math.sqrt(x)rK   rJ   Tzx**(1/2)z	x**(-1/2)zmpmath.sqrt(x)z x**(mpmath.mpf(1)/mpmath.mpf(2))znumpy.sqrt(x)zsympy.sqrt(x))r%   Z
_print_Powr   rC   r$   r)   r*   r'   rE   rG   rG   rH   	test_sqrt   s(    r   c                  C   s   ddl m}  | t}t }||dks,J t }||dksDJ t }||dks\J t }||dkstJ t }||dksJ d S )Nr   )fracznumpy.mod(x, 1)zx % 1zmpmath.frac(x)z+sympy.functions.elementary.integers.frac(x))	Z#sympy.functions.elementary.integersr   rC   r)   rB   r*   r%   r$   r'   )r   ro   rF   rG   rG   rH   	test_frac   s    r   c                   @   s   e Zd Zdd Zdd ZdS )CustomPrintedObjectc                 C   s   dS )Nrq   rG   selfprinterrG   rG   rH   
_numpycode   s    zCustomPrintedObject._numpycodec                 C   s   dS )NmpmathrG   r   rG   rG   rH   _mpmathcode   s    zCustomPrintedObject._mpmathcodeN)__name__
__module____qualname__r   r   rG   rG   rG   rH   r      s   r   c                  C   s2   t  } t | dksJ t | dks.J d S )Nrq   r   )r   r)   rB   r$   )objrG   rG   rH   test_printmethod   s    r   c                   C   s   t tdksJ d S )NNone)r&   r   rG   rG   rG   rH   test_codegen_ast_nodes  s    r   c                  C   s0   t  } | tdksJ | t dks,J d S )Nzmath.nanzfloat('-inf'))r%   rB   r   r   rE   rG   rG   rH   test_issue_14283  s    r   c                  C   s    t  } | tddksJ d S )Nr7   z(0, 1,))r)   Z
_print_seqrange)nrG   rG   rH   test_NumPyPrinter_print_seq  s    r   c                  C   s   ddl m} m} td}| |t}||t}t }||dksDJ ||dksVJ t }d||v snJ d||v sJ t }d||v sJ d||v sJ d S )Nr   )
lowergamma
uppergammarb   z3scipy.special.gamma(a)*scipy.special.gammainc(a, x)z4scipy.special.gamma(a)*scipy.special.gammaincc(a, x)Not supported)	'sympy.functions.special.gamma_functionsr   r   r
   rC   r*   rB   r)   r%   )r   r   rb   rv   expr2rF   rG   rG   rH   test_issue_16535_16536  s    

r   c                     s   ddl m}  ddlm} || t tdtf}|td | tt  tt tftdtf}|td t|td tdf t 	|dksJ 	|dksJ t
tfdd	 t
t fd
d	 t 	|dksJ 	|dksJ t
tfdd	 t
t fdd	 d S )Nr   )exp)Integralr7   r8   z?scipy.integrate.quad(lambda x: numpy.exp(-x), 0, numpy.PINF)[0]zMscipy.integrate.nquad(lambda x, y: x**2*numpy.exp(x*y), ((-z, z), (0, z)))[0]c                      s
     S NrB   rG   
indefiniterF   rG   rH   rL   3  rM   ztest_Integral.<locals>.<lambda>c                      s
     S r   r   rG   
evaluateatrF   rG   rH   rL   4  rM   z6mpmath.quad(lambda x: mpmath.exp(-x), (0, mpmath.inf))z?mpmath.quad(lambda x, y: x**2*mpmath.exp(x*y), (-z, z), (0, z))c                      s
     S r   r   rG   r   rG   rH   rL   9  rM   c                      s
     S r   r   rG   r   rG   rH   rL   :  rM   )Z&sympy.functions.elementary.exponentialr   Zsympy.integrals.integralsr   rC   r   rD   zr*   rB   r+   NotImplementedErrorr$   )r   r   singledoublerG   )r   r   rF   rH   test_Integral'  s     *r   c                  C   s   ddl m} m} | t}|t}t }||dks8J ||dksJJ t }d||v sbJ d||v stJ t }d||v sJ d||v sJ t }||dksJ ||dksJ d S )Nr   )fresnelcfresnelszscipy.special.fresnel(x)[1]zscipy.special.fresnel(x)[0]r   zmpmath.fresnelc(x)zmpmath.fresnels(x))	Z'sympy.functions.special.error_functionsr   r   rC   r*   rB   r)   r%   r$   )r   r   rv   r   rF   rG   rG   rH   test_fresnel_integrals=  s    r   c                  C   s   ddl m}  | tt}t }||dks.J t }||dksFJ t }||dks^J tddi}||dks|J t }||dksJ d S )Nr   )betazscipy.special.beta(x, y)z-math.gamma(x)*math.gamma(y)/math.gamma(x + y)Zallow_unknown_functionsTzmpmath.beta(x, y))	Z&sympy.functions.special.beta_functionsr   rC   rD   r*   rB   r)   r%   r$   )r   ro   rF   rG   rG   rH   	test_betaT  s    
r   c                  C   s   ddl m} m} | t}|t}t }||dks8J ||dksJJ t }d||v sbJ d||v stJ t }d||v sJ d||v sJ d S )Nr   )airyaiairybizscipy.special.airy(x)[0]zscipy.special.airy(x)[2]r   )sympy.functions.special.besselr   r   rC   r*   rB   r)   r%   )r   r   rv   r   rF   rG   rG   rH   	test_airyh  s    r   c                  C   s   ddl m} m} | t}|t}t }||dks8J ||dksJJ t }d||v sbJ d||v stJ t }d||v sJ d||v sJ d S )Nr   )airyaiprimeairybiprimezscipy.special.airy(x)[1]zscipy.special.airy(x)[3]r   )r   r   r   rC   r*   rB   r)   r%   )r   r   rv   r   rF   rG   rG   rH   test_airy_primez  s    r   c                  C   sL   t  } | ttdksJ | ttdks2J | ttdksHJ d S )Nznumpy.expm1(x)znumpy.log1p(x)zscipy.special.cosm1(x))r*   rB   r   rC   r   r   rE   rG   rG   rH   !test_numerical_accuracy_functions  s    r   c                  C   s  t dd} td}tddtddtdd	  }}}t }|td
dksPJ |td
dksfJ |t| ddgdksJ ||dksJ |t| g ddksJ |t| ddgddgdksJ |t| dgdgdksJ |t	||||f ||||f dksJ t
 }|td
dks<J |td
dksTJ |t| ddgdksrJ ||dksJ |t| g ddksJ |t| ddgddgdksJ |t| dgdgdksJ |t	||||f ||||f dksJ d S )Nrd   )ri   ri   r;   r;   r;   Iir?   jr@   k)ri   rg   rg   znumpy.zeros((5,))znumpy.ones((5,))r7   r<   znumpy.einsum("abccd->abd", A))r7   r<   ri   znumpy.einsum("abccc->abc", A)r   r8   znumpy.einsum("aabbc->cab", A)znumpy.einsum("abcde->abe", A)zI = Iztensorflow.zeros((5,))ztensorflow.ones((5,))z)tensorflow.linalg.einsum("abccd->abd", A)z)tensorflow.linalg.einsum("abccc->abc", A)z)tensorflow.linalg.einsum("aabbc->cab", A)z)tensorflow.linalg.einsum("abcde->abe", A))r/   r-   r.   r)   rB   r2   r3   r1   r0   r   r(   )rd   r   r   r   r   rF   rG   rG   rH   test_array_printer  s*    
"".$ r   N)bZsympy.codegenr   Zsympy.codegen.astr   Zsympy.codegen.cfunctionsr   r   Zsympy.codegen.scipy_nodesr   Zsympy.codegen.matrix_nodesr   Z
sympy.corer   r	   r
   r   r   r   r   r   r   r   Zsympy.core.numbersr   Zsympy.core.singletonr   Zsympy.functionsr   r   r   r   r   r   r   r   r   r   r   Zsympy.logicr   r    Zsympy.matricesr!   r"   r#   Zsympy.printing.pycoder$   r%   r&   r'   Zsympy.printing.tensorflowr(   Zsympy.printing.numpyr)   r*   Zsympy.testing.pytestr+   r,   Zsympy.tensorr-   r.   Z0sympy.tensor.array.expressions.array_expressionsr/   r0   r1   r2   r3   Zsympy.externalr4   r   r5   rC   rD   r   r6   rI   rO   rW   rp   rx   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rG   rG   rG   rH   <module>   sV   04,2	