U
    0ex(                     @   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 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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+m,Z,m-Z-m.Z.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5m6Z6m7Z7 d dl8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z> d dl?m@Z@ d dlAmBZBmCZC d dlDmEZE eEdZFeFreFGeFHg jIZJeJjKZLdd ZMdd ZNdd ZOdd  ZPd!d" ZQd#d$ ZRd%d& ZSd'd( ZTd)d* ZUd+d, ZVd-d. ZWd/d0 ZXd1d2 ZYd3d4 ZZd5d6 Z[d7d8 Z\d9d: Z]d;d< Z^d=d> Z_d?d@ Z`dAdB ZadCdD ZbdEdF ZcdGdH ZddIdJ ZedKS )L    )Sum)Mod)Equality
Unequality)Symbol)sqrt)	Piecewise)	polygamma)SiCi)BlockMatrix)MatrixSymbol)Identity)lambdify)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numpyc                  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)r1   selectZlessnanN)r'   r   r   doprintAssertionErrorZmodule_imports)printerp r9   C/tmp/pip-unpacked-wheel-_6tpq7m6/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'   r5   r6   r   )ZlaeZlae2r9   r9   r:   test_numpy_logaddexp/   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|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 installedr1   r   
   r2   r?   c                 3   s   | ]} | V  qd S Nr9   .0i_x_r9   r:   	<genexpr>?   s     ztest_sum.<locals>.<genexpr>c                 3   s   | ]}|  V  qd S rA   r9   rB   rE   r9   r:   rG   F   s     )npr.   r   r   r   r   r   r   linspaceallclosesumranger6   sfa_b_r9   rE   r:   test_sum6   s    4rR   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 )
Nr=   r1   r>   )      r@   r2   r?   c                 3   s.   | ]&}t  d  D ]}| | V  qqdS )r2   N)rL   )rC   rD   Zj_Zc_Zd_rF   r9   r:   rG   T   s       z%test_multiple_sums.<locals>.<genexpr>)rH   r.   r   r   r   r   r   r   r   r   r   rI   rJ   rK   rL   r6   rM   r9   rU   r:   test_multiple_sumsI   s     "rV   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 )Nr=   M   Nr1   r2         r@   )	rH   r.   r   r-   r   arraymatmulallr6   )rW   rY   cgrO   mambr9   r9   r:   test_codegen_einsumW   s    rc   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 )Nr=   rW   rX   rY   PQr2   rZ   r[   r\   r@   r      r1   )r2   rX   rZ   r   r2   rX   )Zaxis1Zaxis2)rH   r.   r   r]   r#   r   Zeinsumr_   r6   r$   r%   TZ	transposer&   Zdiagonal)
rW   rY   rd   re   ra   rb   ZmcZmdr`   rO   r9   r9   r:   test_codegen_extraf   s>    
*
"(4ri   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 )Nr=   r2   r   rX   FT)	rH   r.   r   r   r   r]   array_equalr6   r   )erO   rF   r9   r9   r:   test_relational   s4    

rl   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 )Nr=   r   r2   rX   rZ   r[      )	rH   r.   r   r   r   r   r]   rj   r6   )rk   rO   rP   rQ   r9   r9   r:   test_mod   s    
rn   c                  C   s8   t std tdddd} tg | d}| dks4td S )Nr=   rX   r@   F)evaluater1   g      ?)rH   r.   r   r   r6   )exprrO   r9   r9   r:   test_pow   s
    rq   c                  C   sB   t std ttfttd} t| dd d dt ks>td S )Nr=   r1   g|=g#B;)rH   r.   r   r   r   absNUMPY_DEFAULT_EPSILONr6   rO   r9   r9   r:   
test_expm1   s    ru   c                  C   s>   t std ttfttd} t| dd dt ks:td S )Nr=   r1   g>N}a+)rH   r.   r   r   r   rr   rs   r6   rt   r9   r9   r:   
test_log1p   s    rv   c                   C   s<   t std ttttftttdddd tks8td S )Nr=   r1   rZ   r[   rm   )	rH   r.   rr   r   r   r   r   rs   r6   r9   r9   r9   r:   
test_hypot   s    rw   c                   C   s6   t std tttfttddd tks2td S )Nr=   r1   d   rX   )rH   r.   rr   r   r   r   rs   r6   r9   r9   r9   r:   
test_log10   s    ry   c                   C   s6   t std tttfttddd tks2td S )Nr=   r1   rm       )rH   r.   rr   r   r   r   rs   r6   r9   r9   r9   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 )Nr=   r1         )rH   r.   rr   r   r   r    rs   r6   r9   r9   r9   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 Nr=   r1   r[   rX   )rH   r.   rr   r   r   r!   rs   r6   r9   r9   r9   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   )rH   r.   rr   r   r   r   rs   r6   r9   r9   r9   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 )Nr=   rW   rZ   r   r2   r@   rX   rm      rf   r[   )
rH   r.   r   r   r   r]   ZlinalgZmatrix_rankr6   rJ   )rW   r   rp   Zmatsolve_exprrO   Z
f_matsolveZm0Zx0r9   r9   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 )
Nr=   a_1r?   rZ   a_2a_3a_4)   r   z%numpy.block([[a_1, a_2], [a_3, a_4]]))rH   r.   r   r   shaper6   r'   r5   )r   r   r   r   Ar7   r9   r9   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 )Nr=   rW   rX   r2   rZ   r[   rm   r   )symbolsnT)integerc                      s   t   t S rA   )r   r   r9   rY   r   r9   r:   <lambda>;      z"test_issue_17006.<locals>.<lambda>)rH   r.   r   r   r   r]   r_   r6   sympy.core.symbolr   r/   NotImplementedError)rW   rO   ra   mrr   r9   r   r:   test_issue_17006,  s    r   c                   C   s4   t  tddkstt  tddks0td S )N)rg   )rZ   rm   znumpy.array([[1, 2], [3, 5]])rg   znumpy.array((1, 2)))r'   r5   r"   r6   r9   r9   r9   r:   test_numpy_array=  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)   r6   r*   r9   r9   r9   r:   test_numpy_known_funcs_constsA  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+   r6   r,   r9   r9   r9   r:   test_scipy_known_funcs_constsH  s    r   c                  C   s&   t  } t| dstt| ds"td S )N_print_acos
_print_log)r'   hasattrr6   )prntrr9   r9   r:   test_numpy_print_methodsO  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   r6   r   r5   r	   r
   r   )r   r   r   r9   r9   r:   test_scipy_print_methodsT  s    r   N)fZ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	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_arrayr-   Zsympy.testing.pytestr.   r/   Zsympy.externalr0   rH   Zfinfor]   ZdtypeZdeafult_float_infoZepsrs   r;   r<   rR   rV   rc   ri   rl   rn   rq   ru   rv   rw   ry   r{   r~   r   r   r   r   r   r   r   r   r   r   r9   r9   r9   r:   <module>   sf   $$ *)	