U
    L?h>                     @   sF  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%m&Z& d d
l'm(Z(m)Z) d dl*m+Z+m,Z,m-Z- d dl.m/Z/m0Z0m1Z1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7 d dl8m9Z9m:Z: d dl;m<Z<m=Z= d dl>m?Z?m@Z@mAZAmBZBmCZC d dlDmEZE d dlFmGZG ed\ZHZIZJe<dZKdd ZLdd ZMdd ZNdd ZOdd ZPd d! ZQd"d# ZRd$d% ZSd&d' ZTd(d) ZUG d*d+ d+eZVd,d- ZWd.d/ ZXd0d1 ZYd2d3 ZZd4d5 Z[d6d7 Z\d8d9 Z]d:d; Z^d<d= Z_d>d? Z`d@dA ZadBdC ZbdDS )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sec)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t| tt dks&t| ttddks>t| ttt dksXt| tt tdksrt| tttdkst| tttdkst| dtt  d	kst| jrt| t	d
kst| jddhikst| tt
dd dks
t| ttdks"t| jdddhiks:t| ttdksRt| ttdksjt| ttdkst| ttdkst| ttdkst| ttddkst| tdttdfdtdkfdkst| tdttdfdttdfdddks*t| ttdksBt| td dksZt| tttdkstt| d d!kst| ddgd"kst| tttd#kst| tttd$kst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))z;((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   r9   zp[0, 1]z(1 if x == y else 0)r8   r=   z(2, 3)z[2, 3]z	min(x, y)z	max(x, y))r&   module_importsAssertionErrordoprintxyr	   r    r!   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r7   r   r   r   prntr rI   R/var/www/html/venv/lib/python3.8/site-packages/sympy/printing/tests/test_pycode.pytest_PythonCodePrinter   sN    



 
rK   c                  C   s&   t  } | jdkstttdd  d S )Npython3c                   S   s   t ddiS )NstandardZpython4)r&   rI   rI   rI   rJ   <lambda>M       z1test_PythonCodePrinter_standard.<locals>.<lambda>)r&   rM   rC   r,   
ValueErrorrG   rI   rI   rJ   test_PythonCodePrinter_standardH   s    rQ   c                  C   s   t  } | ttdkst| tdddks4t| tjdksHt| tjdks\t| tj	dkspt| tj
dkst| tjd	kst| tjd
kst| tjdkst| ttdkstd S )Nzmpmath.sign(x)r9   r8   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%   rD   r   rE   rC   r   r   Exp1PiGoldenRatio
EulerGammaNaNInfinityNegativeInfinityr6   )r7   rI   rI   rJ   test_MpmathPrinterP   s    rY   c               	   C   s6  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sttddd}tddd}tddd}tddd}||d dkst||d dkst|tddksttddd}tddd}|t||dks0t|t||| dksNt||	dddksht||dddkst||dd| |
|f|
| dkst||||dkst||||d kst|||d!kst|||d"kst|||d#ks(t|||d$ks@t|td d%ksXt|td& d'kspttddd(d)}||d*kst|tjd+kst|tjd,kst|tj d-kst|tj!d.kst|tj"d/ks t|tj#d0kst|t$td d1ks2td S )2Nr   )Lambda)Adjoint)
DiagMatrixDiagonalMatrix
DiagonalOf)FunctionMatrix)HadamardProduct)KroneckerProduct)	OneMatrix
ZeroMatrix)abznumpy.sign(x)Ar8   BCr9      Dr=      znumpy.linalg.inv(A)znumpy.linalg.matrix_power(A, 5)znumpy.eye(3)rE   rF   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.infz
-numpy.infz(numpy.cos(x)**(-1.0))**2)%Zsympy.core.functionrZ   Z"sympy.matrices.expressions.adjointr[   Z#sympy.matrices.expressions.diagonalr\   r]   r^   Z%sympy.matrices.expressions.funcmatrixr_   Z#sympy.matrices.expressions.hadamardr`   Z$sympy.matrices.expressions.kroneckerra   Z"sympy.matrices.expressions.specialrb   rc   Z	sympy.abcrd   re   r*   rD   r   rE   rC   r#   r$   r   r   r   rR   rS   rU   rV   rW   rX   r   )rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   r7   rf   rg   rh   rj   uvexprrI   rI   rJ   test_NumPyPrinter_   sV    
rr   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d
ddgk	 st
|ddkst
|td td }|t|d}|| dddddddgk	 st
|ddkst
d S )Nnumpyznumpy not installed.r   )r   r   )lambdifyg?r=   r9   g      ?g      ?g      ?g      @rk   r8   rl      @   )r5   r-   Z(sympy.functions.elementary.miscellaneousr   r   Zsympy.utilities.lambdifyrt   rE   ZlinspaceallrC   )rs   r   r   rt   expr1funcrI   rI   rJ   test_issue_18770   s     $&rz   c                  C   s   t  } tt}d| jkst| |dks.td| jks<ttdd | jD rTttddddi}| |d	ksvtd
| jkst| tj	dkst| tj
dkst| tjdkstd S )Nrs   znumpy.arccos(x)c                 s   s   | ]}| d V  qdS )ZscipyN)
startswith).0mrI   rI   rJ   	<genexpr>   s     z$test_SciPyPrinter.<locals>.<genexpr>r8   ri   r@   r=   z8scipy.sparse.coo_matrix(([3], ([0], [1])), shape=(2, 5))zscipy.sparsezscipy.constants.golden_ratiozscipy.constants.pirn   )r+   r   rE   rB   rC   rD   anyr"   r   rT   rS   rR   )r7   rq   ZsmatrI   rI   rJ   test_SciPyPrinter   s    r   c                     s<   t d\ tt fdd t  } | dks8td S )Nzif elsec                      s   t   ddS )NT)Zerror_on_reserved)r'   rI   s1s2rI   rJ   rN      rO   z,test_pycode_reserved_words.<locals>.<lambda>)zelse_ + if_zif_ + else_)r
   r,   rP   r'   rC   )Zpy_strrI   r   rJ   test_pycode_reserved_words   s    r   c                  C   sB   t d\} }}| | }t|dks&t|| }t|dks>td S )Nza_{b} b a_{11}za_b*bza_11*b)r
   r'   rC   )Za_bre   Za_11rq   rI   rI   rJ   test_issue_20762   s
    r   c                  C   sv  t  } | jttdddks t| jdtt dddks>tt ddi} | jttddd	ksdt| jdtt ddd
