o
    *ήc&                     @   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 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(m)Z) d dl*m+Z+ d dl,m-Z-m.Z.m/Z/m0Z0 d dl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 d dl8m9Z9 d dl:m;Z;m<Z< d dl=m>Z> e>dZ?e?re?@e?Ag jBZCeCjDZEdd ZFdd ZGdd ZHdd ZIdd ZJd d! ZKd"d# ZLd$d% ZMd&d' ZNd(d) ZOd*d+ ZPd,d- ZQd.d/ ZRd0d1 ZSd2d3 ZTd4d5 ZUd6d7 ZVd8d9 ZWd:d; ZXd<d= ZYd>d? ZZd@dA Z[dBdC Z\dDdE Z]dFdG Z^dHS )I    )Sum)Mod)Equality
Unequality)sqrt)	Piecewise)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   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)r-   >   nanlessselectN)r#   r   r   doprintmodule_imports)printerp r6   F/tmp/pip-target-vg8gfxp4/lib/python/sympy/printing/tests/test_numpy.pytest_numpy_piecewise_regression    s   r8   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#   r2   r   )laelae2r6   r6   r7   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>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 svJ d S )
NNumPy not installedr-   r   
   r.   r>   c                 3   s    | ]} | V  qd S Nr6   .0i_x_r6   r7   	<genexpr><       ztest_sum.<locals>.<genexpr>c                 3   s    | ]}|  V  qd S r@   r6   rA   rD   r6   r7   rF   C   rG   )npr*   r   r   r   r   r   r   linspaceallclosesumrangesfa_b_r6   rD   r7   test_sum3   s   48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 sNJ d S )
Nr<   r-   r=   )      r?   r.   r>   c                 3   s0    | ]}t  d  D ]	}| | V  qqdS )r.   N)rL   )rB   rC   j_c_d_rE   r6   r7   rF   Q   s   . z%test_multiple_sums.<locals>.<genexpr>)rH   r*   r   r   r   r   r   r   r   r   r   rI   rJ   rK   rL   rM   r6   rV   r7   test_multiple_sumsF   s    "rY   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 sEJ d S )Nr<   M   Nr-   r.         r?   )rH   r*   r	   r)   r   arraymatmulall)rZ   r\   cgrO   mambr6   r6   r7   test_codegen_einsumT   s   "rf   c            
   
   C   sx  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 slJ t| |}t| |f|d}	|	|||| k sJ t| ||}t| ||f|d}	|	||||| | k sJ 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 )Nr<   rZ   r[   r\   PQr.   r]   r^   r_   r?   r      r-   )r.   r[   r]   r   r.   r[   )axis1axis2)rH   r*   r	   r`   r   r   einsumrb   r    r!   T	transposer"   diagonal)
rZ   r\   rg   rh   rd   re   mcmdrc   rO   r6   r6   r7   test_codegen_extrac   s>   
*
 &4<rs   c                  C   sp  t std ttd} ttf| }t g d}t ||g ds$J ttd} ttf| }t g d}t ||g dsBJ tdk } ttf| }t g d}t ||g ds_J tdk} ttf| }t g d}t ||g ds|J 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 d S )
Nr<   r.   )r   r.   r[   )FTF)TFT)TFF)TTF)FFT)FTT)rH   r*   r   r   r   r`   array_equalr   )erO   rE   r6   r6   r7   test_relational   s4   

