o
    GZh-                     @   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ZMeLreLNeLOg 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   >   lessnanselectN)r+   r   r   doprintZmodule_imports)printerp r>   N/var/www/auris/lib/python3.10/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   

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>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 installedr5   r   
   r7   rD   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 rF   r>   rG   rJ   r>   r?   rL   I   rM   )npr2   r   r   r   r   r   r   linspaceallclosesumrangesfa_b_r>   rJ   r?   test_sum9   s   48rX   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 )
NrB   r5   rC   )      rE   r7   rD   c                 3   s0    | ]}t  d  D ]	}| | V  qqdS )r7   N)rR   )rH   rI   Zj_Zc_Zd_rK   r>   r?   rL   W   s   . z%test_multiple_sums.<locals>.<genexpr>)rN   r2   r   r   r   r   r   r   r   r   r   rO   rP   rQ   rR   rS   r>   r[   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 sEJ d S )NrB   M   Nr5   r7         rE   )rN   r2   r   r1   r   arraymatmulall)r]   r_   cgrU   mambr>   r>   r?   test_codegen_einsumZ   s   "ri   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 )NrB   r]   r^   r_   PQr7   r`   ra   rb   rE   r      r5   )r7   r^   r`   r   )r7   r^   )Zaxis1Zaxis2)rN   r2   r   rc   r'   r   Zeinsumre   r(   r)   TZ	transposer*   Zdiagonal)
r]   r_   rj   rk   rg   rh   Zmcmdrf   rU   r>   r>   r?   test_codegen_extrai   s>   
*
 &4<ro   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 )
NrB   r7   )r   r7   r^   )FTF)TFT)TFF)TTF)FFT)FTT)rN   r2   r   r   r   rc   array_equalr   )erU   rK   r>   r>   r?   test_relational   s4   

rr   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 )NrB   )r   r7   r^   r`   r^   )r   r7   r   r7   )r^   r^   r^   r^   )r^   r`   ra      )r   r   r   r   )rN   r2   r   r   r   r   rc   rp   )rq   rU   rV   rW   r>   r>   r?   test_mod   s   
rt   c                  C   s8   t std tdddd} tg | d}| dksJ d S )NrB   r^   rE   F)evaluater5   g      ?)rN   r2   r   r   )exprrU   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J d S )NrB   r5   g|=g#B;)rN   r2   r   r   r    absNUMPY_DEFAULT_EPSILONrU   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J d S )NrB   r5   g>N}a+)rN   r2   r   r   r   rx   ry   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sJ d S )NrB   r5   r`   ra   rs   )rN   r2   rx   r   r   r   r!   ry   r>   r>   r>   r?   
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 )NrB   r5   d   r^   )rN   r2   rx   r   r   r"   ry   r>   r>   r>   r?   
test_log10      *r   c                   C   r~   )NrB   r5   rs       )rN   r2   rx   r   r   r#   ry   r>   r>   r>   r?   	test_exp2   r   r   c                   C   r~   )NrB   r5         )rN   r2   rx   r   r   r$   ry   r>   r>   r>   r?   	test_log2   r   r   c                   C   r~   NrB   r5   ra   r^   )rN   r2   rx   r   r   r%   ry   r>   r>   r>   r?   	test_Sqrt   r   r   c                   C   r~   r   )rN   r2   rx   r   r   r   ry   r>   r>   r>   r?   	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 )NrB   r]   r`   r   r7   rE   r7   r^   r`   )r`   r^   rs   )rs      rl   )r`   ra   rs   )	rN   r2   r   r   r   rc   ZlinalgZmatrix_rankrP   )r]   r   rv   Zmatsolve_exprrU   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s;J d S )
NrB   a_1rD   r`   a_2a_3a_4)   r   z%numpy.block([[a_1, a_2], [a_3, a_4]]))rN   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 s5J dd	lm} |d
ddtd t	t
 fdd d S )NrB   r]   r^   r7   r`   ra   rs   r   )r   nT)integerc                      s   t   t S rF   )r   r   r>   r_   r   r>   r?   <lambda>>  s    z"test_issue_17006.<locals>.<lambda>)rN   r2   r   r   r   rc   re   sympy.core.symbolr   r3   NotImplementedError)r]   rU   rg   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	|| || sKJ d S )NzJax not installedzx y zr6   )r   )ra   rs   r   )
r6   r2   r   r   r   r   r5   ZasarrayrN   rP   )	r   yzrv   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s!J | tg dggdks0J | tg d	d
ks<J | tg ddksHJ | tg ddksTJ | tg ddks`J | tdgddksmJ d S )Nr7   r^   r`   rs   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s!J | tddg dks.J | tddg d	ks;J | tddg d
ksHJ d S )Nr7   r^   r`   rs   r   znumpy.array([[1], [2]])r   r   r   r   )r+   r;   r   r   r>   r>   r?   test_numpy_matrixW  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.nanZ
EulerGammaznumpy.euler_gammaacosznumpy.arccoslogz	numpy.log)r-   r.   r>   r>   r>   r?   test_numpy_known_funcs_consts_     r   c                   C   r   )	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  r   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sJ t| dsJ t| ds&J tdddd}td	dd
}| t||dks?J | t|dksJJ | t|dksUJ 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   rN   r6   Zfinforc   ZdtypeZdeafult_float_infoZepsry   r@   rA   rX   r\   ri   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>   r?   <module>   sr    $$ *)	