o
    3Ih-                     @   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   >   nanlessselectN)r+   r   r   doprintmodule_imports)printerp r?   _/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/sympy/printing/tests/test_numpy.pytest_numpy_piecewise_regression&   s   rA   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   )laelae2r?   r?   r@   test_numpy_logaddexp2   s   

rD   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   rG   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 rI   r?   rJ   rM   r?   r@   rO   I   rP   )npr2   r   r   r   r   r   r   linspaceallclosesumrangesfa_b_r?   rM   r@   test_sum9   s   48r[   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 )
NrE   r5   rF   )      rH   r7   rG   c                 3   s0    | ]}t  d  D ]	}| | V  qqdS )r7   N)rU   )rK   rL   j_c_d_rN   r?   r@   rO   W   s   . z%test_multiple_sums.<locals>.<genexpr>)rQ   r2   r   r   r   r   r   r   r   r   r   rR   rS   rT   rU   rV   r?   r_   r@   test_multiple_sumsL   s    "rb   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 )NrE   M   Nr5   r7         rH   )rQ   r2   r   r1   r   arraymatmulall)rc   re   cgrX   mambr?   r?   r@   test_codegen_einsumZ   s   "ro   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 )NrE   rc   rd   re   PQr7   rf   rg   rh   rH   r      r5   )r7   rd   rf   r   )r7   rd   )axis1axis2)rQ   r2   r   ri   r'   r   einsumrk   r(   r)   T	transposer*   diagonal)
rc   re   rp   rq   rm   rn   mcmdrl   rX   r?   r?   r@   test_codegen_extrai   s>   
*
 &4<r{   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 )
NrE   r7   )r   r7   rd   )FTF)TFT)TFF)TTF)FFT)FTT)rQ   r2   r   r   r   ri   array_equalr   )erX   rN   r?   r?   r@   test_relational   s4   

r~   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 )NrE   )r   r7   rd   rf   rd   )r   r7   r   r7   )rd   rd   rd   rd   )rd   rf   rg      )r   r   r   r   )rQ   r2   r   r   r   r   ri   r|   )r}   rX   rY   rZ   r?   r?   r@   test_mod   s   
r   c                  C   s8   t std tdddd} tg | d}| dksJ d S )NrE   rd   rH   F)evaluater5   g      ?)rQ   r2   r   r   )exprrX   r?   r?   r@   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 )NrE   r5   g|=g#B;)rQ   r2   r   r   r    absNUMPY_DEFAULT_EPSILONrX   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 )NrE   r5   g>N}a+)rQ   r2   r   r   r   r   r   r   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 )NrE   r5   rf   rg   r   )rQ   r2   r   r   r   r   r!   r   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 )NrE   r5   d   rd   )rQ   r2   r   r   r   r"   r   r?   r?   r?   r@   
test_log10      *r   c                   C   r   )NrE   r5   r       )rQ   r2   r   r   r   r#   r   r?   r?   r?   r@   	test_exp2   r   r   c                   C   r   )NrE   r5         )rQ   r2   r   r   r   r$   r   r?   r?   r?   r@   	test_log2   r   r   c                   C   r   NrE   r5   rg   rd   )rQ   r2   r   r   r   r%   r   r?   r?   r?   r@   	test_Sqrt   r   r   c                   C   r   r   )rQ   r2   r   r   r   r   r   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 )NrE   rc   rf   r   r7   rH   r7   rd   rf   )rf   rd   r   )r      rr   )rf   rg   r   )	rQ   r2   r   r   r   ri   linalgmatrix_rankrS   )rc   r   r   matsolve_exprrX   
f_matsolvem0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 )
NrE   a_1rG   rf   a_2a_3a_4)   r   z%numpy.block([[a_1, a_2], [a_3, a_4]]))rQ   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 )NrE   rc   rd   r7   rf   rg   r   r   )r   nT)integerc                      s   t   t S rI   )r   r   r?   re   r   r?   r@   <lambda>>  s    z"test_issue_17006.<locals>.<lambda>)rQ   r2   r   r   r   ri   rk   sympy.core.symbolr   r3   NotImplementedError)rc   rX   rm   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   )rg   r   r   )
r6   r2   r   r   r   r   r5   asarrayrQ   rS   )	r   yzr   funcinput_tuple1input_tuple2input_array1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   rd   rf   r   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   rd   rf   r   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.nan
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   )	N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   
_print_erf_print_factorial_print_chebyshevtkT)r   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)osympy.concrete.summationsr   sympy.core.modr   sympy.core.relationalr   r   r   r   (sympy.functions.elementary.miscellaneousr   $sympy.functions.elementary.piecewiser   'sympy.functions.special.gamma_functionsr	   'sympy.functions.special.error_functionsr
   r   sympy.matricesr   &sympy.matrices.expressions.blockmatrixr   "sympy.matrices.expressions.matexprr   "sympy.matrices.expressions.specialr   sympy.utilities.lambdifyr   sympyr   r   r   	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/   r0   3sympy.tensor.array.expressions.from_matrix_to_arrayr1   sympy.testing.pytestr2   r3   sympy.externalr4   rQ   r6   finfori   dtypedeafult_float_infoepsr   rA   rD   r[   rb   ro   r{   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r?   r?   r?   r@   <module>   sr    $$ *)	