rv   c                  C   s   t std ttt} tttf| }t g d}d}t |||g ds(J t g d}t g d}t |||g dsCJ t g d}t g d}t |||g ds^J d S )Nr<   )r   r.   r[   r]   r[   )r   r.   r   r.   )r[   r[   r[   r[   )r[   r]   r^      )r   r   r   r   )rH   r*   r   r   r   r   r`   rt   )ru   rO   rP   rQ   r6   r6   r7   test_mod   s   
rx   c                  C   s8   t std tdddd} tg | d}| dksJ d S )Nr<   r[   r?   F)evaluater-   g      ?)rH   r*   r   r   )exprrO   r6   r6   r7   test_pow   s
   r{   c                  C   sB   t std ttfttd} t| dd d dt ksJ d S )Nr<   r-   g|=g#B;)rH   r*   r   r   r   absNUMPY_DEFAULT_EPSILONrO   r6   r6   r7   
test_expm1   s   $r   c                  C   s>   t std ttfttd} t| dd dt ksJ d S )Nr<   r-   g>N}a+)rH   r*   r   r   r   r|   r}   r~   r6   r6   r7   
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sJ d S )Nr<   r-   r]   r^   rw   )rH   r*   r|   r   r   r   r   r}   r6   r6   r6   r7   
test_hypot   s   0r   c                   C   6   t std tttfttddd tksJ d S )Nr<   r-   d   r[   )rH   r*   r|   r   r   r   r}   r6   r6   r6   r7   
test_log10      *r   c                   C   r   )Nr<   r-   rw       )rH   r*   r|   r   r   r   r}   r6   r6   r6   r7   	test_exp2   r   r   c                   C   r   )Nr<   r-         )rH   r*   r|   r   r   r   r}   r6   r6   r6   r7   	test_log2   r   r   c                   C   r   Nr<   r-   r^   r[   )rH   r*   r|   r   r   r   r}   r6   r6   r6   r7   	test_Sqrt   r   r   c                   C   r   r   )rH   r*   r|   r   r   r   r}   r6   r6   r6   r7   	test_sqrt   r   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sGJ t g d
}t ||||||s\J d S )Nr<   rZ   r]   r   r.   r?   )r.   r[   r]   )r]   r[   rw   )rw      ri   )r]   r^   rw   )	rH   r*   r	   r   r   r`   linalgmatrix_rankrJ   )rZ   r   rz   matsolve_exprrO   
f_matsolvem0x0r6   r6   r7   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s;J d S )
Nr<   a_1r>   r]   a_2a_3a_4)   r   z%numpy.block([[a_1, a_2], [a_3, a_4]]))rH   r*   r	   r   shaper#   r2   )r   r   r   r   Ar4   r6   r6   r7   
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 s5J dd	lm} |d
ddtd t	t
 fdd d S )Nr<   rZ   r[   r.   r]   r^   rw   r   )symbolsnT)integerc                      s   t   t S r@   )r   r
   r6   r\   r   r6   r7   <lambda>8  s    z"test_issue_17006.<locals>.<lambda>)rH   r*   r	   r   r
   r`   rb   sympy.core.symbolr   r+   NotImplementedError)rZ   rO   rd   mrr   r6   r   r7   test_issue_17006)  s   r   c                   C   s4   t  tddksJ t  tddksJ d S )N)rj   )r]   rw   znumpy.array([[1, 2], [3, 5]])rj   znumpy.array((1, 2)))r#   r2   r   r6   r6   r6   r7   test_numpy_array:  s   r   c                   C   D   t d dksJ t d dksJ td dksJ td dks J d S )	NNaNz	numpy.nan
EulerGammaznumpy.euler_gammaacosznumpy.arccoslogz	numpy.log)r%   r&   r6   r6   r6   r7   test_numpy_known_funcs_consts>     r   c                   C   r   )	NGoldenRatiozscipy.constants.golden_ratioPizscipy.constants.pierfzscipy.special.erf	factorialzscipy.special.factorial)r'   r(   r6   r6   r6   r7   test_scipy_known_funcs_constsE  r   r   c                  C   s&   t  } t| ds
J t| dsJ d S )N_print_acos
_print_log)r#   hasattrprntrr6   r6   r7   test_numpy_print_methodsL  s   r   c                  C   sP   t  } t| ds
J t| dsJ t| dsJ t| dsJ t| ds&J d S )Nr   r   
_print_erf_print_factorial_print_chebyshevt)r$   r   r   r6   r6   r7   test_scipy_print_methodsQ  s   r   N)_sympy.concrete.summationsr   sympy.core.modr   sympy.core.relationalr   r   (sympy.functions.elementary.miscellaneousr   $sympy.functions.elementary.piecewiser   &sympy.matrices.expressions.blockmatrixr   "sympy.matrices.expressions.matexprr	   "sympy.matrices.expressions.specialr
   sympy.utilities.lambdifyr   	sympy.abcr   r   r   r   r   r   r   
sympy.corer   sympy.codegen.matrix_nodesr   sympy.codegen.numpy_nodesr   r   sympy.codegen.cfunctionsr   r   r   r   r   r   r   sympy.tensor.arrayr   0sympy.tensor.array.expressions.array_expressionsr   r    r!   r"   sympy.printing.numpyr#   r$   r%   r&   r'   r(   3sympy.tensor.array.expressions.conv_matrix_to_arrayr)   sympy.testing.pytestr*   r+   sympy.externalr,   rH   finfor`   dtypedeafult_float_infoepsr}   r8   r;   rR   rY   rf   rs   rv   rx   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r6   r6   r6   r7   <module>   sb    $$ *)	