o
    oh6+                     @   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mZ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/m0Z0m1Z1m2Z2 d dl3m4Z4m5Z5m6Z6 d dl7m8Z8 d dl9m:Z:m;Z; d dl<m=Z= e=dZ>e>re>j?@e>j?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)FunctionPowSymbol)MatrixSolve)	logaddexp
logaddexp2)log1pexpm1hypotlog10exp2log2Sqrt)Array)ArrayTensorProductArrayAddPermuteDimsArrayDiagonal)
JaxPrinter_jax_known_constants_jax_known_functions)convert_matrix_to_array)skipraises)import_module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   TzKjax.numpy.select([jax.numpy.less(x, 0),True], [1,0], default=jax.numpy.nan)z	jax.numpy>   nanlessselectN)r%   r   r   doprintmodule_imports)printerp r5   q/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/printing/tests/test_jax.pytest_jax_piecewise_regression(   s   r7   c                  C   s@   t tt} t | dksJ ttt}t |dksJ d S )Nzjax.numpy.logaddexp(a, b)zjax.numpy.logaddexp2(a, b))r   r   r   r%   r1   r   )laelae2r5   r5   r6   test_jax_logaddexp5   s   

r:   c               	      s   t std ttt tttf} ttttf| d}d\}}t j	ddd t j
||| t fddt||d D s@J ttt tttf} ttttf| d}d\}}t j	ddd t j
||| t fd	dt||d D szJ d S )
NJAX not installedr,   r   
   r-   r=   c                 3   s    | ]} | V  qd S Nr5   .0i_x_r5   r6   	<genexpr>E       ztest_jax_sum.<locals>.<genexpr>c                 3   s    | ]}|  V  qd S r?   r5   r@   rC   r5   r6   rE   L   rF   )r,   r)   r   r   r   r   r   r   numpylinspaceallclosesumrangesfa_b_r5   rC   r6   test_jax_sum<   s   6:rQ   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 jdddt j||| t fdd	t||d D sPJ d S )
Nr;   r,   r<   )      r>   r-   r=   c                 3   s0    | ]}t  d  D ]	}| | V  qqdS )r-   N)rK   )rA   rB   j_c_d_rD   r5   r6   rE   Z   s   . z)test_jax_multiple_sums.<locals>.<genexpr>)r,   r)   r   r   r   r   r   r   r   r   r   rG   rH   rI   rJ   rK   rL   r5   rU   r6   test_jax_multiple_sumsO   s    "rX   c                  C   s   t std tddd} tddd}t| | }t| |f|d}t jddgddgg}t jdd	gd
dgg}|||t j||k sHJ d S )Nr;   M   Nr,   r-         r>   )	r,   r)   r	   r(   r   rG   arraymatmulall)rY   r[   cgrN   mambr5   r5   r6   test_jax_codegen_einsum]   s   $re   c            
   
   C   s  t std tddd} tddd}tddd}tddd}t jddgdd	gg}t jdd
gddgg}t jddgddgg}t jddgd	dgg}t| |}t| |f|d}	|	||t j|ddg|ddgk sqJ 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 jt j|ddg|ddgdk sJ tt| |d}t| |f|d}	|	||t jjt j|ddg|ddgdddk sCJ d S )Nr;   rY   rZ   r[   PQr-   r\   r]   r^   r>   r      r,   )r-   rZ   r\   r   r-   rZ   )axis1axis2)r,   r)   r	   rG   r_   r!   r   einsumra   r"   r#   T	transposer$   diagonal)
rY   r[   rf   rg   rc   rd   mcmdrb   rN   r5   r5   r6   test_jax_codegen_extral   s>   
,
 &8@rr   c                  C   s&  t std ttd} ttf| d}t jg d}t j||g ds'J ttd} ttf| d}t jg d}t j||g dsHJ tdk } ttf| d}t jg d}t j||g dshJ tdk} ttf| d}t jg d}t j||g dsJ tdk} ttf| d}t jg d}t j||g d	sJ tdk} ttf| d}t jg d}t j||g d
