o
    8Va%                     @   s  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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$m%Z%m&Z&m'Z' d d	l(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. d d
l/m0Z0 d dl1m2Z2 d dl1m3Z3m4Z4 d dl5m6Z6 e6dZ7dd Z8dd Z9dd Z:dd Z;dd Z<dd Z=dd Z>dd Z?dd  Z@d!d" ZAd#d$ ZBd%d& ZCd'd( ZDd)d* ZEd+d, ZFd-d. ZGd/d0 ZHd1d2 ZId3d4 ZJd5d6 ZKd7d8 ZLd9d: ZMd;d< ZNd=d> ZOd?d@ ZPdAS )B    )
	PiecewiselambdifyEquality
UnequalitySumModsqrtMatrixSymbolBlockMatrixIdentity)eye)xijabcd)Pow)MatrixSolve)	logaddexp
logaddexp2)log1pexpm1hypotlog10exp2log2Sqrt)ArrayTensorProductArrayAddPermuteDimsArrayDiagonal)NumPyPrinterSciPyPrinter_numpy_known_constants_numpy_known_functions_scipy_known_constants_scipy_known_functions)convert_matrix_to_array)warns_deprecated_sympy)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.   >   lessselectnanN)r#   r   r   doprintZmodule_imports)printerp r6   A/usr/lib/python3/dist-packages/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#   r3   r   )ZlaeZlae2r6   r6   r7   test_numpy_logaddexp$   s   

r9   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>4       ztest_sum.<locals>.<genexpr>c                 3   s    | ]}|  V  qd S r>   r6   r?   rB   r6   r7   rD   ;   rE   )npr+   r   r   r   r   r   r   linspaceallclosesumrangesfa_b_r6   rB   r7   test_sum+   s   48rP   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)rJ   )r@   rA   Zj_Zc_Zd_rC   r6   r7   rD   I   s   . z%test_multiple_sums.<locals>.<genexpr>)rF   r+   r   r   r   r   r   r   r   r   r   rG   rH   rI   rJ   rK   r6   rS   r7   test_multiple_sums>   s    "rT   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}||||| k sCJ d S )Nr:   M   Nr.   r/         r=   )rF   r+   r	   r)   r   matrixall)rU   rW   cgrM   mambr6   r6   r7   test_codegen_einsumL   s   r`   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:   rU   rV   rW   PQr/   rX   rY   rZ   r=   r      r.   )r/   rV   rX   r   )r/   rV   )Zaxis1Zaxis2)rF   r+   r	   r[   r   r   Zeinsumr\   r    r!   TZ	transposer"   Zdiagonal)
rU   rW   ra   rb   r^   r_   ZmcZmdr]   rM   r6   r6   r7   test_codegen_extra[   s>   
*
 &4<re   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/   rV   )FTF)TFT)TFF)TTF)FFT)FTT)rF   r+   r   r   r   arrayarray_equalr   )erM   rC   r6   r6   r7   test_relational   s4   

ri   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/   rV   rX   rV   )r   r/   r   r/   )rV   rV   rV   rV   )rV   rX   rY      )r   r   r   r   )rF   r+   r   r   r   r   rf   rg   )rh   rM   rN   rO   r6   r6   r7   test_mod   s   
rk   c                  C   s8   t std tdddd} tg | d}| dksJ d S )Nr:   rV   r=   F)Zevaluater.   g      ?)rF   r+   r   r   )exprrM   r6   r6   r7   test_pow   s
   rm   c                  C   s>   t std ttfttd} t| dd d dk sJ d S )Nr:   r.   g|=g#B;g^ 9^;)rF   r+   r   r   r   absrM   r6   r6   r7   