kstt } | jttdddkst| jttdddkstt } | jttdddkst| jttddd	kstt } | jttdddkst| jttddd	ks4tt } | jttdddksVt| jttddd	ksrtd S )NF)Zrationalr;   r9   z1/math.sqrt(x)rM   rL   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   rE   rC   r%   r*   r+   r(   rG   rI   rI   rJ   	test_sqrt   s(    r   c                  C   s   ddl m}  | t}t }||dks,tt }||dksDtt }||dks\tt }||dksttt	 }||dkst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   rE   r*   rD   rC   r+   r&   r%   r(   )r   rq   rH   rI   rI   rJ   	test_frac   s    r   c                   @   s   e Zd Zdd Zdd ZdS )CustomPrintedObjectc                 C   s   dS )Nrs   rI   selfprinterrI   rI   rJ   
_numpycode   s    zCustomPrintedObject._numpycodec                 C   s   dS )NmpmathrI   r   rI   rI   rJ   _mpmathcode   s    zCustomPrintedObject._mpmathcodeN)__name__
__module____qualname__r   r   rI   rI   rI   rJ   r      s   r   c                  C   s2   t  } t | dkstt | dks.td S )Nrs   r   )r   r*   rD   rC   r%   )objrI   rI   rJ   test_printmethod   s    r   c                   C   s   t tdkstd S )NNone)r'   r   rC   rI   rI   rI   rJ   test_codegen_ast_nodes  s    r   c                  C   s0   t  } | tdkst| t dks,td S )Nzmath.nanzfloat('-inf'))r&   rD   r   rC   r   rG   rI   rI   rJ   test_issue_14283	  s    r   c                  C   s    t  } | tddkstd S )Nr8   z(0, 1,))r*   Z
_print_seqrangerC   )nrI   rI   rJ   test_NumPyPrinter_print_seq  s    r   c            	   
   C   s   ddl m} m} td}| |t}||t}t }||dksDt||dksVtt }t	ddi}||fD ]4}t
t || W 5 Q R X d||ksptqpd S )	Nr   )
lowergamma
uppergammard   z3scipy.special.gamma(a)*scipy.special.gammainc(a, x)z4scipy.special.gamma(a)*scipy.special.gammaincc(a, x)strictFNot supported)'sympy.functions.special.gamma_functionsr   r   r
   rE   r+   rD   rC   r*   r&   r,   NotImplementedError)	r   r   rd   rx   expr2rH   p_numpyp_pycoderq   rI   rI   rJ   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st
	|dkst