sJ tdktdk @ } ttf| d}t jg d}t j||g dsJ tdktdk B } ttf| d}t jg d}t j||g dsJ d S )Nr;   r-   r,   )r   r-   rZ   )FTF)TFT)TFF)TTF)FFT)FTTrZ   )TTT)	r,   r)   r   r   r   rG   r_   array_equalr   )erN   rD   r5   r5   r6   test_jax_relational   sD   

 ru   c                  C   s   t std ttt} tttf| d}t jg d}d}t j|||g ds+J t jg d}t jg d}t j|||g dsIJ t jg d}t jg d}t j|||g dsgJ d S )	Nr;   r,   )r   r-   rZ   r\   rZ   )r   r-   r   r-   )rZ   rZ   rZ   rZ   )rZ   r\   r]      )r   r   r   r   )	r,   r)   r   r   r   r   rG   r_   rs   )rt   rN   rO   rP   r5   r5   r6   test_jax_mod   s   
 rw   c                  C   s8   t std tdddd} tg | d}| dksJ d S )Nr;   rZ   r>   F)evaluater,   g      ?)r,   r)   r   r   )exprrN   r5   r5   r6   test_jax_pow   s
   rz   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;)r,   r)   r   r   r   absJAX_DEFAULT_EPSILONrN   r5   r5   r6   test_jax_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+)r,   r)   r   r   r   r{   r|   r}   r5   r5   r6   test_jax_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]   rv   )r,   r)   r{   r   r   r   r   r|   r5   r5   r5   r6   test_jax_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   rZ   )r,   r)   r{   r   r   r   r|   r5   r5   r5   r6   test_jax_log10   s   *r   c                   C   r   )Nr;   r,   rv       )r,   r)   r{   r   r   r   r|   r5   r5   r5   r6   test_jax_exp2     *r   c                   C   r   )Nr;   r,         )r,   r)   r{   r   r   r   r|   r5   r5   r5   r6   test_jax_log2  r   r   c                   C   r   Nr;   r,   r]   rZ   )r,   r)   r{   r   r   r   r|   r5   r5   r5   r6   test_jax_Sqrt  r   r   c                   C   r   r   )r,   r)   r{   r   r   r   r|   r5   r5   r5   r6   test_jax_sqrt  r   r   c                  C   s   t std tddd} tddd}| d | | }t| || }t| |f|d}t| |f|d}t jg dg d	g d
g}t jj|dksKJ t jg d}t j	||||||sbJ d S )Nr;   rY   r\   r   r-   r>   r,   )r-   rZ   r\   )r\   rZ   rv   )rv      rh   )r\   r]   rv   )
r,   r)   r	   r   r   rG   r_   linalgmatrix_rankrI   )rY   r   ry   matsolve_exprrN   
f_matsolvem0x0r5   r5   r6   test_jax_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)jax.numpy.block([[a_1, a_2], [a_3, a_4]]))r,   r)   r	   r   shaper%   r1   )r   r   r   r   Ar3   r5   r5   r6   
test_16857.  s   r   c                     s   t std tddd} t| | td d}t jddgddgg}t jddgddgg}|||k s8J d	d
lm	} |dddtd t
t fdd d S )Nr;   rY   rZ   r,   r-   r\   r]   rv   r   )symbolsnT)integerc                      s   t   t dS )Nr,   )r   r
   r5   r[   r   r5   r6   <lambda>L  s    z"test_issue_17006.<locals>.<lambda>)r,   r)   r	   r   r
   rG   r_   ra   sympy.core.symbolr   r*   NotImplementedError)rY   rN   rc   mrr   r5   r   r6   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)ri   )r\   rv   z!jax.numpy.array([[1, 2], [3, 5]])ri   zjax.numpy.array((1, 2)))r%   r1   r    r5   r5   r5   r6   test_jax_arrayO  s   r   c                   C   sD   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jax.numpy.nan
EulerGammazjax.numpy.euler_gammaacoszjax.numpy.arccoslogzjax.numpy.log)r&   r'   r5   r5   r5   r6   test_jax_known_funcs_constsT  s   r   c                  C   s&   t  } t| ds
J t| dsJ d S )N_print_acos
_print_log)r%   hasattr)prntrr5   r5   r6   test_jax_print_methods\     r   c                  C   s&   t  } t| ds
J | jdksJ d S )Nprintmethod_jaxcode)r%   r   r   )r3   r5   r5   r6   test_jax_printmethodb  r   r   c                  C   s4   G dd dt } t }|| tddksJ d S )Nc                   @   s   e Zd Zdd ZdS )z+test_jax_custom_print_method.<locals>.expm1c                 S   s.   | j \}d|| d}||jd | S )Nzexpm1().)args_print_module_format_module)selfr3   r   functionr5   r5   r6   r   l  s   z4test_jax_custom_print_method.<locals>.expm1._jaxcodeN)__name__
__module____qualname__r   r5   r5   r5   r6   r   j  s    r   r   zjax.numpy.expm1(x))r   r%   r1   r   )r   r3   r5   r5   r6   test_jax_custom_print_methodh  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   r   r   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'   3sympy.tensor.array.expressions.from_matrix_to_arrayr(   sympy.testing.pytestr)   r*   sympy.externalr+   r,   rG   finfor_   dtypedeafult_float_infoepsr|   r7   r:   rQ   rX   re   rr   ru   rw   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r5   r5   r5   r6   <module>   sb    $$
*3	