U
    L?h*                     @   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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-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 d dl5m6Z6 d dl7m8Z8m9Z9m:Z:m;Z; d dl<m=Z=m>Z>m?Z?m@Z@mAZAmBZB d dlCmDZD d dlEmFZFmGZG d dlHmIZI eIdZJeIdZKeJreJLeJMg jNZOeOjPZQdd ZRdd ZSdd  ZTd!d" ZUd#d$ ZVd%d& ZWd'd( ZXd)d* ZYd+d, ZZd-d. Z[d/d0 Z\d1d2 Z]d3d4 Z^d5d6 Z_d7d8 Z`d9d: Zad;d< Zbd=d> Zcd?d@ ZddAdB ZedCdD ZfdEdF ZgdGdH ZhdIdJ ZidKdL ZjdMdN ZkdOS )P    )Sum)Mod)Equality
Unequality)Symbol)sqrt)	Piecewise)	polygamma)SiCi)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   sF   t  } tdtdk fd}| |dks*t| jddddhiksBt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)r4   selectlessnanN)r*   r   r   doprintAssertionErrorZmodule_imports)printerp r>   Q/var/www/html/venv/lib/python3.8/site-packages/sympy/printing/tests/test_numpy.pytest_numpy_piecewise_regression%   s    r@   c                  C   s@   t tt} t | dkstttt}t |dks<td S )Nznumpy.logaddexp(a, b)znumpy.logaddexp2(a, b))r   r   r   r*   r:   r;   r   )ZlaeZlae2r>   r>   r?   test_numpy_logaddexp1   s    

rA   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|t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 std S )
NNumPy not installedr4   r   
   r6   rD   c                 3   s   | ]} | V  qd S Nr>   .0i_x_r>   r?   	<genexpr>A   s     ztest_sum.<locals>.<genexpr>c                 3   s   | ]}|  V  qd S rF   r>   rG   rJ   r>   r?   rL   H   s     )npr1   r   r   r   r   r   r   linspaceallclosesumranger;   sfa_b_r>   rJ   r?   test_sum8   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 std S )
NrB   r4   rC   )      rE   r6   rD   c                 3   s.   | ]&}t  d  D ]}| | V  qqdS )r6   N)rQ   )rH   rI   Zj_Zc_Zd_rK   r>   r?   rL   V   s       z%test_multiple_sums.<locals>.<genexpr>)rM   r1   r   r   r   r   r   r   r   r   r   rN   rO   rP   rQ   r;   rR   r>   rZ   r?   test_multiple_sumsK   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 std S )NrB   M   Nr4   r6         rE   )	rM   r1   r   r0   r   arraymatmulallr;   )r\   r^   cgrT   mambr>   r>   r?   test_codegen_einsumY   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 stt	| |}t| |f|d}	|	|||| k stt	| ||}t| ||f|d}	|	||||| | k sNtt	| |||}t| |||f|d}	|	|||||| | | k stt
| ddg}t| f|d}	|	||jk stt
t| |ddddg}t| |f|d}	|	||t t |ddg|ddgdk s(ttt| |d}t| |f|d}	|	||t jt |ddg|ddgdddk std S )NrB   r\   r]   r^   PQr6   r_   r`   ra   rE   r      r4   )r6   r]   r_   r   r6   r]   )Zaxis1Zaxis2)rM   r1   r   rb   r&   r   Zeinsumrd   r;   r'   r(   TZ	transposer)   Zdiagonal)
r\   r^   ri   rj   rf   rg   Zmcmdre   rT   r>   r>   r?   test_codegen_extrah   s>    
*
"(4ro   c                  C   s  t std ttd} ttf| }t dddg}t ||dddgsLtttd} ttf| }t dddg}t ||dddgsttdk } ttf| }t dddg}t ||dddgsttdk} ttf| }t dddg}t ||dddgs
ttdk} ttf| }t dddg}t ||dddgsJttdk} ttf| }t dddg}t ||dddgstd S )NrB   r6   r   r]   FT)	rM   r1   r   r   r   rb   array_equalr;   r   )erT   rK   r>   r>   r?   test_relational   s4    

rr   c                  C   s   t std ttt} tttf| }t ddddg}d}t |||ddddgsXtt ddddg}t ddddg}t |||ddddgstt ddddg}t ddddg}t |||ddddgstd S )NrB   r   r6   r]   r_   r`      )	rM   r1   r   r   r   r   rb   rp   r;   )rq   rT   rU   rV   r>   r>   r?   test_mod   s    
rt   c                  C   s8   t std tdddd} tg | d}| dks4td S )NrB   r]   rE   F)evaluater4   g      ?)rM   r1   r   r   r;   )exprrT   r>   r>   r?   test_pow   s
    rw   c                  C   sB   t std ttfttd} t| dd d dt ks>td S )NrB   r4   g|=g#B;)rM   r1   r   r   r   absNUMPY_DEFAULT_EPSILONr;   rT   r>   r>   r?   