ttfdd	 tt fd
d	 t 	|dkst
	|dkst
ttfdd	 tt fdd	 d S )Nr   )exp)Integralr8   r9   z>scipy.integrate.quad(lambda x: numpy.exp(-x), 0, numpy.inf)[0]zMscipy.integrate.nquad(lambda x, y: x**2*numpy.exp(x*y), ((-z, z), (0, z)))[0]c                      s
     S NrD   rI   
indefiniterH   rI   rJ   rN   6  rO   ztest_Integral.<locals>.<lambda>c                      s
     S r   r   rI   
evaluateatrH   rI   rJ   rN   7  rO   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   rI   r   rI   rJ   rN   <  rO   c                      s
     S r   r   rI   r   rI   rJ   rN   =  rO   )Z&sympy.functions.elementary.exponentialr   Zsympy.integrals.integralsr   rE   r   rF   zr+   rD   rC   r,   r   r%   )r   r   ZsingledoublerI   )r   r   rH   rJ   test_Integral*  s     *r   c            	   
   C   s   ddl m} m} | t}|t}t }||dks8t||dksJtt }t }t	 }||fD ]@}t
t || W 5 Q R X t
t || W 5 Q R X qd||dkst||dkstd S )Nr   )fresnelcfresnelszscipy.special.fresnel(x)[1]zscipy.special.fresnel(x)[0]zmpmath.fresnelc(x)zmpmath.fresnels(x))Z'sympy.functions.special.error_functionsr   r   rE   r+   rD   rC   r*   r&   r%   r,   r   )	r   r   rx   r   rH   r   r   Zp_mpmathrq   rI   rI   rJ   test_fresnel_integrals@  s     

r   c                  C   s   ddl m}  | tt}t }||dks.tt }||dksFtt }||dks^ttddi}||dks|tt	 }||dkst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   rE   rF   r+   rD   rC   r*   r&   r%   )r   rq   rH   rI   rI   rJ   	test_betaW  s    
r   c                  C   s   ddl m} m} | t}|t}t }||dks8t||dksJttddi}d||kshtd||kszttddi}d||kstd||kstd S )Nr   )airyaiairybizscipy.special.airy(x)[0]zscipy.special.airy(x)[2]r   Fr   )	sympy.functions.special.besselr   r   rE   r+   rD   rC   r*   r&   )r   r   rx   r   rH   rI   rI   rJ   	test_airyk  s    r   c                  C   s   ddl m} m} | t}|t}t }||dks8t||dksJttddi}d||kshtd||kszttddi}d||kstd||kstd S )Nr   )airyaiprimeairybiprimezscipy.special.airy(x)[1]zscipy.special.airy(x)[3]r   Fr   )	r   r   r   rE   r+   rD   rC   r*   r&   )r   r   rx   r   rH   rI   rI   rJ   test_airy_prime}  s    r   c                  C   sL   t  } | ttdkst| ttdks2t| ttdksHtd S )Nznumpy.expm1(x)znumpy.log1p(x)zscipy.special.cosm1(x))r+   rD   r   rE   rC   r   r   rG   rI   rI   rJ   !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sPt|td
dksft|t| ddgdkst||dkst|t	| dddgdkst|t	| ddgddgdkst|t| dgdgdkst|t
||||f ||||f dks tt }|td
dks>t|td
dksVt|t| ddgdkstt||dkst|t	| dddgdkst|t	| ddgddgdkst|t| dgdgdkst|t
||||f ||||f dkstd S )Nrf   )rk   rk   r<   r<   r<   Iir@   jrA   k)rk   ri   ri   znumpy.zeros((5,))znumpy.ones((5,))r8   r=   znumpy.einsum("abccd->abd", A)rk   znumpy.einsum("abccc->abc", A)r   r9   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))r0   r.   r/   r*   rD   r3   rC   r4   r2   r1   r   r)   )rf   r   r   r   r   rH   rI   rI   rJ   test_array_printer  s*    
"". $ r   N)cZ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   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_expressionsr0   r1   r2   r3   r4   Zsympy.externalr5   r   r6   rE   rF   r   r7   rK   rQ   rY   rr   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rI   rI   rI   rJ   <module>   sV   08,5	