a
    kh-                     @   s  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 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 d dlmZ d dlmZ d dlmZmZmZ d dl 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. d dl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 d dl7m8Z8 d dl9m:Z:m;Z;m<Z<m=Z= d dl>m?Z?m@Z@mAZAmBZBmCZCmDZD d dlEmFZF d dlGmHZHmIZI d dlJmKZK eKdZLeKdZMeLreLNeLOg jPZQeQjRZSdd ZTdd ZUd d! ZVd"d# ZWd$d% ZXd&d' ZYd(d) ZZd*d+ Z[d,d- Z\d.d/ Z]d0d1 Z^d2d3 Z_d4d5 Z`d6d7 Zad8d9 Zbd:d; Zcd<d= Zdd>d? Zed@dA ZfdBdC ZgdDdE ZhdFdG ZidHdI ZjdJdK ZkdLdM ZldNdO ZmdPdQ ZndRS )S    )Sum)Mod)Equality
Unequality)Symbol)sqrt)	Piecewise)	polygamma)SiCi)Matrix)BlockMatrix)MatrixSymbol)Identity)lambdify)symbolsMinMax)xijabcd)Pow)MatrixSolve)	logaddexp
logaddexp2)log1pexpm1hypotlog10exp2log2Sqrt)Array)ArrayTensorProductArrayAddPermuteDimsArrayDiagonal)NumPyPrinterSciPyPrinter_numpy_known_constants_numpy_known_functions_scipy_known_constants_scipy_known_functions)convert_matrix_to_array)skipraises)import_modulenumpyjaxc                  C   sD   t  } tdtdk fd}| |dks*J | jdh diks@J dS )z
    NumPyPrinter needs to print Piecewise()'s choicelist as a list to avoid
    breaking compatibility with numpy 1.8. This is not necessary in numpy 1.9+.
    See gh-9747 and gh-9749 for details.
       r   )r   Tz?numpy.select([numpy.less(x, 0),True], [1,0], default=numpy.nan)r5   >   ZlessnanselectN)r+   r   r   doprintZmodule_imports)printerp r=   M/var/www/auris/lib/python3.9/site-packages/sympy/printing/tests/test_numpy.pytest_numpy_piecewise_regression&   s    r?   c                  C   s@   t tt} t | dksJ ttt}t |dks<J d S )Nznumpy.logaddexp(a, b)znumpy.logaddexp2(a, b))r   r   r   r+   r:   r   )ZlaeZlae2r=   r=   r>   test_numpy_logaddexp2   s    

r@   c               	      s   t std ttt tttf} ttttf| d}d\}}t ddd t 	||| t
 fddt||d D s|J ttt tttf} ttttf| d}d\}}t ddd t 	||| t
 fd	dt||d D sJ d S )
NNumPy not installedr5   r   
   r7   rC   c                 3   s   | ]} | V  qd S Nr=   .0i_x_r=   r>   	<genexpr>B       ztest_sum.<locals>.<genexpr>c                 3   s   | ]}|  V  qd S rE   r=   rF   rI   r=   r>   rK   I   rL   )npr2   r   r   r   r   r   r   linspaceallclosesumrangesfa_b_r=   rI   r>   test_sum9   s    4rW   c               	      s   t std ttt t tttfttt	f} t
tttt	tf| d}d\}}d\ t dddt ||| t fdd	t||d D sJ d S )
NrA   r5   rB   )      rD   r7   rC   c                 3   s.   | ]&}t  d  D ]}| | V  qqdS )r7   N)rQ   )rG   rH   Zj_Zc_Zd_rJ   r=   r>   rK   W   rL   z%test_multiple_sums.<locals>.<genexpr>)rM   r2   r   r   r   r   r   r   r   r   r   rN   rO   rP   rQ   rR   r=   rZ   r>   test_multiple_sumsL   s     "r[   c                  C   s   t std tddd} tddd}t| | }t| |f|d}t ddgddgg}t dd	gd
dgg}|||t ||k sJ d S )NrA   M   Nr5   r7         rD   )rM   r2   r   r1   r   arraymatmulall)r\   r^   cgrT   mambr=   r=   r>   test_codegen_einsumZ   s    rh   c            
   
   C   s  t std tddd} tddd}tddd}tddd}t ddgdd	gg}t dd
