o
    o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J | tt dksJ | ttddksJ | ttt dks,J | tt tdks9J | tttdksEJ | tttdksQJ | dtt  d	ks^J | jrcJ | td
kslJ | jddhiksvJ | tt	dd dksJ | t
tdksJ | jdddhiksJ | ttdksJ | ttdksJ | 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sJ | td dks#J | tttdks0J | d d!ks:J | ddgd"ksFJ | tttd#ksSJ | tttd$ks`J 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doprintxyr	   r    r!   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r7   r   r   r   prntr rH   t/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/printing/tests/test_pycode.pytest_PythonCodePrinter   sL   



rJ   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standardpython4)r&   rH   rH   rH   rI   <lambda>M   s    z1test_PythonCodePrinter_standard.<locals>.<lambda>)r&   rL   r,   
ValueErrorrF   rH   rH   rI   test_PythonCodePrinter_standardH   s   rP   c                  C   s   t  } | ttdksJ | tdddksJ | tjdks$J | tjdks.J | tjdks8J | tj	dksBJ | tj
d	ksLJ | tjd
ksVJ | tjdks`J | ttdkskJ 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%   rC   r   rD   r   r   Exp1PiGoldenRatio
EulerGammaNaNInfinityNegativeInfinityr6   )r7   rH   rH   rI   test_MpmathPrinterP   s   rX   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sFJ tddd}tddd}tddd}tddd}||d dksiJ ||d dkstJ |tddksJ tddd}tddd}|t||dksJ |t||| dksJ ||	dddksJ ||dddksJ ||dd| |
|f|
| dksJ ||||dksJ ||||d ksJ |||d!ksJ |||d"ksJ |||d#ksJ |||d$ksJ |td d%ks#J |td& d'ks/J tddd(d)}||d*ks@J |tjd+ksKJ |tjd,ksVJ |tjd-ksaJ |tj d.kslJ |tj!d/kswJ |tj"d0ksJ |t#td d1ksJ 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)rD   rE   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)$sympy.core.functionrY   "sympy.matrices.expressions.adjointrZ   #sympy.matrices.expressions.diagonalr[   r\   r]   %sympy.matrices.expressions.funcmatrixr^   #sympy.matrices.expressions.hadamardr_   $sympy.matrices.expressions.kroneckerr`   "sympy.matrices.expressions.specialra   rb   	sympy.abcrc   rd   r*   rC   r   rD   r#   r$   r   r   r   rQ   rR   rT   rU   rV   rW   r   )rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   r7   re   rf   rg   ri   uvexprrH   rH   rI   test_NumPyPrinter_   sV    ry   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sGJ |td td }|t|d}|| dddg dk	 sgJ |ddksoJ d S )Nnumpyznumpy not installed.r   )r   r   )lambdifyg?r=   r9   g      ?)g      ?g      ?g      @rj   r8   rk   )r9   r   r9      @   )
r5   r-   (sympy.functions.elementary.miscellaneousr   r   sympy.utilities.lambdifyr{   rD   linspaceall)rz   r   r   r{   expr1funcrH   rH   rI   test_issue_18770   s    ""r   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 r*J tddddi}| |d	ks;J d
| jv sBJ | tjdksLJ | tj	dksVJ | tj
dks`J d S )Nrz   znumpy.arccos(x)c                 s   s    | ]}| d V  qdS )scipyN)
startswith).0mrH   rH   rI   	<genexpr>   s    z$test_SciPyPrinter.<locals>.<genexpr>r8   rh   r@   r=   z8scipy.sparse.coo_matrix(([3], ([0], [1])), shape=(2, 5))zscipy.sparsezscipy.constants.golden_ratiozscipy.constants.pirm   )r+   r   rD   rB   rC   anyr"   r   rS   rR   rQ   )r7   rx   smatrH   rH   rI   test_SciPyPrinter   s   r   c                     s<   t d\ tt fdd t  } | dv sJ d S )Nzif elsec                      s   t   ddS )NT)error_on_reserved)r'   rH   s1s2rH   rI   rN      s    z,test_pycode_reserved_words.<locals>.<lambda>)zelse_ + if_zif_ + else_)r
   r,   rO   r'   )py_strrH   r   rI   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'   )a_brd   a_11rx   rH   rH   rI   test_issue_20762   s
   r   c                  C   sn  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s2J | jdtt ddd
ksAJ t } | jttdddksQJ | jttdddks^J t } | jttdddksnJ | jttddd	ks{J 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 d S )NF)rationalr;   r9   z1/math.sqrt(x)rL   rK   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&   
_print_Powr   rD   r%   r*   r+   r(   rF   rH   rH   rI   	test_sqrt   s(   r   c                  C   s   ddl m}  | t}t }||dksJ t }||dks"J t }||dks.J t }||dks:J t }||dksFJ d S )Nr   )fracznumpy.mod(x, 1)zx % 1zmpmath.frac(x)z+sympy.functions.elementary.integers.frac(x))	#sympy.functions.elementary.integersr   rD   r*   rC   r+   r&   r%   r(   )r   rx   rG   rH   rH   rI   	test_frac   s   r   c                   @   s   e Zd Zdd Zdd ZdS )CustomPrintedObjectc                 C      dS )Nrz   rH   selfprinterrH   rH   rI   
_numpycode      zCustomPrintedObject._numpycodec                 C   r   )NmpmathrH   r   rH   rH   rI   _mpmathcode   r   zCustomPrintedObject._mpmathcodeN)__name__
__module____qualname__r   r   rH   rH   rH   rI   r      s    r   c                  C   s2   t  } t | dksJ t | dksJ d S )Nrz   r   )r   r*   rC   r%   )objrH   rH   rI   test_printmethod   s   r   c                   C   s   t tdksJ d S )NNone)r'   r   rH   rH   rH   rI   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&   rC   r   r   rF   rH   rH   rI   test_issue_14283	  s   r   c                  C   s    t  } | tddksJ d S )Nr8   z(0, 1,))r*   
_print_seqrange)nrH   rH   rI   test_NumPyPrinter_print_seq  s   r   c            	   	   C   s   ddl m} m} td}| |t}||t}t }||dks"J ||dks+J t }tddi}||fD ]$}t	t
 || W d    n1 sNw   Y  d||v s\J q8d S )	Nr   )
lowergamma
uppergammarc   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
   rD   r+   rC   r*   r&   r,   NotImplementedError)	r   r   rc   r   expr2rG   p_numpyp_pycoderx   rH   rH   rI   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sHJ 	|dksQJ t
tfdd	 t
t fd
d	 t 	|dksqJ 	|dkszJ 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 NrC   rH   
indefiniterG   rH   rI   rN   6     
 ztest_Integral.<locals>.<lambda>c                      r   r   r   rH   
evaluateatrG   rH   rI   rN   7  r   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                      r   r   r   rH   r   rH   rI   rN   <  r   c                      r   r   r   rH   r   rH   rI   rN   =  r   )&sympy.functions.elementary.exponentialr   sympy.integrals.integralsr   rD   r   rE   zr+   rC   r,   r   r%   )r   r   singledoublerH   )r   r   rG   rI   test_Integral*  s    *r   c            	   	   C   s   ddl m} m} | t}|t}t }||dksJ ||dks%J t }t }t }||fD ]4}t	t
 || W d    n1 sHw   Y  t	t
 || W d    n1 saw   Y  q2||dkspJ ||dksyJ d S )Nr   )fresnelcfresnelszscipy.special.fresnel(x)[1]zscipy.special.fresnel(x)[0]zmpmath.fresnelc(x)zmpmath.fresnels(x))'sympy.functions.special.error_functionsr   r   rD   r+   rC   r*   r&   r%   r,   r   )	r   r   r   r   rG   r   r   p_mpmathrx   rH   rH   rI   test_fresnel_integrals@  s&   

r   c                  C   s   ddl m}  | tt}t }||dksJ t }||dks#J t }||dks/J tddi}||dks>J t }||dksJJ d S )Nr   )betazscipy.special.beta(x, y)z/(math.gamma(x)*math.gamma(y)/math.gamma(x + y))allow_unknown_functionsTzmpmath.beta(x, y))	&sympy.functions.special.beta_functionsr   rD   rE   r+   rC   r*   r&   r%   )r   rx   rG   rH   rH   rI   	test_betaW  s   
r   c                  C      ddl m} m} | t}|t}t }||dksJ ||dks%J tddi}d||v s4J d||v s=J tddi}d||v sLJ d||v sUJ d S )Nr   )airyaiairybizscipy.special.airy(x)[0]zscipy.special.airy(x)[2]r   Fr   )sympy.functions.special.besselr   r   rD   r+   rC   r*   r&   )r   r   r   r   rG   rH   rH   rI   	test_airyk     r   c                  C   r   )Nr   )airyaiprimeairybiprimezscipy.special.airy(x)[1]zscipy.special.airy(x)[3]r   Fr   )r   r   r   rD   r+   rC   r*   r&   )r   r   r   r   rG   rH   rH   rI   test_airy_prime}  r   r   c                  C   sL   t  } | ttdksJ | ttdksJ | ttdks$J d S )Nznumpy.expm1(x)znumpy.log1p(x)zscipy.special.cosm1(x))r+   rC   r   rD   r   r   rF   rH   rH   rI   !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s(J |td
dks3J |t| ddgdksAJ ||dksJJ |t| g ddksXJ |t| ddgddgdksiJ |t| dgdgdksxJ |t	||||f ||||f dksJ t
 }|td
dksJ |td
dksJ |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 d S )Nre   )rj   rj   r<   r<   r<   Iir@   jrA   k)rj   rh   rh   znumpy.zeros((5,))znumpy.ones((5,))r8   r=   znumpy.einsum("abccd->abd", A))r8   r=   rj   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*   rC   r3   r4   r2   r1   r   r)   )re   r   r   r   r   rG   rH   rH   rI   test_array_printer  s*   
"","2r   N)csympy.codegenr   sympy.codegen.astr   sympy.codegen.cfunctionsr   r   sympy.codegen.scipy_nodesr   sympy.codegen.matrix_nodesr   
sympy.corer   r	   r
   r   r   r   r   r   r   r   sympy.core.numbersr   sympy.core.singletonr   sympy.functionsr   r   r   r   r   r   r   r   r   r   r   r   sympy.logicr    r!   sympy.matricesr"   r#   r$   sympy.printing.pycoder%   r&   r'   r(   sympy.printing.tensorflowr)   sympy.printing.numpyr*   r+   sympy.testing.pytestr,   r-   sympy.tensorr.   r/   0sympy.tensor.array.expressions.array_expressionsr0   r1   r2   r3   r4   sympy.externalr5   r   r6   rD   rE   r   r7   rJ   rP   rX   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rH   rH   rH   rI   <module>   sX    08,5	