test_expm1   s    rp   c                  C   s:   t std ttfttd} t| dd dk sJ d S )Nr:   r.   g>N}a+g0.++)rF   r+   r   r   r   rn   ro   r6   r6   r7   
test_log1p   s   rq   c                   C   s<   t std ttttftttdddd dk sJ d S )Nr:   r.   rX   rY   rj   缉ؗҜ<)rF   r+   rn   r   r   r   r   r6   r6   r6   r7   
test_hypot   s   0rs   c                   C   6   t std tttfttddd dk sJ d S )Nr:   r.   d   rV   rr   )rF   r+   rn   r   r   r   r6   r6   r6   r7   
test_log10      *rv   c                   C   rt   )Nr:   r.   rj       rr   )rF   r+   rn   r   r   r   r6   r6   r6   r7   	test_exp2   rw   ry   c                   C   rt   )Nr:   r.         rr   )rF   r+   rn   r   r   r   r6   r6   r6   r7   	test_log2   rw   r|   c                   C   rt   Nr:   r.   rY   rV   rr   )rF   r+   rn   r   r   r   r6   r6   r6   r7   	test_Sqrt   rw   r~   c                   C   rt   r}   )rF   r+   rn   r   r   r   r6   r6   r6   r7   	test_sqrt   rw   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:   rU   rX   r   r/   r=   )r/   rV   rX   )rX   rV   rj   )rj      rc   )rX   rY   rj   )	rF   r+   r	   r   r   rf   ZlinalgZmatrix_rankrH   )rU   r   rl   Zmatsolve_exprrM   Z
f_matsolveZm0Zx0r6   r6   r7   test_matsolve   s    r   c                  C   s   t std tddd} tddd}| | }t| |f|d}t  |tdtd}t |t g ds8J W d    d S 1 sCw   Y  d S )NzNumpy not installedrU   rX   rW   r.   )	r/   r   r   r   r/   r   r   r   r/   )rF   r+   r	   r   r*   r   rg   rf   )rU   rW   rl   rM   Zansr6   r6   r7   test_issue_15601  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<   rX   a_2a_3a_4)   r   z%numpy.block([[a_1, a_2], [a_3, a_4]]))rF   r+   r	   r
   shaper#   r3   )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:   rU   rV   r/   rX   rY   rj   r   )symbolsnT)Zintegerc                      s   t   t S r>   )r   r   r6   rW   r   r6   r7   <lambda>=  s    z"test_issue_17006.<locals>.<lambda>)rF   r+   r	   r   r   rf   r\   sympyr   r,   NotImplementedError)rU   rM   r^   mrr   r6   r   r7   test_issue_17006.  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 )	NZNaNz	numpy.nanZ
EulerGammaznumpy.euler_gammaZacosznumpy.arccoslogz	numpy.log)r%   r&   r6   r6   r6   r7   test_numpy_known_funcs_consts?     r   c                   C   r   )	NZGoldenRatiozscipy.constants.golden_ratioZPizscipy.constants.piZerfzscipy.special.erfZ	factorialzscipy.special.factorial)r'   r(   r6   r6   r6   r7   test_scipy_known_funcs_constsF  r   r   c                  C   s&   t  } t| ds
J t| dsJ d S )N_print_acos
_print_log)r#   hasattrZprntrr6   r6   r7   test_numpy_print_methodsM  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   Z
_print_erfZ_print_factorialZ_print_chebyshevt)r$   r   r   r6   r6   r7   test_scipy_print_methodsR  s   r   N)Qr   r   r   r   r   r   r   r   r	   r
   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   Z0sympy.tensor.array.expressions.array_expressionsr   r    r!   r"   Zsympy.printing.numpyr#   r$   r%   r&   r'   r(   Z3sympy.tensor.array.expressions.conv_matrix_to_arrayr)   Zsympy.testing.pytestr*   r+   r,   Zsympy.externalr-   rF   r8   r9   rP   rT   r`   re   ri   rk   rm   rp   rq   rs   rv   ry   r|   r~   r   r   r   r   r   r   r   r   r   r6   r6   r6   r7   <module>   sN   0 $$ *)	