gddgg}t ddgddgg}t ddgd	dgg}t| |}t| |f|d}	|	||t |ddg|ddgk sJ t| |}t| |f|d}	|	|||| k sJ t| ||}t| ||f|d}	|	||||| | k sNJ t| |||}t| |||f|d}	|	|||||| | | k sJ t	| ddg}t| f|d}	|	||j
k sJ t	t| |g d}t| |f|d}	|	||t t |ddg|ddgdk s$J tt| |d}t| |f|d}	|	||t jt |ddg|ddgdddk s|J d S )NrA   r\   r]   r^   PQr7   r_   r`   ra   rD   r      r5   )r7   r]   r_   r   )r7   r]   )Zaxis1Zaxis2)rM   r2   r   rb   r'   r   Zeinsumrd   r(   r)   TZ	transposer*   Zdiagonal)
r\   r^   ri   rj   rf   rg   ZmcZmdre   rT   r=   r=   r>   test_codegen_extrai   s>    
*
"(4rm   c                  C   st  t std ttd} ttf| }t g d}t ||g dsHJ ttd} ttf| }t g d}t ||g dsJ tdk } ttf| }t g d}t ||g dsJ tdk} ttf| }t g d}t ||g dsJ tdk} ttf| }t g d}t ||g ds4J tdk} ttf| }t g d}t ||g d	spJ d S )
NrA   r7   )r   r7   r]   )FTF)TFT)TFF)TTF)FFT)FTT)rM   r2   r   r   r   rb   array_equalr   )erT   rJ   r=   r=   r>   test_relational   s4    

rp   c                  C   s   t std ttt} tttf| }t g d}d}t |||g dsPJ t g d}t g d}t |||g dsJ t g d}t g d}t |||g dsJ d S )NrA   )r   r7   r]   r_   r]   )r   r7   r   r7   )r]   r]   r]   r]   )r]   r_   r`      )r   r   r   r   )rM   r2   r   r   r   r   rb   rn   )ro   rT   rU   rV   r=   r=   r>   test_mod   s    
rr   c                  C   s8   t std tdddd} tg | d}| dks4J d S )NrA   r]   rD   F)evaluater5   g      ?)rM   r2   r   r   )exprrT   r=   r=   r>   test_pow   s
    ru   c                  C   sB   t std ttfttd} t| dd d dt ks>J d S )NrA   r5   g|=g#B;)rM   r2   r   r   r    absNUMPY_DEFAULT_EPSILONrT   r=   r=   r>   
test_expm1   s    ry   c                  C   s>   t std ttfttd} t| dd dt ks:J d S )NrA   r5   g>N}a+)rM   r2   r   r   r   rv   rw   rx   r=   r=   r>   
test_log1p   s    rz   c                   C   s<   t std ttttftttdddd tks8J d S )NrA   r5   r_   r`   rq   )rM   r2   rv   r   r   r   r!   rw   r=   r=   r=   r>   
test_hypot   s    r{   c                   C   s6   t std tttfttddd tks2J d S )NrA   r5   d   r]   )rM   r2   rv   r   r   r"   rw   r=   r=   r=   r>   
test_log10   s    r}   c                   C   s6   t std tttfttddd tks2J d S )NrA   r5   rq       )rM   r2   rv   r   r   r#   rw   r=   r=   r=   r>   	test_exp2   s    r   c                   C   s6   t std tttfttddd tks2J d S )NrA   r5         )rM   r2   rv   r   r   r$   rw   r=   r=   r=   r>   	test_log2   s    r   c                   C   s6   t std tttfttddd tks2J d S NrA   r5   r`   r]   )rM   r2   rv   r   r   r%   rw   r=   r=   r=   r>   	test_Sqrt   s    r   c                   C   s6   t std tttfttddd tks2J d S r   )rM   r2   rv   r   r   r   rw   r=   r=   r=   r>   	test_sqrt  s    r   c                  C   s   t std tddd} tddd}| d | | }t| || }t| |f|}t| |f|}t g dg dg d	g}t j|dksJ t g d
}t ||||||sJ d S )NrA   r\   r_   r   r7   rD   r7   r]   r_   )r_   r]   rq   )rq      rk   )r_   r`   rq   )	rM   r2   r   r   r   rb   ZlinalgZmatrix_rankrO   )r\   r   rt   Zmatsolve_exprrT   Z
f_matsolveZm0Zx0r=   r=   r>   test_matsolve  s    r   c                  C   sz   t std tddd} tddd}tddd}tddd}t| |g||gg}|jdks^J t }||d	ksvJ d S )
NrA   a_1rC   r_   a_2a_3a_4)   r   z%numpy.block([[a_1, a_2], [a_3, a_4]]))rM   r2   r   r   shaper+   r:   )r   r   r   r   Ar;   r=   r=   r>   
test_16857   s    r   c                     s   t std tddd} t| | td }t ddgddgg}t ddgddgg}|||k sjJ dd	lm} |d
ddtd t	t
 fdd d S )NrA   r\   r]   r7   r_   r`   rq   r   )r   nT)integerc                      s   t   t S rE   )r   r   r=   r^   r   r=   r>   <lambda>>  rL   z"test_issue_17006.<locals>.<lambda>)rM   r2   r   r   r   rb   rd   sympy.core.symbolr   r3   NotImplementedError)r\   rT   rf   mrr   r=   r   r>   test_issue_17006/  s    r   c            	      C   s   t std td\} }}t| ||t| || }t| ||f|d}d\}}t j|t j| }}t	|| || s~J t	|| || sJ d S )NzJax not installedzx y zr6   )r   )r`   rq   r   )