test_expm1   s    r{   c                  C   s>   t std ttfttd} t| dd dt ks:td S )NrB   r4   g>N}a+)rM   r1   r   r   r   rx   ry   r;   rz   r>   r>   r?   
test_log1p   s    r|   c                   C   s<   t std ttttftttdddd tks8td S )NrB   r4   r_   r`   rs   )	rM   r1   rx   r   r   r   r    ry   r;   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s2td S )NrB   r4   d   r]   )rM   r1   rx   r   r   r!   ry   r;   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s2td S )NrB   r4   rs       )rM   r1   rx   r   r   r"   ry   r;   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s2td S )NrB   r4         )rM   r1   rx   r   r   r#   ry   r;   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s2td S NrB   r4   r`   r]   )rM   r1   rx   r   r   r$   ry   r;   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s2td S r   )rM   r1   rx   r   r   r   ry   r;   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 dddgdddgdd	d
gg}t j|dkstt dddg}t 	||||||std S )NrB   r\   r_   r   r6   rE   r]   rs      rk   r`   )
rM   r1   r   r   r   rb   ZlinalgZmatrix_rankr;   rO   )r\   r   rv   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^tt }||d	ksvtd S )
NrB   a_1rD   r_   a_2a_3a_4)   r   z%numpy.block([[a_1, a_2], [a_3, a_4]]))rM   r1   r   r   shaper;   r*   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 sjtdd	lm	} |d
ddtd t
t fdd d S )NrB   r\   r]   r6   r_   r`   rs   r   )r   nT)integerc                      s   t   t S rF   )r   r   r>   r^   r   r>   r?   <lambda>=      z"test_issue_17006.<locals>.<lambda>)rM   r1   r   r   r   rb   rd   r;   sympy.core.symbolr   r2   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~t
t	|| || st
d S )NzJax not installedzx y zr5   ))r6   r]   r_   )r`   rs   r   )r5   r1   r   r   r   r   r4   ZasarrayrM   rO   r;   )	r   yzrv   funcZinput_tuple1Zinput_tuple2Zinput_array1Zinput_array2r>   r>   r?   test_jax_tuple_compatibility?  s    r   c                   C   s4   t  tddkstt  tddks0td S )N)rl   )r_   rs   znumpy.array([[1, 2], [3, 5]])rl   znumpy.array((1, 2)))r*   r:   r%   r;   r>   r>   r>   r?   test_numpy_arrayK  s    r   c                   C   sD   t d dkstt d dks ttd dks0ttd dks@td S )	NNaNz	numpy.nanZ
EulerGammaznumpy.euler_gammaacosznumpy.arccoslogz	numpy.log)r,   r;   r-   r>   r>   r>   r?   test_numpy_known_funcs_constsO  s    r   c                   C   sD   t d dkstt d dks ttd dks0ttd dks@td S )	NZGoldenRatiozscipy.constants.golden_ratioPizscipy.constants.pierfzscipy.special.erf	factorialzscipy.special.factorial)r.   r;   r/   r>   r>   r>   r?   test_scipy_known_funcs_constsV  s    r   c                  C   s&   t  } t| dstt| ds"td S )N_print_acos
_print_log)r*   hasattrr;   )prntrr>   r>   r?   test_numpy_print_methods]  s    r   c                  C   s   t  } t| dstt| ds"tt| ds0tt| ds>tt| dsLttdddd}td	dd
}| t||dks~t| t|dkst| t|dkst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>   r?   test_scipy_print_methodsb  s    r   N)lZ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.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.   r/   Z3sympy.tensor.array.expressions.from_matrix_to_arrayr0   Zsympy.testing.pytestr1   r2   Zsympy.externalr3   rM   r5   Zfinforb   ZdtypeZdeafult_float_infoepsry   r@   rA   rW   r[   rh   ro   rr   rt   rw   r{   r|   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r>   r>   r>   r?   <module>   sl   $$ *)	