r6   r2   r   r   r   r   r5   ZasarrayrM   rO   )	r   yzrt   funcZinput_tuple1Zinput_tuple2Zinput_array1Zinput_array2r=   r=   r>   test_jax_tuple_compatibility@  s    r   c                  C   s   t  } | tddgddggdks(J | tddgdksBJ | tg dggdks`J | tg d	d
ksxJ | tg ddksJ | tg ddksJ | tg ddksJ | tdgddksJ d S )Nr7   r]   r_   rq   numpy.array([[1, 2], [3, 5]])znumpy.array([1, 2])r   znumpy.array([[[1, 2, 3]]]))r   znumpy.zeros((0,)))r   r   numpy.zeros((0, 0)))r   r7   numpy.zeros((0, 1)))r7   r   numpy.zeros((1, 0))r=   znumpy.array(1))r+   r:   r&   r<   r=   r=   r>   test_numpy_arrayL  s    "r   c                  C   s   t  } | tddgddggdks(J | tddgdksBJ | tddg dks\J | tddg d	ksvJ | tddg d
ksJ d S )Nr7   r]   r_   rq   r   znumpy.array([[1], [2]])r   r   r   r   )r+   r:   r   r   r=   r=   r>   test_numpy_matrixW  s    "r   c                   C   sD   t d dksJ t d dks J td dks0J td dks@J d S )	NNaNz	numpy.nanZ
EulerGammaznumpy.euler_gammaacosznumpy.arccoslogz	numpy.log)r-   r.   r=   r=   r=   r>   test_numpy_known_funcs_consts_  s    r   c                   C   sD   t d dksJ t d dks J td dks0J td dks@J d S )	NZGoldenRatiozscipy.constants.golden_ratioPizscipy.constants.pierfzscipy.special.erf	factorialzscipy.special.factorial)r/   r0   r=   r=   r=   r>   test_scipy_known_funcs_constsf  s    r   c                  C   s&   t  } t| dsJ t| ds"J d S )N_print_acos
_print_log)r+   hasattr)prntrr=   r=   r>   test_numpy_print_methodsm  s    r   c                  C   s   t  } t| dsJ t| ds"J t| ds0J t| ds>J t| dsLJ tdddd}td	dd
}| t||dks~J | t|dksJ | t|dksJ d S )Nr   r   Z
_print_erfZ_print_factorialZ_print_chebyshevtkT)r   Znonnegativer   )realzscipy.special.polygamma(k, x)zscipy.special.sici(x)[0]zscipy.special.sici(x)[1])r,   r   r   r:   r	   r
   r   )r   r   r   r=   r=   r>   test_scipy_print_methodsr  s    r   N)oZsympy.concrete.summationsr   Zsympy.core.modr   Zsympy.core.relationalr   r   r   r   Z(sympy.functions.elementary.miscellaneousr   Z$sympy.functions.elementary.piecewiser   Z'sympy.functions.special.gamma_functionsr	   Z'sympy.functions.special.error_functionsr
   r   Zsympy.matricesr   Z&sympy.matrices.expressions.blockmatrixr   Z"sympy.matrices.expressions.matexprr   Z"sympy.matrices.expressions.specialr   Zsympy.utilities.lambdifyr   Zsympyr   r   r   Z	sympy.abcr   r   r   r   r   r   r   Z
sympy.corer   Zsympy.codegen.matrix_nodesr   Zsympy.codegen.numpy_nodesr   r   Zsympy.codegen.cfunctionsr   r    r!   r"   r#   r$   r%   Zsympy.tensor.arrayr&   Z0sympy.tensor.array.expressions.array_expressionsr'   r(   r)   r*   Zsympy.printing.numpyr+   r,   r-   r.   r/   r0   Z3sympy.tensor.array.expressions.from_matrix_to_arrayr1   Zsympy.testing.pytestr2   r3   Zsympy.externalr4   rM   r6   Zfinforb   ZdtypeZdeafult_float_infoZepsrw   r?   r@   rW   r[   rh   rm   rp   rr   ru   ry   rz   r{   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r=   r=   r=   r>   <module>   sp   $$ *)	